astral-sh / astral-sh/ruff

(🎁) preserve node line of `noqa` comments when formatting

Open
#12,901 6 comments 5 reactions 0 assignees View on GitHub
incompatibility suppression wish
Dominant language
Rust
Stars
49.6k
Forks
2.4k
Avg merge
1d 21h
Merged PRs (30d)
435

Description

```py
dict(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=1) # noqa: C408
```

# after format (fail)
```py
dict(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=1
) # noqa: C408
```

ruff is doing the `check`ing of this `noqa`, ruff is also the one doing the `format`ing, so it would seem logical that ruff use the `check` information to keep the `noqa` on the right line
```py
dict( # noqa: C408
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=1
)
```

# Additionally

this isn't exclusive to `format` as changes from `check` can also conflict, see #12179

related:
- #8232
- #12179

Contributor guide

Open the contributing guide

Research direction

Run the provided Python reproduction with Ruff's check and format workflows, then read the handling of noqa diagnostics and formatted line changes. Compare the related issues #8232 and #12179; done means the noqa remains on the line checked by Ruff after formatting and check-induced changes do not create the same conflict.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.