You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When formatting a pyi file, ruff format only keeps a single line after the imports. If ruff.lint.isort.lines-after-imports is configured to 2. ruff format will conflict with ruff check.
This doesn't happen to py files. ruff format will keep the two lines after the imports.
Example:
(.venv) ☁ ruff-demo cat test.py
from typing import Any
class Foo:
def bar(self, data: Any) -> None:
pass
(.venv) ☁ ruff-demo ruff format --check test.py
1 file already formatted
(.venv) ☁ ruff-demo cat test.pyi
from typing import Any
class Foo:
def bar(self, data: Any) -> None: ...
(.venv) ☁ ruff-demo ruff format --check test.pyi
Would reformat: test.pyi
1 file would be reformatted
(.venv) ☁ ruff-demo
Ruff Version: 0.1.9
Ruff Command: ruff format
The text was updated successfully, but these errors were encountered:
This feels like it's "working as intended" even though the option is conflicting. If anything, we may want to warn here, as we do for other incompatible options (2 is a permitted value, but I don't think we considered that it would conflict for .pyi files). The alternative would be to ignore lines-after-imports in .pyi files.
Ignore lines-after-imports in .pyi files would be nice. Currently, we're using both ruff check and ruff format --check in our CI pipeline. We do want two lines after the imports in py files. So, in order to make the CI green, we need to skip ruff check for all the pyi files for now.
Thank you for reporting this issue. That's something I haven't been aware when adding the warnings.
Warning when setting lines-after-imports to a value other than 1 might be noisy, except if we limit it only to warn when formatting a pyi file (which would be different from the other incompatible warnings). It would also not enable the use case mentioned by @kkpattern.
I think I would start by ignoring lines-after-imports in pyi files. But we may need to do run a GitHub code search first to find projects that use lines-after-imports with a value other than 1 and have pyi files to not break their setup.
When formatting a pyi file,
ruff format
only keeps a single line after the imports. Ifruff.lint.isort.lines-after-imports
is configured to2
.ruff format
will conflict withruff check
.This doesn't happen to py files.
ruff format
will keep the two lines after the imports.Example:
Ruff Version: 0.1.9
Ruff Command:
ruff format
The text was updated successfully, but these errors were encountered: