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 and #695
  • Loading branch information
wakingrufus committed Aug 3, 2023
1 parent 840e72e commit a145c65
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

- Fix custom rulesets not loading from classpath [#698](https://github.com/JLLeitschuh/ktlint-gradle/pull/698)
- update latest version text file manually [#688](https://github.com/JLLeitschuh/ktlint-gradle/pull/688)

## [11.5.0] - 2023-07-03
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 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 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 a145c65

Please sign in to comment.