Skip to content

Commit

Permalink
test custom rule loading in ktlin 0.50.0
Browse files Browse the repository at this point in the history
Edit Main.kt in the kotlin-rulesets-using projects according to inline comment, then
run ./gradlew samples:kotlin-rulesets-using:build
  • Loading branch information
wakingrufus committed Aug 7, 2023
1 parent a145c65 commit 22b656b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions samples/kotlin-js/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.js.compiler=ir
1 change: 1 addition & 0 deletions samples/kotlin-mpp/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.js.compiler=ir
2 changes: 1 addition & 1 deletion samples/kotlin-rulesets-creating/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
@@ -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<RuleProvider> {
return setOf(RuleProvider { NoVarRule() })
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions samples/kotlin-rulesets-using/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
}

ktlint {
version.set("0.50.0")
verbose.set(true)
outputToConsole.set(true)
reporters {
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 22b656b

Please sign in to comment.