From 22b656b61f10830a1502d452aebb5c6afc522cf1 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 Edit Main.kt in the kotlin-rulesets-using projects according to inline comment, then run ./gradlew samples:kotlin-rulesets-using:build --- samples/kotlin-js/gradle.properties | 1 + samples/kotlin-mpp/gradle.properties | 1 + samples/kotlin-rulesets-creating/build.gradle.kts | 2 +- .../ktlint/sample/kotlin/CustomRuleSetProvider.kt | 11 +++++++---- .../gradle/ktlint/sample/kotlin/NoVarRule.kt | 10 +++++++--- ...est.ktlint.cli.ruleset.core.api.RuleSetProviderV3} | 0 samples/kotlin-rulesets-using/build.gradle.kts | 1 + settings.gradle.kts | 4 ++-- 8 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 samples/kotlin-js/gradle.properties create mode 100644 samples/kotlin-mpp/gradle.properties rename samples/kotlin-rulesets-creating/src/main/resources/META-INF/services/{com.pinterest.ktlint.core.RuleSetProvider => com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3} (100%) diff --git a/samples/kotlin-js/gradle.properties b/samples/kotlin-js/gradle.properties new file mode 100644 index 00000000..f670486d --- /dev/null +++ b/samples/kotlin-js/gradle.properties @@ -0,0 +1 @@ +kotlin.js.compiler=ir diff --git a/samples/kotlin-mpp/gradle.properties b/samples/kotlin-mpp/gradle.properties new file mode 100644 index 00000000..f670486d --- /dev/null +++ b/samples/kotlin-mpp/gradle.properties @@ -0,0 +1 @@ +kotlin.js.compiler=ir diff --git a/samples/kotlin-rulesets-creating/build.gradle.kts b/samples/kotlin-rulesets-creating/build.gradle.kts index 666ecc17..6ca7c02a 100644 --- a/samples/kotlin-rulesets-creating/build.gradle.kts +++ b/samples/kotlin-rulesets-creating/build.gradle.kts @@ -6,5 +6,5 @@ plugins { 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..945e3c8e 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,12 @@ 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 { +class CustomRuleSetProvider : RuleSetProviderV3(RuleSetId("custom")) { - override fun get(): RuleSet = RuleSet("custom", NoVarRule()) + 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..6f373bec 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("test:novar"), + About() +) { + override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit diff --git a/samples/kotlin-rulesets-creating/src/main/resources/META-INF/services/com.pinterest.ktlint.core.RuleSetProvider b/samples/kotlin-rulesets-creating/src/main/resources/META-INF/services/com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3 similarity index 100% rename from samples/kotlin-rulesets-creating/src/main/resources/META-INF/services/com.pinterest.ktlint.core.RuleSetProvider rename to samples/kotlin-rulesets-creating/src/main/resources/META-INF/services/com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3 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 { diff --git a/settings.gradle.kts b/settings.gradle.kts index 7629df4a..b7525591 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,8 +4,8 @@ pluginManagement { includeBuild("./plugin") plugins { - id("org.jetbrains.kotlin.jvm") version "1.5.31" - id("org.jetbrains.kotlin.js") version "1.5.31" + id("org.jetbrains.kotlin.jvm") version "1.8.22" + id("org.jetbrains.kotlin.js") version "1.8.22" } repositories {