-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What's done: - Deprecated API usages removed (except for `DiktatBaseMojo`). - @Suppress("Deprecation") annotations removed (except for `DiktatBaseMojo`). - A part of #1543.
- Loading branch information
1 parent
b8f4350
commit 113fbe5
Showing
30 changed files
with
412 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.cqfn.diktat.ruleset.rules | ||
|
||
import com.pinterest.ktlint.core.RuleProvider | ||
import com.pinterest.ktlint.core.RuleSetProviderV2 | ||
|
||
/** | ||
* A group of [RuleProvider]'s discoverable through [RuleSetProviderV2]. | ||
*/ | ||
interface DiktatRuleSet { | ||
/** | ||
* The rule providers. | ||
*/ | ||
val ruleProviders: Set<RuleProvider> | ||
} |
40 changes: 40 additions & 0 deletions
40
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.cqfn.diktat.ruleset.rules | ||
|
||
import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF | ||
import com.pinterest.ktlint.core.KtLint | ||
import com.pinterest.ktlint.core.Rule | ||
import kotlin.Function0 | ||
|
||
/** | ||
* _KtLint_-agnostic factory which creates a [DiktatRuleSet]. | ||
*/ | ||
fun interface DiktatRuleSetFactory : Function0<DiktatRuleSet> { | ||
/** | ||
* This method is going to be called once for each file (which means if any | ||
* of the rules have state or are not thread-safe - a new [DiktatRuleSet] must | ||
* be created). | ||
* | ||
* For each invocation of [KtLint.lint] and [KtLint.format] the [DiktatRuleSet] | ||
* is retrieved. | ||
* This results in new instances of each [Rule] for each file being | ||
* processed. | ||
* As of that a [Rule] does not need to be thread-safe. | ||
* | ||
* However, [KtLint.format] requires the [Rule] to be executed twice on a | ||
* file in case at least one violation has been autocorrected. | ||
* As the same [Rule] instance is reused for the second execution of the | ||
* [Rule], the state of the [Rule] is shared. | ||
* As of this [Rule] have to clear their internal state. | ||
*/ | ||
override fun invoke(): DiktatRuleSet | ||
|
||
companion object { | ||
/** | ||
* @param diktatConfigFile the configuration file where all configurations for | ||
* inspections and rules are stored. | ||
* @return a new instance of [DiktatRuleSetFactory]. | ||
*/ | ||
operator fun invoke(diktatConfigFile: String = DIKTAT_ANALYSIS_CONF): DiktatRuleSetFactory = | ||
DiktatRuleSetProvider(diktatConfigFile) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProviderV2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.cqfn.diktat.ruleset.rules | ||
|
||
import org.cqfn.diktat.common.config.rules.DIKTAT_RULE_SET_ID | ||
import com.pinterest.ktlint.core.RuleProvider | ||
import com.pinterest.ktlint.core.RuleSetProviderV2 | ||
|
||
/** | ||
* [RuleSetProviderV2] that provides diKTat ruleset. | ||
* | ||
* The no-argument constructor is used by the Java SPI interface; that's why | ||
* it's explicitly annotated with [JvmOverloads]. | ||
*/ | ||
@Suppress("serial") | ||
class DiktatRuleSetProviderV2 | ||
@JvmOverloads | ||
constructor(private val factory: DiktatRuleSetFactory = DiktatRuleSetFactory()) : RuleSetProviderV2( | ||
id = DIKTAT_RULE_SET_ID, | ||
about = About( | ||
maintainer = "Diktat", | ||
description = "Strict coding standard for Kotlin and a custom set of rules for detecting code smells, code style issues, and bugs", | ||
license = "https://github.com/saveourtool/diktat/blob/master/LICENSE", | ||
repositoryUrl = "https://github.com/saveourtool/diktat", | ||
issueTrackerUrl = "https://github.com/saveourtool/diktat/issues", | ||
), | ||
) { | ||
/** | ||
* @param diktatConfigFile the configuration file where all configurations for | ||
* inspections and rules are stored. | ||
*/ | ||
constructor(diktatConfigFile: String) : this(DiktatRuleSetFactory(diktatConfigFile)) | ||
|
||
override fun getRuleProviders(): Set<RuleProvider> = | ||
factory().ruleProviders | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.