Skip to content

Commit

Permalink
load all RuleSetProviderV3 from the classpath in ktlint 49+
Browse files Browse the repository at this point in the history
fixes #697
  • Loading branch information
wakingrufus committed Aug 3, 2023
1 parent 840e72e commit 0d983b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package org.jlleitschuh.gradle.ktlint.worker

import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3
import com.pinterest.ktlint.rule.engine.api.Code
import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine
import com.pinterest.ktlint.rule.engine.api.LintError
import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider
import com.pinterest.ktlint.rule.engine.core.api.RuleProvider
import java.io.File
import java.util.ServiceLoader

class KtLintInvocation49(
private val engine: KtLintRuleEngine
) : KtLintInvocation {
companion object Factory : KtLintInvocationFactory {
fun initialize(): KtLintInvocation {
val engine = KtLintRuleEngine(
ruleProviders = StandardRuleSetProvider().getRuleProviders()
ruleProviders = loadRuleSetsFromClasspathWithRuleSetProviderV3()
)
return KtLintInvocation49(engine)
}

private fun loadRuleSetsFromClasspathWithRuleSetProviderV3(): Set<RuleProvider> {
return ServiceLoader
.load(RuleSetProviderV3::class.java)
.flatMap { it.getRuleProviders() }
.toSet()
}
}

override fun invokeLint(file: File): LintErrorResult {
Expand All @@ -38,6 +47,8 @@ class KtLintInvocation49(
override fun trimMemory() {
engine.trimMemory()
}
// StandardRuleSetProvider().getRuleProviders()

}

internal fun LintError.toSerializable(): SerializableLintError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package org.jlleitschuh.gradle.ktlint.worker

import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3
import com.pinterest.ktlint.rule.engine.api.Code
import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine
import com.pinterest.ktlint.rule.engine.api.LintError
import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider
import com.pinterest.ktlint.rule.engine.core.api.RuleProvider
import java.io.File
import java.util.ServiceLoader

class KtLintInvocation50(
private val engine: KtLintRuleEngine
) : KtLintInvocation {
companion object Factory : KtLintInvocationFactory {
fun initialize(): KtLintInvocation {
val engine = KtLintRuleEngine(
ruleProviders = StandardRuleSetProvider().getRuleProviders()
ruleProviders = loadRuleSetsFromClasspathWithRuleSetProviderV3()
)
return KtLintInvocation50(engine)
}

private fun loadRuleSetsFromClasspathWithRuleSetProviderV3(): Set<RuleProvider> {
return ServiceLoader
.load(RuleSetProviderV3::class.java)
.flatMap { it.getRuleProviders() }
.toSet()
}
}

override fun invokeLint(file: File): LintErrorResult {
Expand Down

0 comments on commit 0d983b6

Please sign in to comment.