Skip to content

Commit

Permalink
Add --disabled_rules flag to CLI (#534)
Browse files Browse the repository at this point in the history
Fixes #533

Note: command line flag will override `.editorconfig`
  • Loading branch information
shashachu authored Jul 17, 2019
1 parent b548fef commit 1f87128
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ object KtLint {
throw ParseException(line, col, errorElement.errorDescription)
}
val rootNode = psiFile.node
val mergedUserData = params.userData + userDataResolver(params.editorConfigPath, params.debug)(params.fileName)
// Passed-in userData overrides .editorconfig
val mergedUserData = userDataResolver(params.editorConfigPath, params.debug)(params.fileName) + params.userData
injectUserData(rootNode, mergedUserData)
val isSuppressed = calculateSuppressedRegions(rootNode)
val errors = mutableListOf<LintError>()
Expand Down
9 changes: 8 additions & 1 deletion ktlint/src/main/kotlin/com/pinterest/ktlint/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ class KtlintCommandLine {
)
var debug: Boolean = false

@Option(
names = ["--disabled_rules"],
description = ["Comma-separated list of rules to globally disable"]
)
var disabledRules: String = ""

// todo: this should have been a command, not a flag (consider changing in 1.0.0)
@Option(
names = ["--format", "-F"],
Expand Down Expand Up @@ -275,7 +281,8 @@ class KtlintCommandLine {
val tripped = AtomicBoolean()
val reporter = loadReporter(dependencyResolver) { tripped.get() }
data class LintErrorWithCorrectionInfo(val err: LintError, val corrected: Boolean)
val userData = mapOf("android" to android.toString())
val userData = mapOf("android" to android.toString(), "disabled_rules" to disabledRules)

fun process(fileName: String, fileContent: String): List<LintErrorWithCorrectionInfo> {
if (debug) {
val fileLocation = if (fileName != KtLint.STDIN_FILE) File(fileName).location(relative) else fileName
Expand Down

0 comments on commit 1f87128

Please sign in to comment.