diff --git a/README.md b/README.md index a942c33792..d00affdb1c 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Main features of diktat are the following: ```shell # another option is "brew install ktlint" - curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.47.1/ktlint && chmod a+x ktlint + curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.46.1/ktlint && chmod a+x ktlint ``` 1. Load diKTat manually: [here](https://github.com/saveourtool/diKTat/releases/download/v1.2.4/diktat-1.2.4.jar) diff --git a/diktat-gradle-plugin/build.gradle.kts b/diktat-gradle-plugin/build.gradle.kts index d83551ed0b..e478515701 100644 --- a/diktat-gradle-plugin/build.gradle.kts +++ b/diktat-gradle-plugin/build.gradle.kts @@ -28,7 +28,7 @@ repositories { // default value is needed for correct gradle loading in IDEA; actual value from maven is used during build // To debug gradle plugin, please set `diktatVersion` manually to the current maven project version. -val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.47.1") as String +val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.46.1") as String val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "1.2.3" val junitVersion = project.properties.getOrDefault("junitVersion", "5.8.1") as String val jacocoVersion = project.properties.getOrDefault("jacocoVersion", "0.8.7") as String diff --git a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt index 311564e9eb..34f4bcb622 100644 --- a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt +++ b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt @@ -11,10 +11,9 @@ import com.pinterest.ktlint.core.LintError import com.pinterest.ktlint.core.Reporter import com.pinterest.ktlint.core.RuleExecutionException import com.pinterest.ktlint.core.RuleSet -import com.pinterest.ktlint.core.api.Baseline -import com.pinterest.ktlint.core.api.Baseline.Status.VALID -import com.pinterest.ktlint.core.api.containsLintError -import com.pinterest.ktlint.core.api.loadBaseline +import com.pinterest.ktlint.core.internal.CurrentBaseline +import com.pinterest.ktlint.core.internal.containsLintError +import com.pinterest.ktlint.core.internal.loadBaseline import com.pinterest.ktlint.reporter.baseline.BaselineReporter import com.pinterest.ktlint.reporter.html.HtmlReporter import com.pinterest.ktlint.reporter.json.JsonReporter @@ -121,7 +120,7 @@ abstract class DiktatBaseMojo : AbstractMojo() { listOf(DiktatRuleSetProvider(configFile).get()) } val baselineResults = baseline?.let { loadBaseline(it.absolutePath) } - ?: Baseline(status = VALID) + ?: CurrentBaseline(emptyMap(), false) reporterImpl = resolveReporter(baselineResults) reporterImpl.beforeAll() val lintErrors: MutableList = mutableListOf() @@ -129,7 +128,7 @@ abstract class DiktatBaseMojo : AbstractMojo() { inputs .map(::File) .forEach { - checkDirectory(it, lintErrors, baselineResults.lintErrorsPerFile, ruleSets) + checkDirectory(it, lintErrors, baselineResults.baselineRules ?: emptyMap(), ruleSets) } reporterImpl.afterAll() @@ -138,7 +137,7 @@ abstract class DiktatBaseMojo : AbstractMojo() { } } - private fun resolveReporter(baselineResults: Baseline): Reporter { + private fun resolveReporter(baselineResults: CurrentBaseline): Reporter { val output = if (this.output.isBlank()) { if (this.githubActions) { // need to set user.home specially for ktlint, so it will be able to put a relative path URI in SARIF @@ -166,7 +165,7 @@ abstract class DiktatBaseMojo : AbstractMojo() { } } - return if (baselineResults.status != VALID) { + return if (baselineResults.baselineGenerationNeeded) { val baselineReporter = BaselineReporter(PrintStream(FileOutputStream(baseline, true))) return Reporter.from(actualReporter, baselineReporter) } else { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt index b37b46f15b..96487958a1 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt @@ -34,7 +34,7 @@ abstract class DiktatRule( /** * The **file-specific** error emitter, initialized in - * [beforeVisitChildNodes] and used in [logic] implementations. + * [visit] and used in [logic] implementations. * * Since the file is indirectly a part of the state of a `Rule`, the same * `Rule` instance should **never be re-used** to check more than a single @@ -42,13 +42,13 @@ abstract class DiktatRule( * See the documentation of the [Rule] class for more details. * * @see Rule - * @see beforeVisitChildNodes + * @see visit * @see logic */ lateinit var emitWarn: EmitType @Suppress("TooGenericExceptionThrown") - final override fun beforeVisitChildNodes( + final override fun visit( node: ASTNode, autoCorrect: Boolean, emit: EmitType diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/OrderedRuleSet.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/OrderedRuleSet.kt index 7040128b60..62178544db 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/OrderedRuleSet.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/OrderedRuleSet.kt @@ -8,7 +8,6 @@ import org.cqfn.diktat.common.config.rules.qualifiedWithRuleSetId import org.cqfn.diktat.ruleset.constants.EmitType import com.pinterest.ktlint.core.Rule import com.pinterest.ktlint.core.RuleSet -import com.pinterest.ktlint.core.api.EditorConfigProperties import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** @@ -81,16 +80,6 @@ class OrderedRuleSet(id: String, vararg rules: Rule) : RuleSet(id, rules = adjus val rule: Rule, prevRule: Rule ) : Rule(rule.id.qualifiedWithRuleSetId(ruleSetId), adjustVisitorModifiers(ruleSetId, rule, prevRule)) { - override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) = - rule.beforeFirstNode(editorConfigProperties) - - override fun beforeVisitChildNodes( - node: ASTNode, - autoCorrect: Boolean, - emit: EmitType, - ) = - rule.beforeVisitChildNodes(node, autoCorrect, emit) - @Deprecated( "Marked for deletion in ktlint 0.48.0", replaceWith = ReplaceWith("beforeVisitChildNodes(node, autoCorrect, emit)"), @@ -101,16 +90,6 @@ class OrderedRuleSet(id: String, vararg rules: Rule) : RuleSet(id, rules = adjus emit: EmitType, ) = rule.visit(node, autoCorrect, emit) - - override fun afterVisitChildNodes( - node: ASTNode, - autoCorrect: Boolean, - emit: EmitType, - ) = - rule.afterVisitChildNodes(node, autoCorrect, emit) - - override fun afterLastNode() = - rule.afterLastNode() } } } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/RunInScript.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/RunInScript.kt index bd4259cecf..c00cfc01eb 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/RunInScript.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/RunInScript.kt @@ -27,7 +27,7 @@ class RunInScript(private val configRules: List) : Rule(NAME_ID.qua private var isFixMode: Boolean = false private lateinit var emitWarn: EmitType - override fun beforeVisitChildNodes( + override fun visit( node: ASTNode, autoCorrect: Boolean, emit: EmitType diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/rules/OrderedRuleSetTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/rules/OrderedRuleSetTest.kt index 83112cc15b..de65572f0b 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/rules/OrderedRuleSetTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/rules/OrderedRuleSetTest.kt @@ -134,12 +134,19 @@ class OrderedRuleSetTest { * | * V * C(File) -> C(Node) -> C(Leaf) + * + * val expectedRuleInvocationOrder = rules.asSequence() + * .map(Rule::id) + * .flatMap { ruleId -> + * generateSequence { ruleId }.take(astNodeCount) + * } + * .toList() */ - val expectedRuleInvocationOrder = rules.asSequence() - .map(Rule::id) - .flatMap { ruleId -> - generateSequence { ruleId }.take(astNodeCount) - } + val expectedRuleInvocationOrder = generateSequence { + rules.map(Rule::id) + } + .take(astNodeCount) + .flatten() .toList() assertThat(actualRuleInvocationOrder) @@ -152,7 +159,7 @@ class OrderedRuleSetTest { visitorModifiers: Set = emptySet(), onVisit: (Rule) -> Unit = { } ): Rule = object : Rule(id.qualifiedWithRuleSetId(), visitorModifiers) { - override fun beforeVisitChildNodes( + override fun visit( node: ASTNode, autoCorrect: Boolean, emit: EmitType diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt index 0adc251de5..db62fe1d78 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt @@ -792,9 +792,9 @@ private class PrettyPrintingVisitor(private val elementType: IElementType, private val maxLevel: Int, private val expected: String ) : Rule("print-ast") { - override fun beforeVisitChildNodes(node: ASTNode, - autoCorrect: Boolean, - emit: EmitType + override fun visit(node: ASTNode, + autoCorrect: Boolean, + emit: EmitType ) { if (node.elementType == elementType) { Assertions.assertEquals( diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt index 28af015790..7e5386948b 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt @@ -51,9 +51,10 @@ internal fun applyToCode(code: String, text = code, ruleSets = listOf( RuleSet("test", object : Rule("astnode-utils-test") { - override fun beforeVisitChildNodes(node: ASTNode, - autoCorrect: Boolean, - emit: EmitType + override fun visit( + node: ASTNode, + autoCorrect: Boolean, + emit: EmitType ) { applyToNode(node, counter) } diff --git a/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt b/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt index 37c753bf73..04c35ae6ea 100644 --- a/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt +++ b/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt @@ -138,7 +138,7 @@ class DiktatSaveSmokeTest : DiktatSmokeTestBase() { private const val BASE_DIRECTORY = "src/test/resources/test/smoke" private const val BUILD_DIRECTORY = "target" private const val FAT_JAR_GLOB = "diktat-*.jar" - private const val KTLINT_VERSION = "0.47.1" + private const val KTLINT_VERSION = "0.46.1" private const val SAVE_VERSION: String = "0.3.4" private val baseDirectoryPath = Path(BASE_DIRECTORY).absolute() diff --git a/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt b/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt index fbeb8c057e..cf31ebe8cd 100644 --- a/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt +++ b/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt @@ -238,8 +238,8 @@ abstract class DiktatSmokeTestBase { /* * This 2nd `MISSING_KDOC_ON_FUNCTION` is a duplicate caused by * https://github.com/saveourtool/diktat/issues/1538. + * LintError(6, 5, "$DIKTAT_RULE_SET_ID:${KdocMethods.NAME_ID}", "${MISSING_KDOC_ON_FUNCTION.warnText()} foo", false), */ - LintError(6, 5, "$DIKTAT_RULE_SET_ID:${KdocMethods.NAME_ID}", "${MISSING_KDOC_ON_FUNCTION.warnText()} foo", false), LintError(9, 3, "$DIKTAT_RULE_SET_ID:${EmptyBlock.NAME_ID}", EMPTY_BLOCK_STRUCTURE_ERROR.warnText() + " empty blocks are forbidden unless it is function with override keyword", false), LintError(12, 10, "$DIKTAT_RULE_SET_ID:${KdocFormatting.NAME_ID}", "${KDOC_NO_EMPTY_TAGS.warnText()} @return", false), diff --git a/pom.xml b/pom.xml index e3d68692e1..54391aa8ae 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ true official 1.4.1 - 0.47.1 + 0.46.1 5.9.1 1.9.1 1.1.0