-
Notifications
You must be signed in to change notification settings - Fork 1k
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
(🎁) preserve node line of noqa
comments when formatting
#12901
Comments
I understand why this is desired, but it has quite far-reaching implications, and it would significantly slow down formatting because formatting would require running the linter, a trade-off that I think isn't worth the occasional move of a noqa comment. Long-term, this does not just apply to running the linter but also type-checking and there are suppression comments that ruff doesn't even understand. So the problem doesn't go away, it might just happen less often (which would already be nice). To me the most likely solution is redesigning suppression comments so that it is known what target they suppress by being more explicit about where they can be placed. E.g. only allow own-line suppression comments, maybe even on a statement level. |
99% of the time I want to both format and check, currently it's two separate steps, and I would presume that would make it take longer Personally I would love to trade speed for more correctness, but know not everyone thinks the same |
I have the same problem with with mypy's For example, the following line: def parse_document(self, document: DocumentInfo, stream: BytesIO, effective: datetime.date, span: Span) -> None: # type: ignore[override]
... Gets reformatted as: def parse_document(
self, document: DocumentInfo, stream: BytesIO, effective: datetime.date, span: Span
) -> None: # type: ignore[override]
... Which makes mypy unable to detect the ignore comment, as it has been moved to the incorrect place. Black prevents splitting lines that contain |
Another example I've run into:
Reformatted file:
Workaround:
|
after format (fail)
ruff is doing the
check
ing of thisnoqa
, ruff is also the one doing theformat
ing, so it would seem logical that ruff use thecheck
information to keep thenoqa
on the right lineAdditionally
this isn't exclusive to
format
as changes fromcheck
can also conflict, see #12179related:
I001
andRUF100
#12179The text was updated successfully, but these errors were encountered: