Skip to content

Commit ff1ec1e

Browse files
authored
Downgrade ktlint to 0.46.1 (#1565)
1 parent 341ef78 commit ff1ec1e

File tree

12 files changed

+36
-50
lines changed

12 files changed

+36
-50
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Main features of diktat are the following:
5353
```shell
5454
# another option is "brew install ktlint"
5555

56-
curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.47.1/ktlint && chmod a+x ktlint
56+
curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.46.1/ktlint && chmod a+x ktlint
5757
```
5858

5959
1. Load diKTat manually: [here](https://github.com/saveourtool/diKTat/releases/download/v1.2.4/diktat-1.2.4.jar)

diktat-gradle-plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repositories {
2828

2929
// default value is needed for correct gradle loading in IDEA; actual value from maven is used during build
3030
// To debug gradle plugin, please set `diktatVersion` manually to the current maven project version.
31-
val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.47.1") as String
31+
val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.46.1") as String
3232
val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "1.2.3"
3333
val junitVersion = project.properties.getOrDefault("junitVersion", "5.8.1") as String
3434
val jacocoVersion = project.properties.getOrDefault("jacocoVersion", "0.8.7") as String

diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import com.pinterest.ktlint.core.LintError
1111
import com.pinterest.ktlint.core.Reporter
1212
import com.pinterest.ktlint.core.RuleExecutionException
1313
import com.pinterest.ktlint.core.RuleSet
14-
import com.pinterest.ktlint.core.api.Baseline
15-
import com.pinterest.ktlint.core.api.Baseline.Status.VALID
16-
import com.pinterest.ktlint.core.api.containsLintError
17-
import com.pinterest.ktlint.core.api.loadBaseline
14+
import com.pinterest.ktlint.core.internal.CurrentBaseline
15+
import com.pinterest.ktlint.core.internal.containsLintError
16+
import com.pinterest.ktlint.core.internal.loadBaseline
1817
import com.pinterest.ktlint.reporter.baseline.BaselineReporter
1918
import com.pinterest.ktlint.reporter.html.HtmlReporter
2019
import com.pinterest.ktlint.reporter.json.JsonReporter
@@ -121,15 +120,15 @@ abstract class DiktatBaseMojo : AbstractMojo() {
121120
listOf(DiktatRuleSetProvider(configFile).get())
122121
}
123122
val baselineResults = baseline?.let { loadBaseline(it.absolutePath) }
124-
?: Baseline(status = VALID)
123+
?: CurrentBaseline(emptyMap(), false)
125124
reporterImpl = resolveReporter(baselineResults)
126125
reporterImpl.beforeAll()
127126
val lintErrors: MutableList<LintError> = mutableListOf()
128127

129128
inputs
130129
.map(::File)
131130
.forEach {
132-
checkDirectory(it, lintErrors, baselineResults.lintErrorsPerFile, ruleSets)
131+
checkDirectory(it, lintErrors, baselineResults.baselineRules ?: emptyMap(), ruleSets)
133132
}
134133

135134
reporterImpl.afterAll()
@@ -138,7 +137,7 @@ abstract class DiktatBaseMojo : AbstractMojo() {
138137
}
139138
}
140139

141-
private fun resolveReporter(baselineResults: Baseline): Reporter {
140+
private fun resolveReporter(baselineResults: CurrentBaseline): Reporter {
142141
val output = if (this.output.isBlank()) {
143142
if (this.githubActions) {
144143
// 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() {
166165
}
167166
}
168167

169-
return if (baselineResults.status != VALID) {
168+
return if (baselineResults.baselineGenerationNeeded) {
170169
val baselineReporter = BaselineReporter(PrintStream(FileOutputStream(baseline, true)))
171170
return Reporter.from(actualReporter, baselineReporter)
172171
} else {

diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ abstract class DiktatRule(
3434

3535
/**
3636
* The **file-specific** error emitter, initialized in
37-
* [beforeVisitChildNodes] and used in [logic] implementations.
37+
* [visit] and used in [logic] implementations.
3838
*
3939
* Since the file is indirectly a part of the state of a `Rule`, the same
4040
* `Rule` instance should **never be re-used** to check more than a single
4141
* file, or confusing effects (incl. race conditions) will occur.
4242
* See the documentation of the [Rule] class for more details.
4343
*
4444
* @see Rule
45-
* @see beforeVisitChildNodes
45+
* @see visit
4646
* @see logic
4747
*/
4848
lateinit var emitWarn: EmitType
4949

5050
@Suppress("TooGenericExceptionThrown")
51-
final override fun beforeVisitChildNodes(
51+
final override fun visit(
5252
node: ASTNode,
5353
autoCorrect: Boolean,
5454
emit: EmitType

diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/OrderedRuleSet.kt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.cqfn.diktat.common.config.rules.qualifiedWithRuleSetId
88
import org.cqfn.diktat.ruleset.constants.EmitType
99
import com.pinterest.ktlint.core.Rule
1010
import com.pinterest.ktlint.core.RuleSet
11-
import com.pinterest.ktlint.core.api.EditorConfigProperties
1211
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
1312

1413
/**
@@ -81,16 +80,6 @@ class OrderedRuleSet(id: String, vararg rules: Rule) : RuleSet(id, rules = adjus
8180
val rule: Rule,
8281
prevRule: Rule
8382
) : Rule(rule.id.qualifiedWithRuleSetId(ruleSetId), adjustVisitorModifiers(ruleSetId, rule, prevRule)) {
84-
override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) =
85-
rule.beforeFirstNode(editorConfigProperties)
86-
87-
override fun beforeVisitChildNodes(
88-
node: ASTNode,
89-
autoCorrect: Boolean,
90-
emit: EmitType,
91-
) =
92-
rule.beforeVisitChildNodes(node, autoCorrect, emit)
93-
9483
@Deprecated(
9584
"Marked for deletion in ktlint 0.48.0",
9685
replaceWith = ReplaceWith("beforeVisitChildNodes(node, autoCorrect, emit)"),
@@ -101,16 +90,6 @@ class OrderedRuleSet(id: String, vararg rules: Rule) : RuleSet(id, rules = adjus
10190
emit: EmitType,
10291
) =
10392
rule.visit(node, autoCorrect, emit)
104-
105-
override fun afterVisitChildNodes(
106-
node: ASTNode,
107-
autoCorrect: Boolean,
108-
emit: EmitType,
109-
) =
110-
rule.afterVisitChildNodes(node, autoCorrect, emit)
111-
112-
override fun afterLastNode() =
113-
rule.afterLastNode()
11493
}
11594
}
11695
}

diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/RunInScript.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class RunInScript(private val configRules: List<RulesConfig>) : Rule(NAME_ID.qua
2727
private var isFixMode: Boolean = false
2828
private lateinit var emitWarn: EmitType
2929

30-
override fun beforeVisitChildNodes(
30+
override fun visit(
3131
node: ASTNode,
3232
autoCorrect: Boolean,
3333
emit: EmitType

diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/rules/OrderedRuleSetTest.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,19 @@ class OrderedRuleSetTest {
134134
* |
135135
* V
136136
* C(File) -> C(Node) -> C(Leaf)
137+
*
138+
* val expectedRuleInvocationOrder = rules.asSequence()
139+
* .map(Rule::id)
140+
* .flatMap { ruleId ->
141+
* generateSequence { ruleId }.take(astNodeCount)
142+
* }
143+
* .toList()
137144
*/
138-
val expectedRuleInvocationOrder = rules.asSequence()
139-
.map(Rule::id)
140-
.flatMap { ruleId ->
141-
generateSequence { ruleId }.take(astNodeCount)
142-
}
145+
val expectedRuleInvocationOrder = generateSequence {
146+
rules.map(Rule::id)
147+
}
148+
.take(astNodeCount)
149+
.flatten()
143150
.toList()
144151

145152
assertThat(actualRuleInvocationOrder)
@@ -152,7 +159,7 @@ class OrderedRuleSetTest {
152159
visitorModifiers: Set<Rule.VisitorModifier> = emptySet(),
153160
onVisit: (Rule) -> Unit = { }
154161
): Rule = object : Rule(id.qualifiedWithRuleSetId(), visitorModifiers) {
155-
override fun beforeVisitChildNodes(
162+
override fun visit(
156163
node: ASTNode,
157164
autoCorrect: Boolean,
158165
emit: EmitType

diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,9 @@ private class PrettyPrintingVisitor(private val elementType: IElementType,
792792
private val maxLevel: Int,
793793
private val expected: String
794794
) : Rule("print-ast") {
795-
override fun beforeVisitChildNodes(node: ASTNode,
796-
autoCorrect: Boolean,
797-
emit: EmitType
795+
override fun visit(node: ASTNode,
796+
autoCorrect: Boolean,
797+
emit: EmitType
798798
) {
799799
if (node.elementType == elementType) {
800800
Assertions.assertEquals(

diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ internal fun applyToCode(code: String,
5151
text = code,
5252
ruleSets = listOf(
5353
RuleSet("test", object : Rule("astnode-utils-test") {
54-
override fun beforeVisitChildNodes(node: ASTNode,
55-
autoCorrect: Boolean,
56-
emit: EmitType
54+
override fun visit(
55+
node: ASTNode,
56+
autoCorrect: Boolean,
57+
emit: EmitType
5758
) {
5859
applyToNode(node, counter)
5960
}

diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class DiktatSaveSmokeTest : DiktatSmokeTestBase() {
138138
private const val BASE_DIRECTORY = "src/test/resources/test/smoke"
139139
private const val BUILD_DIRECTORY = "target"
140140
private const val FAT_JAR_GLOB = "diktat-*.jar"
141-
private const val KTLINT_VERSION = "0.47.1"
141+
private const val KTLINT_VERSION = "0.46.1"
142142
private const val SAVE_VERSION: String = "0.3.4"
143143
private val baseDirectoryPath = Path(BASE_DIRECTORY).absolute()
144144

0 commit comments

Comments
 (0)