Skip to content
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

[formatter] do not emit warnings that the formatter conflicts with rule missing-trailing-comma if no conflicts #15807

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading