Skip to content

Commit

Permalink
[formatter] do not emit warnings that the formatter conflicts with …
Browse files Browse the repository at this point in the history
…rule `missing-trailing-commas` if no conflicts
  • Loading branch information
XuehaiPan committed Jan 29, 2025
1 parent 6090408 commit 45b5fde
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 7 additions & 4 deletions crates/ruff/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,19 +787,22 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) {
// First, collect all rules that are incompatible regardless of the linter-specific settings.
let mut incompatible_rules = FxHashSet::default();
for setting in resolver.settings() {
for rule in [
for (rule, is_conflicting) in [
// Flags missing trailing commas when all arguments are on its own line:
// ```python
// def args(
// aaaaaaaa, bbbbbbbbb, cccccccccc, ddddddddd, eeeeeeee, ffffff, gggggggggggg, hhhh
// ):
// pass
// ```
Rule::MissingTrailingComma,
(
Rule::MissingTrailingComma, // adds trailing commas
setting.formatter.magic_trailing_comma.is_ignore(), // ignores trailing commas
),
// The formatter always removes blank lines before the docstring.
Rule::IncorrectBlankLineBeforeClass,
(Rule::IncorrectBlankLineBeforeClass, true),
] {
if setting.linter.rules.enabled(rule) {
if is_conflicting && setting.linter.rules.enabled(rule) {
incompatible_rules.insert(rule);
}
}
Expand Down
2 changes: 0 additions & 2 deletions crates/ruff/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,6 @@ if condition:
print('Should change quotes')
----- stderr -----
warning: The following rule may cause conflicts when used with the formatter: `COM812`. To avoid unexpected behavior, we recommend disabling this rule, either by removing it from the `select` or `extend-select` configuration, or adding it to the `ignore` configuration.
"#);
Ok(())
}
Expand Down Expand Up @@ -1118,7 +1117,6 @@ def say_hy(name: str):
----- stderr -----
warning: `incorrect-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `incorrect-blank-line-before-class`.
warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`.
warning: The following rule may cause conflicts when used with the formatter: `COM812`. To avoid unexpected behavior, we recommend disabling this rule, either by removing it from the `select` or `extend-select` configuration, or adding it to the `ignore` configuration.
");
Ok(())
}
Expand Down

0 comments on commit 45b5fde

Please sign in to comment.