Thanks to visit codestin.com
Credit goes to github.com

Skip to content

docs: Clarify COM819 and formatter interaction#25045

Merged
MichaReiser merged 3 commits into
astral-sh:mainfrom
Andrej730:warn-com819-formatter-incompatibility
May 13, 2026
Merged

docs: Clarify COM819 and formatter interaction#25045
MichaReiser merged 3 commits into
astral-sh:mainfrom
Andrej730:warn-com819-formatter-incompatibility

Conversation

@Andrej730
Copy link
Copy Markdown
Contributor

@Andrej730 Andrej730 commented May 8, 2026

When fixing #25044 and review what other rules might not be documented, I've stumbled upon https://docs.astral.sh/ruff/rules/prohibited-trailing-comma/ which is documented, but it seems to be more than just redundant.

Using this rule changes the meaning of using magic comma in some cases. E.g. foo = (1, 2, 3,) - if user would run ruff check first, then it would strip the magic comma and ruff format would do nothing. And if we'd do ruff format first, then it would expand this to multiple lines and then ruff check would do nothing. Given that when you're writing code you might leave this magic command, knowing that it will expand later in an expected way, - with COM819 it might if you run linter first.

So I've added a warning when this rule is enabled and adjusted the documentation.

I've executed the tests and adjusted the ones that were testing ALL.
All tests seems to be fine now, besides that one (seems unrelated to PR) and bunch of other tests that seems to conflict with my global ruff settings, I'll report it as an issue separately (see #25046).

Reviewing [1/6] [email protected]:
Snapshot: semantic_syntax_errors
Source: crates/ruff/tests/cli/lint.rs:3553
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
program: ruff
args:
  - check
  - "--output-format"
  - concise
  - "--preview"
  - "--quiet"
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
-old snapshot
+new results
────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    1     1 │ success: false
    2     2 │ exit_code: 1
    3     3 │ ----- stdout -----
    4     4 │ main.py:1:3: error[invalid-syntax] assignment expression cannot rebind comprehension variable
    5       │-main.py:1:20: error[F821] Undefined name `foo`
    6     5 │ 
    7     6 │ ----- stderr -----
────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

When fixing #25044 and review what other rules might not be documented, I've stumbled upon https://docs.astral.sh/ruff/rules/prohibited-trailing-comma/ which is documented, but it seems to be more than just redundant.

Using this rule changes the meaning of using magic comma in some cases. E.g. `foo = (1, 2, 3,)` - if user would run `ruff check` first, then it would strip the magic comma and `ruff format` would do nothing. And if we'd do `ruff format` first, then it would expand this to multiple lines and then `ruff check` would do nothing. Given that when you're writing code you might leave this magic command, knowing that it will expand later in an expected way, - with COM819 it might if you run linter first.

So I've added a warning when this rule is enabled and adjusted the documentation.
@astral-sh-bot astral-sh-bot Bot requested a review from ntBre May 8, 2026 11:48
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 8, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser
Copy link
Copy Markdown
Member

MichaReiser commented May 12, 2026

Thank you.

I don't see COM819 qualify as being incompatible with the formatter. A rule is only incompatible if the formatter can introduce new violations when running the formatter after a clean ruff check. This is not the case for COM819.

I do agree that you want to disable COM819 when using skip-magic-comma=false (the default). We could update the rule documentation but I don't think we should add a warning. They're very disruptive because they can't be suppressed.

@Andrej730 Andrej730 changed the title fix: Add COM819 to formatter incompatibility checks docs: Clarify COM819 and formatter interaction May 12, 2026
@Andrej730
Copy link
Copy Markdown
Contributor Author

Yeah, incompatibility is probably too strong of a term for this, it's more of a conflict.

Personally, I'd like this kind of rules conflict to surface to me when using the tool, instead of encountering inconsistency and exploring the docs, but warnings can be annoying - especially since this one would become a new default ignore for everyone using select ALL, though arguably it is the thing they need when blanket subscribing to rules...

Anyways, I've dropped the warning and updated the docs, mentioning format.skip-magic-trailing-comma setting more specifically.

@MichaReiser MichaReiser added the documentation Improvements or additions to documentation label May 13, 2026
@MichaReiser MichaReiser enabled auto-merge (squash) May 13, 2026 12:16
@MichaReiser MichaReiser merged commit 8d4d72f into astral-sh:main May 13, 2026
43 checks passed
@Andrej730 Andrej730 deleted the warn-com819-formatter-incompatibility branch May 16, 2026 08:53
thejchap pushed a commit to thejchap/ruff that referenced this pull request May 23, 2026
When fixing astral-sh#25044 and review what
other rules might not be documented, I've stumbled upon
https://docs.astral.sh/ruff/rules/prohibited-trailing-comma/ which is
documented, but it seems to be more than just redundant.

Using this rule changes the meaning of using magic comma in some cases.
E.g. `foo = (1, 2, 3,)` - if user would run `ruff check` first, then it
would strip the magic comma and `ruff format` would do nothing. And if
we'd do `ruff format` first, then it would expand this to multiple lines
and then `ruff check` would do nothing. Given that when you're writing
code you might leave this magic command, knowing that it will expand
later in an expected way, - with COM819 it might if you run linter
first.

So I've added a warning when this rule is enabled and adjusted the
documentation.

I've executed the tests and adjusted the ones that were testing `ALL`.
All tests seems to be fine now, besides that one (seems unrelated to PR)
and bunch of other tests that seems to conflict with my global ruff
settings, I'll report it as an issue separately (see
astral-sh#25046).
```
Reviewing [1/6] [email protected]:
Snapshot: semantic_syntax_errors
Source: crates/ruff/tests/cli/lint.rs:3553
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
program: ruff
args:
  - check
  - "--output-format"
  - concise
  - "--preview"
  - "--quiet"
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
-old snapshot
+new results
────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    1     1 │ success: false
    2     2 │ exit_code: 1
    3     3 │ ----- stdout -----
    4     4 │ main.py:1:3: error[invalid-syntax] assignment expression cannot rebind comprehension variable
    5       │-main.py:1:20: error[F821] Undefined name `foo`
    6     5 │ 
    7     6 │ ----- stderr -----
────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

```

---------

Co-authored-by: Micha Reiser <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants