From 9802c54b51df9272170b1931cc3dff52bd077a1b Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 12 Jan 2021 17:24:12 +0300 Subject: [PATCH 1/3] Minor infrastructure improvements ### What's done: * Fixed kotlin compiler warnings * Updated version in build.gradle.kts for diktat-gradle-plugin * Added update of info/buildSrc/gradle.properties version during release workflow * Run gradle functional tests in parallel --- .github/workflows/release.yml | 2 ++ diktat-gradle-plugin/build.gradle.kts | 3 ++- diktat-rules/pom.xml | 1 + .../diktat/ruleset/rules/identifiers/LocalVariablesRule.kt | 6 +++--- .../kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt | 4 ++-- .../org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt | 2 +- .../ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt | 2 +- .../diktat/ruleset/utils/VariablesWithUsagesSearchTest.kt | 1 - 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c2260a5bbb..f43f80edb2 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/radle.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) From e02c0f9dfb9c082a84836169450fce493245f946 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 12 Jan 2021 17:34:03 +0300 Subject: [PATCH 2/3] Minor infrastructure improvements ### What's done: * One-phase build in build_and_test.yml instead of two --- .github/workflows/build_and_test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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: From dfe5935ce9455db838459d7459e00a3aeab221c7 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Wed, 13 Jan 2021 17:23:50 +0300 Subject: [PATCH 3/3] Update .github/workflows/release.yml Co-authored-by: Alexander Tsay <48321920+aktsay6@users.noreply.github.com> --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f43f80edb2..f864cb1cd6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -79,7 +79,7 @@ jobs: 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/radle.properties + echo "version=$next_snapshot_version" > info/buildSrc/gradle.properties - name: Create pull request uses: peter-evans/create-pull-request@v3 with: