-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Test adding custom rule sets Rule sets can be configured by adding them to the `ktlint` dependency configuration * Don't fail test project build on lint * Fix test
- Loading branch information
1 parent
c4ae1fd
commit af7ea9f
Showing
11 changed files
with
71 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
plugins { | ||
kotlin("jvm") version "2.1.0" | ||
id("org.jmailen.kotlinter") | ||
kotlin("jvm") version "2.1.0" apply false | ||
} |
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,7 @@ | ||
plugins { | ||
kotlin("jvm") | ||
} | ||
|
||
dependencies { | ||
compileOnly("com.pinterest.ktlint:ktlint-cli-ruleset-core:1.5.0") | ||
} |
23 changes: 23 additions & 0 deletions
23
test-project/rules/src/main/kotlin/org/jmailen/ktlint/rule/NoVarRule.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,23 @@ | ||
package org.jmailen.ktlint.rule | ||
|
||
import com.pinterest.ktlint.rule.engine.core.api.* | ||
import org.jetbrains.kotlin.com.intellij.lang.ASTNode | ||
|
||
class NoVarRule : | ||
Rule( | ||
ruleId = RuleId("$CUSTOM_RULE_SET_ID:no-var"), | ||
about = About( | ||
maintainer = "jmailen", | ||
repositoryUrl = "https://gtihub.com/jeremymailen/kotlinter-gradle" | ||
) | ||
), | ||
RuleAutocorrectApproveHandler { | ||
override fun beforeVisitChildNodes( | ||
node: ASTNode, | ||
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision | ||
) { | ||
if (node.elementType == ElementType.VAR_KEYWORD) { | ||
emit(node.startOffset, "Use val instead of var", false) | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test-project/rules/src/main/kotlin/org/jmailen/ktlint/rule/RuleSetProvider.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,16 @@ | ||
package org.jmailen.ktlint.rule | ||
|
||
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 | ||
|
||
internal val CUSTOM_RULE_SET_ID = "kotlinter-test-rules" | ||
|
||
class CustomRuleSetProvider : RuleSetProviderV3(RuleSetId(CUSTOM_RULE_SET_ID)) { | ||
override fun getRuleProviders(): Set<RuleProvider> = | ||
setOf( | ||
RuleProvider { | ||
NoVarRule() | ||
}, | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
...n/resources/META-INF/services/com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3
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 @@ | ||
org.jmailen.ktlint.rule.CustomRuleSetProvider |
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,13 @@ | ||
plugins { | ||
kotlin("jvm") | ||
id("org.jmailen.kotlinter") | ||
} | ||
|
||
dependencies { | ||
ktlint(project(":rules")) | ||
} | ||
|
||
kotlinter { | ||
reporters = arrayOf("plain", "checkstyle") | ||
ignoreLintFailures = true | ||
} |
5 changes: 5 additions & 0 deletions
5
test-project/service/src/main/kotlin/org/jmailen/gradle/kotlinter/sample/CustomNoVar.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,5 @@ | ||
package org.jmailen.gradle.kotlinter.sample | ||
|
||
class CustomNoVar { | ||
var test: String = "test" | ||
} |
File renamed without changes.
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
4 changes: 0 additions & 4 deletions
4
test-project/src/main/kotlin/org/jmailen/gradle/kotlinter/sample/EmptyClassBodyClass.kt
This file was deleted.
Oops, something went wrong.