From 5738eb6edd41dfbd476c7f352c4092465d41b114 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov <55441714+GirZ0n@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:24:14 +0400 Subject: [PATCH 01/10] feat: add a config with adapted inspections --- .../inspectionProfiles/Custom_Inspections.xml | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .idea/inspectionProfiles/Custom_Inspections.xml diff --git a/.idea/inspectionProfiles/Custom_Inspections.xml b/.idea/inspectionProfiles/Custom_Inspections.xml new file mode 100644 index 0000000..4345b13 --- /dev/null +++ b/.idea/inspectionProfiles/Custom_Inspections.xml @@ -0,0 +1,78 @@ + + + + From 9d14eb5a10a0e12dc3fd005dc6d4cb84c3cacc6b Mon Sep 17 00:00:00 2001 From: Ilya Vlasov <55441714+GirZ0n@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:30:17 +0400 Subject: [PATCH 02/10] style: sort inspections --- .../inspectionProfiles/Custom_Inspections.xml | 116 +++++++++--------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/.idea/inspectionProfiles/Custom_Inspections.xml b/.idea/inspectionProfiles/Custom_Inspections.xml index 4345b13..b2d5a5c 100644 --- a/.idea/inspectionProfiles/Custom_Inspections.xml +++ b/.idea/inspectionProfiles/Custom_Inspections.xml @@ -1,78 +1,78 @@ From 8a2a5317e57bec2133c59bfa320c43e9b155e2fe Mon Sep 17 00:00:00 2001 From: Ilya Vlasov <55441714+GirZ0n@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:36:22 +0400 Subject: [PATCH 03/10] fix: fix the `enabled_by_default` field --- .../inspectionProfiles/Custom_Inspections.xml | 146 +++++++++--------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/.idea/inspectionProfiles/Custom_Inspections.xml b/.idea/inspectionProfiles/Custom_Inspections.xml index b2d5a5c..ad57bc4 100644 --- a/.idea/inspectionProfiles/Custom_Inspections.xml +++ b/.idea/inspectionProfiles/Custom_Inspections.xml @@ -1,78 +1,78 @@ From cd7f58ae22a760546ad3c4e33463113873f43ed2 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov <55441714+GirZ0n@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:28:48 +0400 Subject: [PATCH 04/10] docs: add a readme with inspection descriptions --- .idea/inspectionProfiles/README.md | 2274 ++++++++++++++++++++++++++++ 1 file changed, 2274 insertions(+) create mode 100644 .idea/inspectionProfiles/README.md diff --git a/.idea/inspectionProfiles/README.md b/.idea/inspectionProfiles/README.md new file mode 100644 index 0000000..a06ad88 --- /dev/null +++ b/.idea/inspectionProfiles/README.md @@ -0,0 +1,2274 @@ +# Inspection descriptions +This README file contains descriptions of all inspections in the [config](./Custom_Inspections.xml) file. + +> [!NOTE] +> This file, as well as the config file, contains only the most common inspections, that have been adapted for better teaching experience. +> For a complete list of inspections available in the IntelliJ platform, see the Kotlin Inspections tab (Settings -> Editor -> Inspections -> Kotlin). + +The `Severity` field (`level` in the config file) indicates how the inspections will be displayed in the upper right corner of the editor and in the Problems tab. Some of the possible values are: +| Name | Config name | Example | +|--------------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------| +| Error | ERROR | image | +| Warning | WARNING | image | +| Weak Warning | WEAK WARNING | image | + +The `Highlighting` field (`editorAttributes` in the config file) indicates how the inspection will be highlighted in the IDE. Some of the possible values are: +| Name | Config name | Example | +|---------------|-------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------| +| Error | ERRORS_ATTRIBUTES | image | +| Warning | WARNING_ATTRIBUTES | image | +| Weak Warning | INFO_ATTRIBUTES | image | +| Strikethrough | MARKED_FOR_REMOVAL_ATTRIBUTES | image | + +> [!NOTE] +> To add a new inspection to the config file please use the Kotlin Inspections tab +> where you could turn on/off an inspection and choose its severity and/or highlighting. + +## AddOperatorModifier + +**Severity**: Weak Warning
+**Highlighting**: Weak Warning
+ +
+Function should have 'operator' modifier + +Reports a function that matches one of the operator conventions but lacks the `operator` keyword. +By adding the `operator` modifier, you might allow function consumers to write idiomatic Kotlin code. + +**Example:** + +```kotlin +class Complex(val real: Double, val imaginary: Double) { + fun plus(other: Complex) = + Complex(real + other.real, imaginary + other.imaginary) +} + +fun usage(a: Complex, b: Complex) { + a.plus(b) +} +``` + +The quick-fix adds the `operator` modifier keyword: + +```kotlin +class Complex(val real: Double, val imaginary: Double) { + operator fun plus(other: Complex) = + Complex(real + other.real, imaginary + other.imaginary) +} + +fun usage(a: Complex, b: Complex) { + a + b +} +``` + +
+ +## AddVarianceModifier + +**Severity**: Weak Warning
+**Highlighting**: Weak Warning
+ +
+Type parameter can have 'in' or 'out' variance + +Reports type parameters that can have `in` or `out` variance. +Using `in` and `out` variance provides more precise type inference in Kotlin and clearer code semantics. + +**Example:** + +```kotlin +class Box(val obj: T) + +fun consumeString(box: Box) {} +fun consumeCharSequence(box: Box) {} + +fun usage(box: Box) { + consumeString(box) + consumeCharSequence(box) // Compilation error +} +``` + +The quick-fix adds the matching variance modifier: + +```kotlin +class Box(val obj: T) + +fun consumeString(box: Box) {} +fun consumeCharSequence(box: Box) {} + +fun usage(box: Box) ++{ + consumeString(box) + consumeCharSequence(box) // OK +} +``` + +
+ +## CanBeParameter + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Constructor parameter is never used as a property + +Reports primary constructor parameters that can have `val` or `var` removed. + +Class properties declared in the constructor increase memory consumption. +If the parameter value is only used in the constructor, you can omit them. + +Note that the referenced object might be garbage-collected earlier. + +**Example:** + +```kotlin +class Task(val name: String) { + init { + print("Task created: $name") + } +} +``` + +The quick-fix removes the extra `val` or `var` keyword: + +```kotlin +class Task(name: String) { + init { + print("Task created: $name") + } +} +``` + +
+ +## CanBePrimaryConstructorProperty + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Property is explicitly assigned to constructor parameter + +Reports properties that are explicitly assigned to primary constructor parameters. +Properties can be declared directly in the primary constructor, reducing the amount of code and increasing code readability. + +**Example:** + +```kotlin +class User(name: String) { + val name = name +} +``` + +The quick-fix joins the parameter and property declaration into a primary constructor parameter: + +```kotlin +class User(val name: String) { +} +``` + +
+ +## CanBeVal + +**Severity**: Error
+**Highlighting**: Error
+ +
+Local 'var' is never modified and can be declared as 'val' + +Reports local variables declared with the `var` keyword that are never modified. +Kotlin encourages to declare practically immutable variables using the `val` keyword, ensuring that their value will never change. + +**Example:** + +```kotlin +fun example() { + var primeNumbers = listOf(1, 2, 3, 5, 7, 11, 13) + var fibonacciNumbers = listOf(1, 1, 2, 3, 5, 8, 13) + print("Same numbers: " + primeNumbers.intersect(fibonacciNumbers)) +} +``` + +The quick-fix replaces the `var` keyword with `val`: + +```kotlin +fun example() { + val primeNumbers = listOf(1, 2, 3, 5, 7, 11, 13) + val fibonacciNumbers = listOf(1, 1, 2, 3, 5, 8, 13) + print("Same numbers: " + primeNumbers.intersect(fibonacciNumbers)) +} +``` + +
+ +## CascadeIf + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Cascade 'if' can be replaced with 'when' + +Reports `if` statements with three or more branches that can be replaced with the `when` expression. +**Example:** + +```kotlin +fun checkIdentifier(id: String) { + fun Char.isIdentifierStart() = this in 'A'..'z' + fun Char.isIdentifierPart() = isIdentifierStart() || this in '0'..'9' + + if (id.isEmpty()) { + print("Identifier is empty") + } else if (!id.first().isIdentifierStart()) { + print("Identifier should start with a letter") + } else if (!id.subSequence(1, id.length).all(Char::isIdentifierPart)) { + print("Identifier should contain only letters and numbers") + } +} +``` + +The quick-fix converts the `if` expression to `when`: + +```kotlin +fun checkIdentifier(id: String) { + fun Char.isIdentifierStart() = this in 'A'..'z' + fun Char.isIdentifierPart() = isIdentifierStart() || this in '0'..'9' + + when { + id.isEmpty() -> { + print("Identifier is empty") + } + !id.first().isIdentifierStart() -> { + print("Identifier should start with a letter") + } + !id.subSequence(1, id.length).all(Char::isIdentifierPart) -> { + print("Identifier should contain only letters and numbers") + } + } +} +``` + +
+ +## ClassName + +**Severity**: Error
+**Highlighting**: Error
+ +
+Class naming convention + +Reports class names that do not follow the recommended naming conventions. + +Consistent naming allows for easier code reading and understanding. +According to the [Kotlin official style guide](https://kotlinlang.org/docs/coding-conventions.html#naming-rules), +class names should start with an uppercase letter and use camel case. + +It is possible to introduce other naming rules by changing the "Pattern" regular expression. + +**Example:** + +```kotlin +class user(val name: String) +``` + +The quick-fix renames the class according to the Kotlin naming conventions: + +```kotlin +class User(val name: String) +``` + +
+ +## ControlFlowWithEmptyBody + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Control flow with empty body + +Reports `if`, `while`, `do` or `for` statements with empty bodies. +While occasionally intended, this construction is confusing and often the result of a typo. + +The quick-fix removes a statement. + +**Example:** + +```kotlin +if (a > b) {} +``` + +
+ +## ConvertLambdaToReference + +**Severity**: Information
+**Highlighting**: None
+ +
+Can be replaced with function reference + +Reports function literal expressions that can be replaced with function references. +Replacing lambdas with function references often makes code look more concise and understandable. + +**Example:** + +```kotlin +fun Int.isEven() = this % 2 == 0 + +fun example() { + val numbers = listOf(1, 2, 4, 7, 9, 10) + val evenNumbers = numbers.filter { it.isEven() } +} +``` + +After the quick-fix is applied: + +```kotlin +fun Int.isEven() = this % 2 == 0 + +fun example() { + val numbers = listOf(1, 2, 4, 7, 9, 10) + val evenNumbers = numbers.filter(Int::isEven) +} +``` + +
+ +## ConvertPairConstructorToToFunction + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Convert Pair constructor to 'to' function + +Reports a `Pair` constructor invocation that can be replaced with a `to()` infix function call. + +Explicit constructor invocations may add verbosity, especially if they are used multiple times. +Replacing constructor calls with `to()` makes code easier to read and maintain. + +**Example:** + +```kotlin +val countries = mapOf( + Pair("France", "Paris"), + Pair("Spain", "Madrid"), + Pair("Germany", "Berlin") +) +``` + +After the quick-fix is applied: + +```kotlin +val countries = mapOf( + "France" to "Paris", + "Spain" to "Madrid", + "Germany" to "Berlin" +) +``` + +
+ +## ConvertReferenceToLambda + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Can be replaced with lambda + +Reports a function reference expression that can be replaced with a function literal (lambda). + +Sometimes, passing a lambda looks more straightforward and more consistent with the rest of the code. +Also, the fix might be handy if you need to replace a simple call with something more complex. + +**Example:** + +```kotlin +fun Int.isEven() = this % 2 == 0 + +fun example() { + val numbers = listOf(1, 2, 4, 7, 9, 10) + val evenNumbers = numbers.filter(Int::isEven) +} +``` + +After the quick-fix is applied: + +```kotlin +fun Int.isEven() = this % 2 == 0 + +fun example() { + val numbers = listOf(1, 2, 4, 7, 9, 10) + val evenNumbers = numbers.filter { it.isEven() } +} +``` + +
+ +## ConvertTwoComparisonsToRangeCheck + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Two comparisons should be converted to a range check + +Reports two consecutive comparisons that can be converted to a range check. +Checking against a range makes code simpler by removing test subject duplication. + +**Example:** + +```kotlin +fun checkMonth(month: Int): Boolean { + return month >= 1 && month <= 12 +} +``` + +The quick-fix replaces the comparison-based check with a range one: + +```kotlin +fun checkMonth(month: Int): Boolean { + return month in 1..12 +} +``` + +
+ +## Destructure + +**Severity**: Weak Warning
+**Highlighting**: Weak Warning
+ +
+Use destructuring declaration + +Reports declarations that can be destructured. +**Example:** + +```kotlin +data class My(val first: String, val second: Int, val third: Boolean) + +fun foo(list: List) { + list.forEach { my -> + println(my.second) + println(my.third) + } +} +``` + +The quick-fix destructures the declaration and introduces new variables with names from the corresponding class: + +```kotlin +data class My(val first: String, val second: Int, val third: Boolean) + +fun foo(list: List) { + list.forEach { (_, second, third) -> + println(second) + println(third) + } +} +``` + +
+ +## ExplicitThis + +**Severity**: Error
+**Highlighting**: Strikethrough
+ +
+Redundant explicit 'this' + +Reports an explicit `this` when it can be omitted. +**Example:** + +```kotlin +class C { + private val i = 1 + fun f() = this.i +} +``` + +The quick-fix removes the redundant `this`: + +```kotlin +class C { + private val i = 1 + fun f() = i +} +``` + +
+ +## ForEachParameterNotUsed + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Iterated elements are not used in forEach + +Reports `forEach` loops that do not use iterable values. +**Example:** + +```kotlin +listOf(1, 2, 3).forEach { } +``` + +The quick fix introduces anonymous parameter in the `forEach` section: + +```kotlin +listOf(1, 2, 3).forEach { _ -> } +``` + +
+ +## FunctionName + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Function naming convention + +Reports function names that do not follow the recommended naming conventions. +**Example:** + +```kotlin +fun Foo() {} +``` + +To fix the problem change the name of the function to match the recommended naming conventions. + +
+ +## HasPlatformType + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Function or property has platform type + +Reports functions and properties that have a platform type. +To prevent unexpected errors, the type should be declared explicitly. + +**Example:** + +```kotlin +fun foo() = java.lang.String.valueOf(1) +``` + +The quick fix allows you to specify the return type: + +```kotlin +fun foo(): String = java.lang.String.valueOf(1) +``` + +
+ +## ImplicitThis + +**Severity**: Weak Warning
+**Highlighting**: Weak Warning
+ +
+Implicit 'this' + +Reports usages of implicit **this**. +**Example:** + +```kotlin +class Foo { + fun s() = "" + + fun test() { + s() + } +} +``` + +The quick fix specifies **this** explicitly: + +```kotlin +class Foo { + fun s() = "" + + fun test() { + this.s() + } +} +``` + +
+ +## IncompleteDestructuring + +**Severity**: Error
+**Highlighting**: Error
+ +
+Incomplete destructuring declaration + +Reports incomplete destructuring declaration. +**Example:** + +```kotlin +data class Person(val name: String, val age: Int) +val person = Person("", 0) +val (name) = person +``` + +The quick fix completes destructuring declaration with new variables: + +```kotlin +data class Person(val name: String, val age: Int) +val person = Person("", 0) +val (name, age) = person +``` + +
+ +## IntroduceWhenSubject + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+when' that can be simplified by introducing an argument + +Reports a `when` expression that can be simplified by introducing a subject argument. +**Example:** + +```kotlin +fun test(obj: Any): String { + return when { + obj is String -> "string" + obj is Int -> "int" + else -> "unknown" + } +} +``` + +The quick fix introduces a subject argument: + +```kotlin +fun test(obj: Any): String { + return when (obj) { + is String -> "string" + is Int -> "int" + else -> "unknown" + } +} +``` + +
+ +## JoinDeclarationAndAssignment + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Join declaration and assignment + +Reports property declarations that can be joined with the following assignment. +**Example:** + +```kotlin +val x: String +x = System.getProperty("") +``` + +The quick fix joins the declaration with the assignment: + +```kotlin +val x = System.getProperty("") +``` + +Configure the inspection: + +You can disable the option **Report with complex initialization of member properties** to skip properties with complex initialization. This covers two cases: + +1. The property initializer is complex (it is a multiline or a compound/control-flow expression) +2. The property is first initialized and then immediately used in subsequent code (for example, to call additional initialization methods) + +
+ +## KDocUnresolvedReference + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Unresolved reference in KDoc + +Reports unresolved references in KDoc comments. +**Example:** + +```kotlin +/** + * [unresolvedLink] + */ +fun foo() {} +``` + +To fix the problem make the link valid. + +
+ +## KotlinConstantConditions + +**Severity**: Error
+**Highlighting**: Error
+ +
+Constant conditions + +Reports non-trivial conditions and values that are statically known to be always true, false, null or zero. +While sometimes intended, often this is a sign of logical error in the program. Additionally, +reports never reachable `when` branches and some expressions that are statically known to fail always. +Examples: + +```kotlin +fun process(x: Int?) { + val isNull = x == null + if (!isNull) { + if (x != null) {} // condition is always true + require(x!! < 0 && x > 10) // condition is always false + } else { + println(x!!) // !! operator will always fail + } +} +fun process(v: Any) { + when(v) { + is CharSequence -> println(v as Int) // cast will always fail + is String -> println(v) // branch is unreachable + } +} +``` + +Uncheck the "Warn when constant is stored in variable" option to avoid reporting of variables having constant values not in conditions. + +New in 2021.3 + +
+ +## KotlinDeprecation + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Usage of redundant or deprecated syntax or deprecated symbols + +Reports obsolete language features and unnecessarily verbose code constructs during the code cleanup operation (**Code | Code Cleanup**). + +The quick-fix automatically replaces usages of obsolete language features or unnecessarily verbose code constructs with compact and up-to-date syntax. + +It also replaces deprecated symbols with their proposed substitutions. + +
+ +## KotlinEqualsBetweenInconvertibleTypes + +**Severity**: Error
+**Highlighting**: Error
+ +
+equals()' between objects of inconvertible types + +Reports calls to `equals()` where the receiver and the argument are +of incompatible primitive, enum, or string types. + +While such a call might theoretically be useful, most likely it represents a bug. + +**Example:** + +```kotlin +5.equals(""); +``` + +
+ +## KotlinUnusedImport + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Unused import directive + +Reports redundant `import` statements. + +Default and unused imports can be safely removed. + +**Example:** + +```kotlin +import kotlin.* +import kotlin.collections.* +import kotlin.comparisons.* +import kotlin.io.* +import kotlin.ranges.* +import kotlin.sequences.* +import kotlin.text.* + +// jvm specific +import java.lang.* +import kotlin.jvm.* + +// js specific +import kotlin.js.* + +import java.io.* // this import is unused and could be removed +import java.util.* + +fun foo(list: ArrayList) { + list.add("") +} +``` + +
+ +## LiftReturnOrAssignment + +**Severity**: Error
+**Highlighting**: Error
+ +
+Return or assignment can be lifted out + +Reports `if`, `when`, and `try` statements that can be converted to expressions +by lifting the `return` statement or an assignment out. +**Example:** + +```kotlin +fun foo(arg: Int): String { + when (arg) { + 0 -> return "Zero" + 1 -> return "One" + else -> return "Multiple" + } +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo(arg: Int): String { + return when (arg) { + 0 -> "Zero" + 1 -> "One" + else -> "Multiple" + } +} +``` + +If you would like this inspection to highlight more complex code with multi-statement branches, uncheck the option "Report only if each branch is a single statement". + +
+ +## LocalVariableName + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Local variable naming convention + +Reports local variables that do not follow the naming conventions. +You can specify the required pattern in the inspection options. + +[Recommended naming conventions](https://kotlinlang.org/docs/coding-conventions.html#function-names): it has to start with a lowercase letter, use camel case and no underscores. + +**Example:** + +```kotlin +fun fibonacciNumber(index: Int): Long = when(index) { + 0 -> 0 + else -> { + // does not follow naming conventions: contains underscore symbol (`_`) + var number_one: Long = 0 + // does not follow naming conventions: starts with an uppercase letter + var NUMBER_TWO: Long = 1 + // follow naming conventions: starts with a lowercase letter, use camel case and no underscores. + var numberThree: Long = number_one + NUMBER_TWO + + for(currentIndex in 2..index) { + numberThree = number_one + NUMBER_TWO + number_one = NUMBER_TWO + NUMBER_TWO = numberThree + } + numberThree + } +} +``` + +
+ +## LoopToCallChain + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Loop can be replaced with stdlib operations + +Reports `for` loops that can be replaced with a sequence of stdlib operations (like `map`, `filter`, and so on). +**Example:** + +```kotlin +fun foo(list: List): List { + val result = ArrayList() + for (s in list) { + if (s.length > 0) + result.add(s.hashCode()) + } + return result +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo(list: List): List { + val result = list + .filter { it.length > 0 } + .map { it.hashCode() } + return result +} +``` + +
+ +## MayBeConstant + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Might be 'const' + +Reports top-level `val` properties in objects that might be declared as `const` +for better performance and Java interoperability. +**Example:** + +```kotlin +object A { + val foo = 1 +} +``` + +After the quick-fix is applied: + +```kotlin +object A { + const val foo = 1 +} +``` + +
+ +## MemberVisibilityCanBePrivate + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Class member can have 'private' visibility + +Reports declarations that can be made `private` to follow the encapsulation principle. +**Example:** + +```kotlin +class Service(val url: String) { + fun connect(): URLConnection = URL(url).openConnection() +} +``` + +After the quick-fix is applied (considering there are no usages of `url` outside of `Service` class): + +```kotlin +class Service(private val url: String) { + fun connect(): URLConnection = URL(url).openConnection() +} +``` + +
+ +## MoveVariableDeclarationIntoWhen + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Variable declaration could be moved inside 'when' + +Reports variable declarations that can be moved inside a `when` expression. +**Example:** + +```kotlin +fun someCalc(x: Int) = x * 42 + +fun foo(x: Int): Int { + val a = someCalc(x) + return when (a) { + 1 -> a + 2 -> 2 * a + else -> 24 + } +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo(x: Int): Int { + return when (val a = someCalc(x)) { + 1 -> a + 2 -> 2 * a + else -> 24 + } +} +``` + +
+ +## NestedLambdaShadowedImplicitParameter + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Nested lambda has shadowed implicit parameter + +Reports nested lambdas with shadowed implicit parameters. +**Example:** + +```kotlin +fun foo(listOfLists: List>) { + listOfLists.forEach { + it.forEach { + println(it) + } + } +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo(listOfLists: List>) { + listOfLists.forEach { + it.forEach { it1 -> + println(it1) + } + } +} +``` + +
+ +## PrivatePropertyName + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Private property naming convention + +Reports private property names that do not follow the recommended naming conventions. + +Consistent naming allows for easier code reading and understanding. +According to the [Kotlin official style guide](https://kotlinlang.org/docs/coding-conventions.html#naming-rules), +private property names should start with a lowercase letter and use camel case. +Optionally, underscore prefix is allowed but only for **private** properties. + +It is possible to introduce other naming rules by changing the "Pattern" regular expression. + +**Example:** + +```kotlin +val _My_Cool_Property = "" +``` + +The quick-fix renames the class according to the Kotlin naming conventions: + +```kotlin +val _myCoolProperty = "" +``` + +
+ +## PublicApiImplicitType + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Public API declaration with implicit return type + +Reports `public` and `protected` functions and properties that have an implicit return type. +For API stability reasons, it's recommended to specify such types explicitly. + +**Example:** + +```kotlin +fun publicFunctionWhichAbusesTypeInference() = + otherFunctionWithNotObviousReturnType() ?: yetAnotherFunctionWithNotObviousReturnType() +``` + +After the quick-fix is applied: + +```kotlin +fun publicFunctionWhichAbusesTypeInference(): **Api** = + otherFunctionWithNotObviousReturnType() ?: yetAnotherFunctionWithNotObviousReturnType() +``` + +
+ +## RedundantElseInIf + +**Severity**: Error
+**Highlighting**: Strikethrough
+ +
+Redundant 'else' in 'if' + +Reports redundant `else` in `if` with `return` + +**Example:** + +```kotlin +fun foo(arg: Boolean): Int { + if (arg) return 0 + else { // This else is redundant, code in braces could be just shifted left + someCode() + } +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo(arg: Boolean): Int { + if (arg) return 0 + someCode() +} +``` + +
+ +## RedundantExplicitType + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Obvious explicit type + +Reports local variables' explicitly given types which are obvious and thus redundant, like `val f: Foo = Foo()`. + +**Example:** + +```kotlin +class Point(val x: Int, val y: Int) + +fun foo() { + val t: **Boolean** = true + val p: **Point** = Point(1, 2) + val i: **Int** = 42 +} +``` + +After the quick-fix is applied: + +```kotlin +class Point(val x: Int, val y: Int) + +fun foo() { + val t = true + val p = Point(1, 2) + val i = 42 +} +``` + +
+ +## RedundantIf + +**Severity**: Weak Warning
+**Highlighting**: Strikethrough
+ +
+Redundant 'if' statement + +Reports `if` statements which can be simplified to a single statement. + +**Example:** + +```kotlin +fun test(): Boolean { + if (foo()) { + return true + } else { + return false + } +} +``` + +After the quick-fix is applied: + +```kotlin +fun test(): Boolean { + return foo() +} +``` + +
+ +## RedundantNullableReturnType + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Redundant nullable return type + +Reports functions and variables with nullable return type which never return or become `null`. +**Example:** + +```kotlin +fun greeting(user: String): String? = "Hello, $user!" +``` + +After the quick-fix is applied: + +```kotlin +fun greeting(user: String): String = "Hello, $user!" +``` + +
+ +## RedundantSemicolon + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Redundant semicolon + +Reports redundant semicolons (`;`) that can be safely removed. + +Kotlin does not require a semicolon at the end of each statement or expression. +The quick-fix is suggested to remove redundant semicolons. + +**Example:** + +```kotlin +val myMap = mapOf("one" to 1, "two" to 2); +myMap.forEach { (key, value) -> print("$key -> $value")}; +``` + +After the quick-fix is applied: + +```kotlin +val myMap = mapOf("one" to 1, "two" to 2) +myMap.forEach { (key, value) -> print("$key -> $value")} +``` + +There are two cases though where a semicolon is required: + +1. Several statements placed on a single line need to be separated with semicolons: + +```kotlin +map.forEach { val (key, value) = it; println("$key -> $value") } +``` + +2. `enum` classes that also declare properties or functions, require a semicolon after the list of enum constants: + +```kotlin +enum class Mode { + SILENT, VERBOSE; + + fun isSilent(): Boolean = this == SILENT +} +``` + +
+ +## RedundantVisibilityModifier + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Redundant visibility modifier + +Reports visibility modifiers that match the default visibility of an element +(`public` for most elements, `protected` for members that override a protected member). + +
+ +## RemoveCurlyBracesFromTemplate + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Redundant curly braces in string template + +Reports usages of curly braces in string templates around simple identifiers. +Use the 'Remove curly braces' quick-fix to remove the redundant braces. + +**Examples:** + +```kotlin +fun redundant() { + val x = 4 + val y = "${x}" // <== redundant +} + +fun correctUsage() { + val x = "x" + val y = "${x.length}" // <== Ok +} +``` + +After the quick-fix is applied: + +```kotlin +fun redundant() { + val x = 4 + val y = "$x" +} + +fun correctUsage() { + val x = "x" <== Updated + val y = "${x.length}" +} +``` + +
+ +## RemoveEmptyParenthesesFromLambdaCall + +**Severity**: Weak Warning
+**Highlighting**: Strikethrough
+ +
+Unnecessary parentheses in function call with lambda + +Reports redundant empty parentheses of function calls where the only parameter is a lambda that's outside the parentheses. +Use the 'Remove unnecessary parentheses from function call with lambda' quick-fix to clean up the code. + +**Examples:** + +```kotlin +fun foo() { + listOf(1).forEach() { } +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo() { + listOf(1).forEach { } +} +``` + +
+ +## RemoveEmptyPrimaryConstructor + +**Severity**: Weak Warning
+**Highlighting**: Strikethrough
+ +
+Redundant empty primary constructor + +Reports empty primary constructors when they are implicitly available anyway. + +A primary constructor is redundant and can be safely omitted when it does not have any annotations or visibility modifiers. +Use the 'Remove empty primary constructor' quick-fix to clean up the code. + +**Examples:** + +```kotlin +class MyClassA constructor() // redundant, can be replaced with 'class MyClassA' + +annotation class MyAnnotation +class MyClassB @MyAnnotation constructor() // required because of annotation + +class MyClassC private constructor() // required because of visibility modifier +``` + +
+ +## RemoveExplicitTypeArguments + +**Severity**: Weak Warning
+**Highlighting**: Strikethrough
+ +
+Unnecessary type argument + +Reports function calls with type arguments that can be automatically inferred. Such type arguments are redundant and can be safely omitted. +Use the 'Remove explicit type arguments' quick-fix to clean up the code. + +**Examples:** + +```kotlin +// 'String' type can be inferred here +fun foo(): MutableList = mutableListOf() + +// Here 'String' cannot be inferred, type argument is required. +fun bar() = mutableListOf() +``` + +After the quick-fix is applied: + +```kotlin +fun foo(): MutableList = mutableListOf() <== Updated + +fun bar() = mutableListOf() +``` + +
+ +## RemoveForLoopIndices + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Unused loop index + +Reports `for` loops iterating over a collection using the `withIndex()` function and not using the index variable. +Use the "Remove indices in 'for' loop" quick-fix to clean up the code. + +**Examples:** + +```kotlin +fun foo(bar: List) { + for ((index : Int, value: String) in bar.withIndex()) { // <== 'index' is unused + println(value) + } +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo(bar: List) { + for (value: String in bar) { // <== '.withIndex()' and 'index' are removed + println(value) + } +} +``` + +
+ +## RemoveRedundantCallsOfConversionMethods + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Redundant call of conversion method + +Reports redundant calls to conversion methods (for example, `toString()` on a `String` or `toDouble()` +on a `Double`). +Use the 'Remove redundant calls of the conversion method' quick-fix to clean up the code. + +
+ +## RemoveRedundantQualifierName + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Redundant qualifier name + +Reports redundant qualifiers (or their parts) on class names, functions, and properties. + +A fully qualified name is an unambiguous identifier that specifies which object, function, or property a call refers to. +In the contexts where the name can be shortened, the inspection informs on the opportunity and the associated +'Remove redundant qualifier name' quick-fix allows amending the code. + +**Examples:** + +```kotlin +package my.simple.name +import kotlin.Int.Companion.MAX_VALUE + +class Foo + +fun main() { + val a = my.simple.name.Foo() // 'Foo' resides in the declared 'my.simple.name' package, qualifier is redundant + val b = kotlin.Int.MAX_VALUE // Can be replaced with 'MAX_VALUE' since it's imported + val c = kotlin.Double.MAX_VALUE // Can be replaced with 'Double.MAX_VALUE' since built-in types are imported automatically +} +``` + +After the quick-fix is applied: + +```kotlin +package my.simple.name +import kotlin.Int.Companion.MAX_VALUE + +class Foo + +fun main() { + val a = Foo() + val b = MAX_VALUE + val c = Double.MAX_VALUE +} +``` + +
+ +## RemoveSingleExpressionStringTemplate + +**Severity**: Error
+**Highlighting**: Error
+ +
+Redundant string template + +Reports single-expression string templates that can be safely removed. +**Example:** + +```kotlin +val x = "Hello" +val y = "$x" +``` + +After the quick-fix is applied: + +```kotlin +val x = "Hello" +val y = x // <== Updated +``` + +
+ +## RemoveToStringInStringTemplate + +**Severity**: Weak Warning
+**Highlighting**: Strikethrough
+ +
+Redundant call to 'toString()' in string template + +Reports calls to `toString()` in string templates that can be safely removed. +**Example:** + +```kotlin +fun foo(a: Int, b: Int) = a + b + +fun test(): String { + return "Foo: ${foo(0, 4).toString()}" // 'toString()' is redundant +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo(a: Int, b: Int) = a + b + +fun test(): String { + return "Foo: ${foo(0, 4)}" +} +``` + +
+ +## ReplaceCallWithBinaryOperator + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Can be replaced with binary operator + +Reports function calls that can be replaced with binary operators, in particular comparison-related ones. +**Example:** + +```kotlin +fun test(): Boolean { + return 2.compareTo(1) > 0 // replaceable 'compareTo()' +} +``` + +After the quick-fix is applied: + +```kotlin +fun test(): Boolean { + return 2 > 1 +} +``` + +
+ +## ReplaceCollectionCountWithSize + +**Severity**: Weak Warning
+**Highlighting**: Strikethrough
+ +
+Collection count can be converted to size + +Reports calls to `Collection.count()`. + +This function call can be replaced with `.size`. + +`.size` form ensures that the operation is O(1) and won't allocate extra objects, whereas +`count()` could be confused with `Iterable.count()`, which is O(n) and allocating. + +**Example:** + +```kotlin +fun foo() { + var list = listOf(1,2,3) + list.count() // replaceable 'count()' +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo() { + var list = listOf(1,2,3) + list.size +} +``` + +
+ +## ReplaceGetOrSet + +**Severity**: Weak Warning
+**Highlighting**: Strikethrough
+ +
+Explicit 'get' or 'set' call + +Reports explicit calls to `get` or `set` functions which can be replaced by an indexing operator `[]`. + +Kotlin allows custom implementations for the predefined set of operators on types. +To overload an operator, you can mark the corresponding function with the `operator` modifier: + +```kotlin +operator fun get(index: Int) {} +operator fun set(index: Int, value: Int) {} +``` + +The functions above correspond to the indexing operator. + +**Example:** + +```kotlin +class Test { + operator fun get(i: Int): Int = 0 +} + +fun test() { + Test().get(0) // replaceable 'get()' +} +``` + +After the quick-fix is applied: + +```kotlin +class Test { + operator fun get(i: Int): Int = 0 +} + +fun test() { + Test()[0] +} +``` + +
+ +## ReplaceGuardClauseWithFunctionCall + +**Severity**: Error
+**Highlighting**: Strikethrough
+ +
+Guard clause can be replaced with Kotlin's function call + +Reports guard clauses that can be replaced with a function call. +**Example:** + +```kotlin +fun test(foo: Int?) { + if (foo == null) throw IllegalArgumentException("foo") // replaceable clause +} +``` + +After the quick-fix is applied: + +```kotlin +fun test(foo: Int?) { + checkNotNull(foo) +} +``` + +
+ +## ReplaceManualRangeWithIndicesCalls + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Range can be converted to indices or iteration + +Reports `until` and `rangeTo` operators that can be replaced with `Collection.indices` or iteration over collection inside `for` loop. +Using syntactic sugar makes your code simpler. + +The quick-fix replaces the manual range with the corresponding construction. + +**Example:** + +```kotlin +fun main(args: Array) { + for (index in 0..args.size - 1) { + println(args[index]) + } +} +``` + +After the quick-fix is applied: + +```kotlin +fun main(args: Array) { + for (element in args) { + println(element) + } +} +``` + +
+ +## ReplaceRangeToWithUntil + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+rangeTo' or the '..' call should be replaced with 'until' + +Reports calls to `rangeTo` or the `..` operator instead of calls to `until`. +Using corresponding functions makes your code simpler. + +The quick-fix replaces `rangeTo` or the `..` call with `until`. + +**Example:** + +```kotlin +fun foo(a: Int) { + for (i in 0..a - 1) { + + } +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo(a: Int) { + for (i in 0 until a) { + + } +} +``` + +
+ +## ReplaceReadLineWithReadln + +**Severity**: Weak Warning
+**Highlighting**: Strikethrough
+ +
+readLine' can be replaced with 'readln' or 'readlnOrNull' + +Reports calls to `readLine()` that can be replaced with `readln()` or `readlnOrNull()`. + +Using corresponding functions makes your code simpler. + +The quick-fix replaces `readLine()!!` with `readln()` and `readLine()` with `readlnOrNull()`. + +**Examples:** + +```kotlin +val x = readLine()!! +val y = readLine()?.length +``` + +After the quick-fix is applied: + +```kotlin +val x = readln() +val y = readlnOrNull()?.length +``` + +
+ +## ReplaceSizeCheckWithIsNotEmpty + +**Severity**: Error
+**Highlighting**: Error
+ +
+Size check can be replaced with 'isNotEmpty()' + +Reports size checks of `Collections/Array/String` that should be replaced with `isNotEmpty()`. +Using `isNotEmpty()` makes your code simpler. + +The quick-fix replaces the size check with `isNotEmpty()`. + +**Example:** + +```kotlin +fun foo() { + val arrayOf = arrayOf(1, 2, 3) + arrayOf.size > 0 +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo() { + val arrayOf = arrayOf(1, 2, 3) + arrayOf.isNotEmpty() +} +``` + +
+ +## ReplaceSizeZeroCheckWithIsEmpty + +**Severity**: Error
+**Highlighting**: Error
+ +
+Size zero check can be replaced with 'isEmpty()' + +Reports `size == 0` checks on `Collections/Array/String` that should be replaced with `isEmpty()`. +Using `isEmpty()` makes your code simpler. + +The quick-fix replaces the size check with `isEmpty()`. + +**Example:** + +```kotlin +fun foo() { + val arrayOf = arrayOf(1, 2, 3) + arrayOf.size == 0 +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo() { + val arrayOf = arrayOf(1, 2, 3) + arrayOf.isEmpty() +} +``` + +
+ +## ReplaceSubstringWithTake + +**Severity**: Error
+**Highlighting**: Strikethrough
+ +
+substring' call should be replaced with 'take' call + +Reports calls like `s.substring(0, x)` that can be replaced with `s.take(x)`. +Using `take()` makes your code simpler. + +The quick-fix replaces the `substring` call with `take()`. + +**Example:** + +```kotlin +fun foo(s: String) { + s.substring(0, 10) +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo(s: String) { + s.take(10) +} +``` + +
+ +## ReplaceToStringWithStringTemplate + +**Severity**: Information
+**Highlighting**: None
+ +
+Call of 'toString' could be replaced with string template + +Reports `toString` function calls that can be replaced with a string template. +Using string templates makes your code simpler. + +The quick-fix replaces `toString` with a string template. + +**Example:** + +```kotlin +fun test(): String { + val x = 1 + return x.toString() +} +``` + +After the quick-fix is applied: + +```kotlin +fun test(): String { + val x = 1 + return "$x" +} +``` + +
+ +## ReplaceWithOperatorAssignment + +**Severity**: Error
+**Highlighting**: Error
+ +
+Assignment can be replaced with operator assignment + +Reports modifications of variables with a simple assignment (such as `y = y + x`) that can be replaced with an operator assignment. +The quick-fix replaces the assignment with an assignment operator. + +**Example:** + +```kotlin +fun foo() { + val list = mutableListOf(1, 2, 3) + list = list + 4 +} +``` + +After the quick-fix is applied: + +```kotlin +fun foo() { + val list = mutableListOf(1, 2, 3) + list += 4 +} +``` + +
+ +## ScopeFunctionConversion + +**Severity**: Information
+**Highlighting**: None
+ +
+Scope function can be converted to another one + +Reports scope functions (`let`, `run`, `apply`, `also`) that can be converted between each other. +Using corresponding functions makes your code simpler. + +The quick-fix replaces the scope function to another one. + +**Example:** + +```kotlin +val x = "".let { + it.length +} +``` + +After the quick-fix is applied: + +```kotlin +val x = "".run { + length +} +``` + +
+ +## SelfAssignment + +**Severity**: Error
+**Highlighting**: Error
+ +
+Redundant assignment + +Reports assignments of a variable to itself. +The quick-fix removes the redundant assignment. + +**Example:** + +```kotlin +fun test() { + var bar = 1 + bar = bar +} +``` + +After the quick-fix is applied: + +```kotlin +fun test() { + var bar = 1 +} +``` + +
+ +## SimplifiableCallChain + +**Severity**: Weak Warning
+**Highlighting**: Strikethrough
+ +
+Call chain on collection type can be simplified + +Reports two-call chains replaceable by a single call. +It can help you to avoid redundant code execution. + +The quick-fix replaces the call chain with a single call. + +**Example:** + +```kotlin +fun main() { + listOf(1, 2, 3).filter { it > 1 }.count() +} +``` + +After the quick-fix is applied: + +```kotlin +fun main() { + listOf(1, 2, 3).count { it > 1 } +} +``` + +
+ +## SimplifyBooleanWithConstants + +**Severity**: Error
+**Highlighting**: Error
+ +
+Boolean expression can be simplified + +Reports boolean expression parts that can be reduced to constants. +The quick-fix simplifies the condition. + +**Example:** + +```kotlin +fun use(arg: Boolean) { + if (false == arg) { + + } +} +``` + +After the quick-fix is applied: + +```kotlin +fun use(arg: Boolean) { + if (!arg) { + + } +} +``` + +
+ +## TrailingComma + +**Severity**: Error
+**Highlighting**: Error
+ +
+Trailing comma recommendations + +Reports trailing commas that do not follow the recommended [style guide](https://kotlinlang.org/docs/coding-conventions.html#trailing-commas). + +
+ +## UnlabeledReturnInsideLambda + +**Severity**: Error
+**Highlighting**: Error
+ +
+Unlabeled return inside lambda + +Reports unlabeled `return` expressions inside inline lambda. +Such expressions can be confusing because it might be unclear which scope belongs to `return`. + +**Change to return@…** quick-fix can be used to amend the code automatically. + +Example: + +```kotlin +fun test(list: List) { + list.forEach { + // This return expression returns from the function test + // One can change it to return@forEach to change the scope + if (it == 10) return + } +} +``` + +After the quick-fix is applied: + +```kotlin +fun test(list: List) { + list.forEach { + if (it == 10) return@test + } +} +``` + +
+ +## UnnecessaryVariable + +**Severity**: Weak Warning
+**Highlighting**: Strikethrough
+ +
+Unnecessary local variable + +Reports local variables that are used only in the very next `return` statement or are exact copies of other variables. +Such variables can be safely inlined to make the code more clear. + +**Example:** + +```kotlin +fun sum(a: Int, b: Int): Int { + val c = a + b + return c +} +``` + +After the quick-fix is applied: + +```kotlin +fun sum(a: Int, b: Int): Int { + return a + b +} +``` + +Configure the inspection: + +Use the **Report immediately returned variables** option to report immediately returned variables. +When given descriptive names, such variables may improve the code readability in some cases, that's why this option is disabled by default. + +
+ +## UnusedEquals + +**Severity**: Error
+**Highlighting**: Error
+ +
+Unused equals expression + +Reports unused `equals`(`==`) expressions. + +
+ +## UnusedReceiverParameter + +**Severity**: Warning
+**Highlighting**: Strikethrough
+ +
+Unused receiver parameter + +Reports receiver parameter of extension functions and properties that is not used. +**Remove redundant receiver parameter** can be used to amend the code automatically. + +
+ +## UseExpressionBody + +**Severity**: Warning
+**Highlighting**: Warning
+ +
+Expression body syntax is preferable here + +Reports `return` expressions (one-liners or `when`) that can be replaced with expression body syntax. +Expression body syntax is recommended by the [style guide](https://kotlinlang.org/docs/coding-conventions.html#functions). + +**Convert to expression body** quick-fix can be used to amend the code automatically. + +Example: + +```kotlin +fun sign(x: Int): Int { + return when { // <== can be simplified + x < 0 -> -1 + x > 0 -> 1 + else -> 0 + } +} +``` + +After the quick-fix is applied: + +```kotlin +fun sign(x: Int): Int = when { + x < 0 -> -1 + x > 0 -> 1 + else -> 0 +} +``` + +
+ +## WarningOnMainUnusedParameterMigration + +**Severity**: Weak Warning
+**Highlighting**: Weak Warning
+ +
+Unused 'args' on 'main' since 1.4 + +Reports `main` function with an unused single parameter. +Since Kotlin 1.4, it is possible to use the `main` function without parameter as the entry point to the Kotlin program. +The compiler reports a warning for the `main` function with an unused parameter. + +
+ From fa9e71a664cc94bd21fd98171aaf46754f27b0f7 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Thu, 16 Nov 2023 15:45:01 +0400 Subject: [PATCH 05/10] feat: add profiles_settings.xml --- .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .idea/inspectionProfiles/profiles_settings.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..76c9db1 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file From cf111d6e8ddc6e7f37891040a5e6db111a0b2bc9 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Thu, 16 Nov 2023 15:45:38 +0400 Subject: [PATCH 06/10] fix: do not ignore `inspectionProfiles` --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7ba49d9..3d70f3a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ build/ !**/src/test/**/build/ .idea +!.idea/inspectionProfiles/ *.iws *.iml *.ipr From fd7a43fe86f63c72ec2023b04882eb95d728e5fd Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Thu, 16 Nov 2023 15:45:54 +0400 Subject: [PATCH 07/10] fix: ignore the `inspectionProfiles` README --- .courseignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.courseignore b/.courseignore index bb9a83f..959ba49 100644 --- a/.courseignore +++ b/.courseignore @@ -1,2 +1,3 @@ README.md /.run +/.idea/inspectionProfiles/README.md From da16f3c387d6e010707711de9a3f25bf705cfb8c Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Thu, 16 Nov 2023 17:31:59 +0400 Subject: [PATCH 08/10] feat: add information about adapted inspections fix: fix notes --- README.md | 114 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 63 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 16140c7..ed9c002 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,7 @@ [![Gradle Build With Detekt](https://github.com/jetbrains-academy/kotlin-course-template/actions/workflows/gradle-build-with-detekt.yml/badge.svg)](https://github.com/jetbrains-academy/kotlin-course-template/actions/workflows/gradle-build-with-detekt.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -> **Note** -> +> ![NOTE] > Click the Use this template button and clone it in IntelliJ IDEA. **JetBrains Academy Kotlin course template** is a repository that provides a @@ -20,8 +19,7 @@ linking to the proper documentation pages, and keeping everything organized. If you're still not quite sure what this is all about, read our introduction: [What is the JetBrains Academy plugin?][docs:intro] -> **Note** -> +> ![NOTE] > Click the Watch button on the top to be notified about releases containing new features and fixes. ### Table of contents @@ -33,6 +31,7 @@ In this README, we will highlight the following elements of template-project cre - [Course info configuration file](#course-info-configuration-file) - [Course ignore file](#course-ignore-file) - [Sample code](#sample-code) +- [Adapted inspections](#adapted-inspections) - [Testing](#testing) - [Predefined Run/Debug configurations](#predefined-rundebug-configurations) - [Continuous integration](#continuous-integration) @@ -84,51 +83,56 @@ A generated JetBrains Academy Kotlin Course Template repository contains the fol ``` . -├── .github/ GitHub Actions workflows -├── .run/ Predefined Run/Debug Configurations -├── build/ Output build directory -├── gradle -│ └── wrapper/ Gradle Wrapper -├── common Course sources common for all sections -│ └── src -│ └── main -│ ├── kotlin/ Kotlin production sources -│ └── resources/ Resources - images, icons -├── courseSection/ An example of the course section -│ ├── courseLesson/ An example of the course lesson -│ │ ├── theoryTask/ An example of a theory task -│ │ │ ├── src/ Task sources -│ │ │ │ └── ... -│ │ │ ├── task.md Task/theory description -│ │ │ └── task-info.yaml Task config file -│ │ ├── quizTask/ An example of a quiz task -│ │ │ ├── src/ Task sources -│ │ │ │ └── ... -│ │ │ ├── task.md Task/quiz description -│ │ │ └── task-info.yaml Task config file -│ │ ├── programmingTask/ An example of a programming task -│ │ │ ├── src/ Task sources -│ │ │ │ └── ... -│ │ │ ├── test/ Task tests -│ │ │ │ └── ... -│ │ │ ├── task.md Task description -│ │ │ └── task-info.yaml Task config file -│ │ └── lesson-info.yaml Lesson config file -│ ├── courseFrameworkLesson/ An example of the course framework lesson -│ │ ├── ... Several examples of lessons -│ │ └── lesson-info.yaml Lesson config file -│ └── section-info.yaml Section config file -├── .courseignore Course ignoring rules -├── .gitignore Git ignoring rules -├── build.gradle.kts Gradle configuration -├── course-info.yaml Course info configuration file -├── detekt.yml Detekt configuration file -├── gradle.properties Gradle configuration properties -├── gradlew *nix Gradle Wrapper script -├── gradlew.bat Windows Gradle Wrapper script -├── LICENSE License, MIT by default -├── README.md README -└── settings.gradle.kts Gradle project settings +├── .github/ GitHub Actions workflows +├── .idea/ +│ └── inspectionProfiles/ Adapted inspection files +│ ├── Custom_Inspections.xml Inspection config +│ ├── profiles_settings.xml Inspection profile settings +│ └── README.md Inspection descriptions +├── .run/ Predefined Run/Debug Configurations +├── build/ Output build directory +├── gradle +│ └── wrapper/ Gradle Wrapper +├── common Course sources common for all sections +│ └── src +│ └── main +│ ├── kotlin/ Kotlin production sources +│ └── resources/ Resources - images, icons +├── courseSection/ An example of the course section +│ ├── courseLesson/ An example of the course lesson +│ │ ├── theoryTask/ An example of a theory task +│ │ │ ├── src/ Task sources +│ │ │ │ └── ... +│ │ │ ├── task.md Task/theory description +│ │ │ └── task-info.yaml Task config file +│ │ ├── quizTask/ An example of a quiz task +│ │ │ ├── src/ Task sources +│ │ │ │ └── ... +│ │ │ ├── task.md Task/quiz description +│ │ │ └── task-info.yaml Task config file +│ │ ├── programmingTask/ An example of a programming task +│ │ │ ├── src/ Task sources +│ │ │ │ └── ... +│ │ │ ├── test/ Task tests +│ │ │ │ └── ... +│ │ │ ├── task.md Task description +│ │ │ └── task-info.yaml Task config file +│ │ └── lesson-info.yaml Lesson config file +│ ├── courseFrameworkLesson/ An example of the course framework lesson +│ │ ├── ... Several examples of lessons +│ │ └── lesson-info.yaml Lesson config file +│ └── section-info.yaml Section config file +├── .courseignore Course ignoring rules +├── .gitignore Git ignoring rules +├── build.gradle.kts Gradle configuration +├── course-info.yaml Course info configuration file +├── detekt.yml Detekt configuration file +├── gradle.properties Gradle configuration properties +├── gradlew *nix Gradle Wrapper script +├── gradlew.bat Windows Gradle Wrapper script +├── LICENSE License, MIT by default +├── README.md README +└── settings.gradle.kts Gradle project settings ``` ## Course info configuration file @@ -177,8 +181,7 @@ only task files, without intermediate steps. You can read more about framework lessons in the official documentation in the [Framework Lessons Creation][ref:framework.lessons.creation] section. -> **Note** -> +> [!NOTE] > Click Course Creator -> Create Course Preview in the context menu in the root of the repository to create a course preview. @@ -186,6 +189,13 @@ The JetBrains Academy plugin provides five different types of tasks, and you can combine them inside one lesson (whether regular or framework). You can read more about tasks in the official documentation in the [Task][ref:tasks] section. +## Adapted inspections +The template also includes adapted Kotlin inspections in order to provide better learning experience. +This means that the IDE will highlight the most popular code issue that students encounter. +To learn more about the inspections please refer to [this][file:inspections.readme] README file. + +If you don't want to use this inspections, then just delete the [inspectionProfiles][file:inspections] folder. + ## Testing To check the programming exercises for [**edu**][ref:tasks] tasks, you need to write tests. @@ -262,6 +272,8 @@ In the `.github/workflows` directory, you can find definitions for the following [file:courseignore]: .courseignore [file:course.lesson.tests]: ./courseSection/courseLesson/programmingTask/test/Tests.kt [file:course.framework.lesson.tests]: ./courseSection/courseFrameworkLesson/programmingTask/test/Tests.kt +[file:inspections]: ./.idea/inspectionProfiles +[file:inspections.readme]: ./.idea/inspectionProfiles/README.md [gradle]: https://gradle.org From d0aee8b28f355b35ac8f3d5209d5267d66969e58 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Thu, 16 Nov 2023 17:32:43 +0400 Subject: [PATCH 09/10] style: fix some style issues --- .idea/inspectionProfiles/README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.idea/inspectionProfiles/README.md b/.idea/inspectionProfiles/README.md index a06ad88..3728ae7 100644 --- a/.idea/inspectionProfiles/README.md +++ b/.idea/inspectionProfiles/README.md @@ -1,11 +1,12 @@ # Inspection descriptions -This README file contains descriptions of all inspections in the [config](./Custom_Inspections.xml) file. +This README file contains descriptions of all adapted inspections in the [config](./Custom_Inspections.xml) file. -> [!NOTE] -> This file, as well as the config file, contains only the most common inspections, that have been adapted for better teaching experience. -> For a complete list of inspections available in the IntelliJ platform, see the Kotlin Inspections tab (Settings -> Editor -> Inspections -> Kotlin). +> [!NOTE] +> This file, as well as the config file, contains only the most common inspections, that have been adapted for better learning experience. +> For a complete list of inspections available in the IntelliJ platform, see the Kotlin Inspections tab (Settings -> Editor -> Inspections -> Kotlin). The `Severity` field (`level` in the config file) indicates how the inspections will be displayed in the upper right corner of the editor and in the Problems tab. Some of the possible values are: + | Name | Config name | Example | |--------------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------| | Error | ERROR | image | @@ -13,16 +14,16 @@ The `Severity` field (`level` in the config file) indicates how the inspections | Weak Warning | WEAK WARNING | image | The `Highlighting` field (`editorAttributes` in the config file) indicates how the inspection will be highlighted in the IDE. Some of the possible values are: -| Name | Config name | Example | -|---------------|-------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------| + +| Name | Config name | Example | +|---------------|-------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------| | Error | ERRORS_ATTRIBUTES | image | | Warning | WARNING_ATTRIBUTES | image | | Weak Warning | INFO_ATTRIBUTES | image | | Strikethrough | MARKED_FOR_REMOVAL_ATTRIBUTES | image | > [!NOTE] -> To add a new inspection to the config file please use the Kotlin Inspections tab -> where you could turn on/off an inspection and choose its severity and/or highlighting. +> To alter the config file please use the Kotlin Inspections tab where you could turn on/off inspections and choose theirs severity and/or highlighting. ## AddOperatorModifier From 49fcd96efed3cc37a6bbd38f2065e2c1e8aa2612 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Thu, 16 Nov 2023 19:34:02 +0400 Subject: [PATCH 10/10] fix: fix PR issue --- .idea/inspectionProfiles/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.idea/inspectionProfiles/README.md b/.idea/inspectionProfiles/README.md index 3728ae7..7a4d293 100644 --- a/.idea/inspectionProfiles/README.md +++ b/.idea/inspectionProfiles/README.md @@ -25,6 +25,8 @@ The `Highlighting` field (`editorAttributes` in the config file) indicates how t > [!NOTE] > To alter the config file please use the Kotlin Inspections tab where you could turn on/off inspections and choose theirs severity and/or highlighting. +Below are detailed descriptions of all the inspections in the current configuration file. + ## AddOperatorModifier **Severity**: Weak Warning