You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support disabling/enabling rules from source code comments #4
@jpsim do we want to make this purely additive or subtractive (additive would be having no rules on by default, subtractive would be having all rules on by default)? I don't think we should support both - that would complicate things unnecessarily.
How do you feel about using introspection to map YAML properties to rules? Another option would be to add a property to each Rule for a YAML identifier.
I would vote for an approach based on a context-stack akin to clang analyzer:
Instead of simple serial switches one would be able to have elaborate nested configurations.
And instead of binary enable_rule/disable_rule switches one would be offered to choose from the same options that clang offers: ignored, note, remark, warning, error, fatal.
// swiftlint: push
// swiftlint: ignored some_rule
... some code
// swiftlint: pop
Or a more complex scenario:
// swiftlint: push
// swiftlint: warning rule_1
// swiftlint: error rule_2
// swiftlint: error rule_3
... some code
// swiftlint: push
// swiftlint: ignored rule_3
... some code
// swiftlint: pop
... some code
// swiftlint: pop
With sensible defaults of course.
People should be fairly familiar with this approach by now and can just apply their knowledge of clang-analyzer to swiftlint, making swiftlint feel kinda like a community-based extension to clang-analyzer. With Apple being more than likely to come up with a stack-based equivalent for #pragma clang diagnostic for Swift in the future, migrating from one stack-based system to another would be much easier than from a stack-less one.
@regexident I have an implementation of the stack approach in #24. It'll be pretty easy to add options for enabling/disabling rules within a LinterContext (but I'll open a new PR for that if/when #24 is merged)
@jpsim curious about your thoughts on something: if we decide to go with the stack approach should commands in a stack apply to that context regardless of order. E.g.
Should both rules be disabled for both ... some code and ... some more code? Doing it that way might be a bit counter intuitive but if we don't we'll need to jump through some more hoops. Thoughts?
No, I don't think it makes sense to apply commands retro-actively across the same stack. The more I think of it, I really dislike the stack-based approach, both from a user's perspective and in terms of how it would add additional complexity to the parsing implementation.
Can we also provide a global configuration file where users of SwiftLint can specify their own coding style to enable/disable certain rules as they see fit? This is what is stopping me from keeping SwiftLint in my project because I either didn't agree with one of the rules, or one of the warnings was too verbose to warrant having it in my build.
Any thoughts on implementing this on a per file basis, without the push/pop first? Meaning that you could disable one or more rules for the entire file? I've implemented this on a fork by checking that the comment at the top of the file contains a string matching the rules identifier to remove it.
Does it somehow address the issue when you have the code like this:
/// Function used to test swiftlint.
///
/// - Returns: Some bool.
// swiftlint:disable:next function_body_length
func test() -> Bool {
// very long function, 100+ lines of code, triggers "function_body_length" rule violation
...
}
If the "swiftlint disable" statement is added as shown above, the documentation won't be displayed in Xcode quick documentation (Option + Click).
Activity
aarondaub commentedon May 18, 2015
@jpsim do we want to make this purely additive or subtractive (additive would be having no rules on by default, subtractive would be having all rules on by default)? I don't think we should support both - that would complicate things unnecessarily.
How do you feel about using introspection to map YAML properties to rules? Another option would be to add a property to each Rule for a YAML identifier.
segiddins commentedon May 18, 2015
I like rubocops approach -- sensible defaults, can override in either direction.
regexident commentedon May 19, 2015
I would vote for an approach based on a context-stack akin to clang analyzer:
Instead of simple serial switches one would be able to have elaborate nested configurations.
And instead of binary
enable_rule/disable_ruleswitches one would be offered to choose from the same options that clang offers:ignored,note,remark,warning,error,fatal.Or a more complex scenario:
With sensible defaults of course.
People should be fairly familiar with this approach by now and can just apply their knowledge of
clang-analyzertoswiftlint, makingswiftlintfeel kinda like a community-based extension toclang-analyzer. With Apple being more than likely to come up with a stack-based equivalent for#pragma clang diagnosticfor Swift in the future, migrating from one stack-based system to another would be much easier than from a stack-less one.aarondaub commentedon May 19, 2015
👍 stack approach. Not sure if we should add the non-binary options in this issue or open another.
regexident commentedon May 19, 2015
I'll add a separate issue for non-binary warning types if desired.
aarondaub commentedon May 21, 2015
@regexident I have an implementation of the stack approach in #24. It'll be pretty easy to add options for enabling/disabling rules within a LinterContext (but I'll open a new PR for that if/when #24 is merged)
regexident commentedon May 21, 2015
@aarondaub that's great! Looking forward to it!
aarondaub commentedon May 25, 2015
@jpsim curious about your thoughts on something: if we decide to go with the stack approach should commands in a stack apply to that context regardless of order. E.g.
Should both rules be disabled for both
... some codeand... some more code? Doing it that way might be a bit counter intuitive but if we don't we'll need to jump through some more hoops. Thoughts?jpsim commentedon May 26, 2015
No, I don't think it makes sense to apply commands retro-actively across the same stack. The more I think of it, I really dislike the stack-based approach, both from a user's perspective and in terms of how it would add additional complexity to the parsing implementation.
alexanderjarvis commentedon Jun 4, 2015
Can we also provide a global configuration file where users of SwiftLint can specify their own coding style to enable/disable certain rules as they see fit? This is what is stopping me from keeping SwiftLint in my project because I either didn't agree with one of the rules, or one of the warnings was too verbose to warrant having it in my build.
jpsim commentedon Jun 4, 2015
@alexanderjarvis we're tracking that in #3 😄
alexanderjarvis commentedon Jun 5, 2015
keith commentedon Aug 11, 2015
Any thoughts on implementing this on a per file basis, without the push/pop first? Meaning that you could disable one or more rules for the entire file? I've implemented this on a fork by checking that the comment at the top of the file contains a string matching the rules identifier to remove it.
keith commentedon Aug 11, 2015
Ah I see that something similar has been implemented in #76
Disable/re-enable rules from within source code comments. Fixes #4.
Merge pull request #111 from realm/jp-comment-commands
LeonidKokhnovich commentedon Feb 12, 2019
Does it somehow address the issue when you have the code like this:
If the "swiftlint disable" statement is added as shown above, the documentation won't be displayed in Xcode quick documentation (Option + Click).
[CI] Remove 'TSan Runs' job
[CI] Remove 'TSan Runs' job (#4701)
Merge pull request realm#4 in IOSUTILS/swiftlint from feature/force_c…