From 6506a5d8225ba98e155c9e0b314dbe8bb62aa6ac Mon Sep 17 00:00:00 2001 From: wakingrufus Date: Mon, 7 Aug 2023 10:45:43 -0500 Subject: [PATCH] test custom rule loading in ktlin 0.50.0 run ./gradlew samples:kotlin-rulesets-using:build --- samples/kotlin-rulesets-creating/build.gradle.kts | 4 ++-- .../ktlint/sample/kotlin/CustomRuleSetProvider.kt | 12 ++++++++---- .../gradle/ktlint/sample/kotlin/NoVarRule.kt | 10 +++++++--- samples/kotlin-rulesets-using/build.gradle.kts | 1 + 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/samples/kotlin-rulesets-creating/build.gradle.kts b/samples/kotlin-rulesets-creating/build.gradle.kts index 666ecc17..ef14fc93 100644 --- a/samples/kotlin-rulesets-creating/build.gradle.kts +++ b/samples/kotlin-rulesets-creating/build.gradle.kts @@ -1,10 +1,10 @@ plugins { id("org.jlleitschuh.gradle.ktlint") - kotlin("jvm") + kotlin("jvm") version ("1.8.22") } dependencies { compileOnly(pluginLibs.kotlin.reflect) compileOnly(pluginLibs.kotlin.script.runtime) - compileOnly(pluginLibs.ktlint.core) + compileOnly("com.pinterest.ktlint:ktlint-cli-ruleset-core:0.50.0") } diff --git a/samples/kotlin-rulesets-creating/src/main/kotlin/org/jlleitschuh/gradle/ktlint/sample/kotlin/CustomRuleSetProvider.kt b/samples/kotlin-rulesets-creating/src/main/kotlin/org/jlleitschuh/gradle/ktlint/sample/kotlin/CustomRuleSetProvider.kt index f30fb72f..b2768ffd 100644 --- a/samples/kotlin-rulesets-creating/src/main/kotlin/org/jlleitschuh/gradle/ktlint/sample/kotlin/CustomRuleSetProvider.kt +++ b/samples/kotlin-rulesets-creating/src/main/kotlin/org/jlleitschuh/gradle/ktlint/sample/kotlin/CustomRuleSetProvider.kt @@ -1,9 +1,13 @@ package org.jlleitschuh.gradle.ktlint.sample.kotlin -import com.pinterest.ktlint.core.RuleSet -import com.pinterest.ktlint.core.RuleSetProvider +import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3 +import com.pinterest.ktlint.rule.engine.core.api.RuleProvider +import com.pinterest.ktlint.rule.engine.core.api.RuleSetId -class CustomRuleSetProvider : RuleSetProvider { - override fun get(): RuleSet = RuleSet("custom", NoVarRule()) +class CustomRuleSetProvider : RuleSetProviderV3(RuleSetId("custom")) { + + override fun getRuleProviders(): Set { + return setOf(RuleProvider{NoVarRule()}) + } } diff --git a/samples/kotlin-rulesets-creating/src/main/kotlin/org/jlleitschuh/gradle/ktlint/sample/kotlin/NoVarRule.kt b/samples/kotlin-rulesets-creating/src/main/kotlin/org/jlleitschuh/gradle/ktlint/sample/kotlin/NoVarRule.kt index b5ac46c7..c0bc7fd6 100644 --- a/samples/kotlin-rulesets-creating/src/main/kotlin/org/jlleitschuh/gradle/ktlint/sample/kotlin/NoVarRule.kt +++ b/samples/kotlin-rulesets-creating/src/main/kotlin/org/jlleitschuh/gradle/ktlint/sample/kotlin/NoVarRule.kt @@ -1,13 +1,17 @@ package org.jlleitschuh.gradle.ktlint.sample.kotlin -import com.pinterest.ktlint.core.Rule +import com.pinterest.ktlint.rule.engine.core.api.Rule +import com.pinterest.ktlint.rule.engine.core.api.RuleId import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.com.intellij.psi.util.PsiTreeUtil.getNonStrictParentOfType import org.jetbrains.kotlin.psi.KtStringTemplateEntry -class NoVarRule : Rule("no-var") { - override fun visit( +class NoVarRule : Rule( + RuleId("no-var"), + About() +) { + override fun afterVisitChildNodes( node: ASTNode, autoCorrect: Boolean, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit diff --git a/samples/kotlin-rulesets-using/build.gradle.kts b/samples/kotlin-rulesets-using/build.gradle.kts index 0717ac9a..0353a48e 100644 --- a/samples/kotlin-rulesets-using/build.gradle.kts +++ b/samples/kotlin-rulesets-using/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { } ktlint { + version.set("0.50.0") verbose.set(true) outputToConsole.set(true) reporters {