-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for disabled_rules property in .editorconfig for globally disabling rules #503
Conversation
@@ -8,8 +8,8 @@ import java.util.Properties | |||
import java.util.concurrent.CompletableFuture | |||
import java.util.concurrent.ConcurrentHashMap | |||
|
|||
class EditorConfig private constructor ( | |||
val parent: EditorConfig?, | |||
class EditorConfigInternal private constructor ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally open to better names for this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's wrong with just EditorConfig ;) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturbosch there's already an EditorConfig
interface inside of ktlint-core
so if you want to use one or the other you need a lot of ugly namespacing. :) We can also rename that one, but I couldn't think of a name for that one!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, didn't know that.
I like to use a Default
for my implementations of an interface.
So maybe consider DefaultEditorConfig
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturbosch but that's the thing - the internal one is actually not an implementation of the EditorConfig
interface ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha correct! I don't have context about why it was implemented this way. I thought about naming the internal one ParsedEditorConfig
or EditorConfigParser
or something...
* @throws ParseException if text is not a valid Kotlin code | ||
* @throws RuleExecutionException in case of internal failure caused by a bug in rule implementation | ||
*/ | ||
fun lint(text: String, ruleSets: Iterable<RuleSet>, cb: (e: LintError) -> Unit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed all the overrides and just pass in Params
now.
.forEach { e -> params.cb(e, false) } | ||
} | ||
|
||
private fun userDataResolver(editorConfigPath: String?, debug: Boolean): (String?) -> Map<String, String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from Main.kt
@jaredsburrows @Tapchicoma @jeremymailen @JLLeitschuh @bethcutler Thoughts on this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, looks great to me! A couple questions to make sure I understand how rule disabling is used, but structurally seems like it should work well with plugins that use ktlint.
text = "var foo", | ||
ruleSets = listOf(RuleSet("standard", NoVarRule())), | ||
cb = { e, _ -> add(e) }, | ||
userData = mapOf(("disabled_rules" to "no-var")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the ability to pass in the disabled_rules as a regular userData param or via editor config 👍
# multiline-if-else - disabled until auto-correct is working properly | ||
# (e.g. try formatting "if (true)\n return { _ ->\n _\n}") | ||
# no-it-in-multiline-lambda - disabled until it's clear what to do in case of `import _.it` | ||
disabled_rules=annotation,multiline-if-else,no-it-in-multiline-lambda |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a rule is not prefixed with anamespace:
is it assumed to be in the standard set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, see this
ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt
Outdated
Show resolved
Hide resolved
… disabling rules Fixes pinterest#208 * Takes in a comma-separated list of rule ids, with namespaces (e.g. `experimental:indent`) * Re-enabled `NoWildcardImports`, `PackageNameRule` * Un-commented `AnnotationRule`, `MultiLineIfElseRule`, and `NoItParamInMultilineLambdaRule`, and moved disabling into default `.editorconfig` * Also cleaned up params passed to lint and format
Does it require some docs in README? |
Yes; I like to wait to update the README until we're ready to release so it doesn't look like features are available that have not yet released. |
Do we know when is planned the next release of ktlin to include this new feature of allowing to disable rules? |
@elenigen I am targeting the end of this week. |
… disabling rules (pinterest#503) * Add support for disabled_rules property to .editorconfig for globally disabling rules Fixes pinterest#208 * Takes in a comma-separated list of rule ids, with namespaces (e.g. `experimental:indent`) * Re-enabled `NoWildcardImports`, `PackageNameRule` * Un-commented `AnnotationRule`, `MultiLineIfElseRule`, and `NoItParamInMultilineLambdaRule`, and moved disabling into default `.editorconfig` * Also cleaned up params passed to lint and format
Fixes #208
experimental:indent
)NoWildcardImports
,PackageNameRule
AnnotationRule
,MultiLineIfElseRule
, andNoItParamInMultilineLambdaRule
, and moved disabling into default.editorconfig
.editorconfig
parsing intoktlint-core
so that plugins that don't invoke ktlint on the command line can take advantage of rule disabling