-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/DisabledRulesTest.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,68 @@ | ||
package com.pinterest.ktlint.core | ||
|
||
import com.pinterest.ktlint.core.ast.ElementType | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.jetbrains.kotlin.com.intellij.lang.ASTNode | ||
import org.junit.Test | ||
import java.util.ArrayList | ||
|
||
class DisabledRulesTest { | ||
|
||
@Test | ||
fun testDisabledRule() { | ||
class NoVarRule : Rule("no-var") { | ||
|
||
override fun visit( | ||
node: ASTNode, | ||
autoCorrect: Boolean, | ||
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit | ||
) { | ||
if (node.elementType == ElementType.VAR_KEYWORD) { | ||
emit(node.startOffset, "Unexpected var, use val instead", false) | ||
} | ||
} | ||
} | ||
|
||
assertThat( | ||
ArrayList<LintError>().apply { | ||
KtLint.lint( | ||
KtLint.Params( | ||
text = "var foo", | ||
ruleSets = listOf(RuleSet("standard", NoVarRule())), | ||
cb = { e, _ -> add(e) } | ||
) | ||
) | ||
} | ||
).isEqualTo( | ||
listOf( | ||
LintError(1, 1, "no-var", "Unexpected var, use val instead") | ||
) | ||
) | ||
|
||
assertThat( | ||
ArrayList<LintError>().apply { | ||
KtLint.lint( | ||
KtLint.Params( | ||
text = "var foo", | ||
ruleSets = listOf(RuleSet("standard", NoVarRule())), | ||
cb = { e, _ -> add(e) }, | ||
userData = mapOf(("disabled_rules" to "no-var")) | ||
) | ||
) | ||
} | ||
).isEmpty() | ||
|
||
assertThat( | ||
ArrayList<LintError>().apply { | ||
KtLint.lint( | ||
KtLint.Params( | ||
text = "var foo", | ||
ruleSets = listOf(RuleSet("experimental", NoVarRule())), | ||
cb = { e, _ -> add(e) }, | ||
userData = mapOf(("disabled_rules" to "experimental:no-var")) | ||
) | ||
) | ||
} | ||
).isEmpty() | ||
} | ||
} |