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
Refine the warnings about incompatible linter options (#8196)
## Summary
Avoid warning about incompatible rules except if their configuration
directly conflicts with the formatter. This should reduce the noise and
potentially the need for #8175
and #8185
I also extended the rule and option documentation to mention any
potential formatter incompatibilities or whether they're redundant when
using the formatter.
* `LineTooLong`: This is a use case we explicitly want to support. Don't
warn about it
* `TabIndentation`, `IndentWithSpaces`: Only warn if
`indent-style="tab"`
* `IndentationWithInvalidMultiple`,
`IndentationWithInvalidMultipleComment`: Only warn if `indent-width !=
4`
* `OverIndented`: Don't warn, but mention that the rule is redundant
* `BadQuotesInlineString`: Warn if quote setting is different from
`format.quote-style`
* `BadQuotesMultilineString`, `BadQuotesDocstring`: Warn if `quote !=
"double"`
## Test Plan
I added a new integration test for the default configuration with `ALL`.
`ruff format` now only shows two incompatible rules, which feels more
reasonable.
for rule in[Rule::TabIndentation,Rule::IndentWithSpaces]{
723
+
if setting.linter.rules.enabled(rule){
724
+
incompatible_rules.push(rule);
725
+
}
726
+
}
727
+
}
728
+
729
+
// Rules asserting for indent-width=4
730
+
if setting.formatter.indent_width.value() != 4{
731
+
for rule in[
732
+
Rule::IndentationWithInvalidMultiple,
733
+
Rule::IndentationWithInvalidMultipleComment,
734
+
]{
735
+
if setting.linter.rules.enabled(rule){
736
+
incompatible_rules.push(rule);
737
+
}
722
738
}
723
739
}
724
740
725
741
if !incompatible_rules.is_empty(){
726
-
incompatible_rules.sort();
727
-
warn!("The following rules may cause conflicts when used with the formatter: {}. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding then to the `ignore` configuration.", incompatible_rules.join(", "));
742
+
letmut rule_names:Vec<_> = incompatible_rules
743
+
.into_iter()
744
+
.map(|rule| format!("`{}`", rule.noqa_code()))
745
+
.collect();
746
+
rule_names.sort();
747
+
warn!("The following rules may cause conflicts when used with the formatter: {}. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding then to the `ignore` configuration.", rule_names.join(", "));
warn!("The `flake8-quotes.inline-quotes=\"double\"` option is incompatible with the formatter's `format.quote-style=\"single\"`. We recommend disabling `Q000` and `Q003` when using the formatter, which enforces a consistent quote style. Alternatively, set both options to either `\"single\"` or `\"double\"`.");
762
+
}
763
+
(Quote::Single,QuoteStyle::Double) => {
764
+
warn!("The `flake8-quotes.inline-quotes=\"single\"` option is incompatible with the formatter's `format.quote-style=\"double\"`. We recommend disabling `Q000` and `Q003` when using the formatter, which enforces a consistent quote style. Alternatively, set both options to either `\"single\"` or `\"double\"`.");
765
+
}
766
+
_ => {}
767
+
}
768
+
}
769
+
770
+
if setting.linter.rules.enabled(Rule::BadQuotesMultilineString)
warn!("The `flake8-quotes.multiline-quotes=\"single\"` option is incompatible with the formatter. We recommend disabling `Q001` when using the formatter, which enforces double quotes for multiline strings. Alternatively, set the `flake8-quotes.multiline-quotes` option to `\"double\"`.`");
774
+
}
775
+
776
+
if setting.linter.rules.enabled(Rule::BadQuotesDocstring)
warn!("The `flake8-quotes.multiline-quotes=\"single\"` option is incompatible with the formatter. We recommend disabling `Q002` when using the formatter, which enforces double quotes for docstrings. Alternatively, set the `flake8-quotes.docstring-quotes` option to `\"double\"`.`");
728
780
}
729
781
730
782
if setting.linter.rules.enabled(Rule::UnsortedImports){
731
783
// The formatter removes empty lines if the value is larger than 2 but always inserts a empty line after imports.
732
784
// Two empty lines are okay because `isort` only uses this setting for top-level imports (not in nested blocks).
733
785
if !matches!(setting.linter.isort.lines_after_imports,1 | 2 | -1){
734
-
warn!("The isort option 'isort.lines-after-imports' with a value other than `-1`, `1` or `2` is incompatible with the formatter. To avoid unexpected behavior, we recommend setting the option to one of: `2`, `1`, or `-1` (default).");
786
+
warn!("The isort option `isort.lines-after-imports` with a value other than `-1`, `1` or `2` is incompatible with the formatter. To avoid unexpected behavior, we recommend setting the option to one of: `2`, `1`, or `-1` (default).");
735
787
}
736
788
737
789
// Values larger than two get reduced to one line by the formatter if the import is in a nested block.
738
790
if setting.linter.isort.lines_between_types > 1{
739
-
warn!("The isort option 'isort.lines-between-types' with a value larger than 1 is incompatible with the formatter. To avoid unexpected behavior, we recommend setting the option to one of: `1` or `0` (default).");
791
+
warn!("The isort option `isort.lines-between-types` with a value greater than 1 is incompatible with the formatter. To avoid unexpected behavior, we recommend setting the option to one of: `1` or `0` (default).");
740
792
}
741
793
742
794
// isort inserts a trailing comma which the formatter preserves, but only if `skip-magic-trailing-comma` isn't false.
743
795
if setting.formatter.magic_trailing_comma.is_ignore(){
744
796
if setting.linter.isort.force_wrap_aliases{
745
-
warn!("The isort option 'isort.force-wrap-aliases' is incompatible with the formatter 'format.skip-magic-trailing-comma=true' option. To avoid unexpected behavior, we recommend either setting 'isort.force-wrap-aliases=false' or 'format.skip-magic-trailing-comma=false'.");
797
+
warn!("The isort option `isort.force-wrap-aliases` is incompatible with the formatter `format.skip-magic-trailing-comma=true` option. To avoid unexpected behavior, we recommend either setting `isort.force-wrap-aliases=false` or `format.skip-magic-trailing-comma=false`.");
746
798
}
747
799
748
800
if setting.linter.isort.split_on_trailing_comma{
749
-
warn!("The isort option 'isort.split-on-trailing-comma' is incompatible with the formatter 'format.skip-magic-trailing-comma=true' option. To avoid unexpected behavior, we recommend either setting 'isort.split-on-trailing-comma=false' or 'format.skip-magic-trailing-comma=false'.");
801
+
warn!("The isort option `isort.split-on-trailing-comma` is incompatible with the formatter `format.skip-magic-trailing-comma=true` option. To avoid unexpected behavior, we recommend either setting `isort.split-on-trailing-comma=false` or `format.skip-magic-trailing-comma=false`.");
0 commit comments