diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 6dbc1c6113..5f3983c7f5 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -22,10 +22,8 @@ jobs: key: ${{ runner.os }}-maven-build-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven-build- - - name: Maven Package - run: mvn -B clean package -DskipTests - name: Maven Install - run: mvn -B install + run: mvn -B clean install - name: Code coverage report uses: codecov/codecov-action@v1 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c2260a5bbb..f864cb1cd6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -78,6 +78,8 @@ jobs: sed -i "s/$PREVIOUS_VERSION/$RELEASE_VERSION/g" $file || echo "File $file hasn't been updated!" cp diktat-rules/src/main/resources/diktat-analysis.yml $(dirname $file) done + next_snapshot_version=$(printf 'VERSION=${project.version}\n0\n' | mvn help:evaluate | grep '^VERSION' | cut -d= -f2) + echo "version=$next_snapshot_version" > info/buildSrc/gradle.properties - name: Create pull request uses: peter-evans/create-pull-request@v3 with: diff --git a/diktat-gradle-plugin/build.gradle.kts b/diktat-gradle-plugin/build.gradle.kts index 08f576145d..5bf9b08466 100644 --- a/diktat-gradle-plugin/build.gradle.kts +++ b/diktat-gradle-plugin/build.gradle.kts @@ -20,7 +20,7 @@ repositories { // default value is needed for correct gradle loading in IDEA; actual value from maven is used during build val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.39.0") as String -val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "0.2.0" +val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "0.3.0" val junitVersion = project.properties.getOrDefault("junitVersion", "5.7.0") as String val jacocoVersion = project.properties.getOrDefault("jacocoVersion", "0.8.6") as String dependencies { @@ -98,6 +98,7 @@ tasks.getByName("functionalTest") { dependsOn("test") testClassesDirs = functionalTest.output.classesDirs classpath = functionalTest.runtimeClasspath + maxParallelForks = Runtime.getRuntime().availableProcessors() doLast { if (getCurrentOperatingSystem().isWindows) { // workaround for https://github.com/koral--/jacoco-gradle-testkit-plugin/issues/9 diff --git a/diktat-rules/pom.xml b/diktat-rules/pom.xml index 2c166e9909..280f6d6ceb 100644 --- a/diktat-rules/pom.xml +++ b/diktat-rules/pom.xml @@ -110,6 +110,7 @@ + src/main/kotlin src/test/kotlin ${project.basedir}/src/main/kotlin diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/identifiers/LocalVariablesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/identifiers/LocalVariablesRule.kt index dbcd5a8061..9c4676ccf7 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/identifiers/LocalVariablesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/identifiers/LocalVariablesRule.kt @@ -91,7 +91,7 @@ class LocalVariablesRule(private val configRules: List) : Rule("loc val declarationScope = property.getDeclarationScope() val firstUsageStatementLine = getFirstUsageStatementOrBlock(usages, declarationScope).node.getLineNumber() - val firstUsage = usages.minBy { it.node.getLineNumber() }!! + val firstUsage = usages.minByOrNull { it.node.getLineNumber() }!! // should skip val and var before it's statement val offset = property @@ -184,7 +184,7 @@ class LocalVariablesRule(private val configRules: List) : Rule("loc */ @Suppress("UnsafeCallOnNullableType", "GENERIC_VARIABLE_WRONG_DECLARATION") private fun getFirstUsageStatementOrBlock(usages: List, declarationScope: KtBlockExpression?): PsiElement { - val firstUsage = usages.minBy { it.node.getLineNumber() }!! + val firstUsage = usages.minByOrNull { it.node.getLineNumber() }!! val firstUsageScope = firstUsage.getParentOfType(true) return if (firstUsageScope == declarationScope) { @@ -194,7 +194,7 @@ class LocalVariablesRule(private val configRules: List) : Rule("loc .find { it.parent == declarationScope }!! } else { // first usage is in deeper block compared to declaration, need to check how close is declaration to the first line of the block - usages.minBy { it.node.getLineNumber() }!! + usages.minByOrNull { it.node.getLineNumber() }!! .parentsWithSelf .find { it.parent == declarationScope }!! } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt index 9acba46866..157dddcb5f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt @@ -603,7 +603,7 @@ fun ASTNode.isChildAfterAnother(child: ASTNode, afterChild: ASTNode): Boolean = * @return boolean result */ fun ASTNode.isChildAfterGroup(child: ASTNode, group: List): Boolean = - getChildren(null).indexOf(child) > (group.map { getChildren(null).indexOf(it) }.max() ?: 0) + getChildren(null).indexOf(child) > (group.map { getChildren(null).indexOf(it) }.maxOrNull() ?: 0) /** * Checks whether [child] is before [beforeChild] among the children of [this] node @@ -637,7 +637,7 @@ fun ASTNode.areChildrenBeforeChild(children: List, beforeChild: ASTNode @Suppress("UnsafeCallOnNullableType") fun ASTNode.areChildrenBeforeGroup(children: List, group: List): Boolean { require(children.isNotEmpty() && group.isNotEmpty()) { "no sense to operate on empty lists" } - return children.map { getChildren(null).indexOf(it) }.max()!! < group.map { getChildren(null).indexOf(it) }.min()!! + return children.map { getChildren(null).indexOf(it) }.maxOrNull()!! < group.map { getChildren(null).indexOf(it) }.minOrNull()!! } /** diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt index e873f1dd83..fbc1789e8d 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt @@ -110,5 +110,5 @@ abstract class VariablesSearch(val node: ASTNode, private val filterForVariables * * @param node an [ASTNode] */ -@SuppressWarnings("FunctionOnlyReturningConstant") +@Suppress("UNUSED_PARAMETER", "FunctionOnlyReturningConstant") fun default(node: KtProperty) = true diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt index ad68718a6b..04e850c62f 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt @@ -351,7 +351,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { @Test @Tag(WarningNames.WRONG_WHITESPACE) - fun `there should be no space before ? in nullable types`() { + fun `there should be no space before question mark in nullable types`() { lintMethod( """ |class Example { diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/VariablesWithUsagesSearchTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/VariablesWithUsagesSearchTest.kt index d0369f181c..5264de2399 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/VariablesWithUsagesSearchTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/VariablesWithUsagesSearchTest.kt @@ -332,7 +332,6 @@ class VariablesWithUsagesSearchTest { val var1 = keys.elementAt(0) val var2 = keys.elementAt(1) val var3 = keys.elementAt(2) - val var4 = keys.elementAt(3) assertEquals("var v = 0", var1) assertEquals(0, vars[var1]?.size) assertEquals("var v = 1", var2)