diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt index f64ce31322..dc652b5fc8 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt @@ -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() diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/Main.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/Main.kt index dad62959bb..af941f39e3 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/Main.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/Main.kt @@ -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"], @@ -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 { if (debug) { val fileLocation = if (fileName != KtLint.STDIN_FILE) File(fileName).location(relative) else fileName