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
run ./gradlew samples:kotlin-rulesets-using:build
  • Loading branch information
wakingrufus committed Aug 7, 2023
1 parent a145c65 commit 6506a5d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions samples/kotlin-rulesets-creating/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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<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("no-var"),
About()
) {
override fun afterVisitChildNodes(
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

0 comments on commit 6506a5d

Please sign in to comment.