Question: What is the expected behaviour of opt_in_rules
and disabled_rules
in a child configuration?
#4876
Closed
2 tasks done
Labels
discussion
Topics that cannot be categorized as bugs or enhancements yet. They require further discussions.
New Issue Checklist
Describe the bug
Replaces #4859
Some of the behaviours of
opt_in_rules
anddisabled_rules
seem, at face value, to be incorrect.For example, consider a case where the parent.yml looks like:
and the child.yml looks like:
Naively, I would expect the specified opt-in rule to be disabled in the parent configuration, and to also be disabled in the child, but in practice, with
0.51.0
, the rule will be enabled in the child, according to therules
subcommand:And observing actual linting behaviour, given
Similarly, if the child configuration is
and the parent has a "default" configuration (using opt_in_rules and disabled_rules), no matter what the parent settings, the specified rule will always be enabled in the child, which seems wrong.
Below is the complete truth table for whether an optin rule is enabled in the merged configuration, as a function of whether it is listed in the opt_in_rules, and/or the disabled_rules sections of the parent and child configurations.
The "unexpected" cases are asterisked.
The current behaviour is actually "better" for some use cases - if I want my child configuration to be stricter than the parent, the current behaviour can actually end up being more compact than the new configuration, and I suspect that fixing this would be a breaking change for some users, but the current behaviour nevertheless seems counter-intuitive to me.
My "question" is, is the current behaviour intentional, or it should it actually behave as the
proposed
column above, or in some other way?A similar situation occurs when the parent configuration uses
only_rules
, and the child has a default configuration.The truth table for this case (of whether the rule is enabled in the merged configuration) is:
Examining case 3
parent.yml:
and child.yml:
Currently (in main/0.51.0) the rule would end up enabled for the child, even though it is explicitly disabled in the child configuration.
Complete output when running SwiftLint, including the stack trace and command used
See above
Environment
swiftlint version
to be sure)?0.51.0
Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew
Paste your configuration file:
See above
Are you using nested configurations? Nested no, but parent and child yes.
Which Xcode version are you using (check
xcodebuild -version
)?echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
to quickly test if your example is really demonstrating the issue. If your example is more
complex, you can use
swiftlint lint --path [file here] --no-cache --enable-all-rules
.See description above
The text was updated successfully, but these errors were encountered: