-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…10096) ## Summary This PR changes the `E3*` rules to respect the `isort` `lines-after-imports` and `lines-between-types` settings. Specifically, the following rules required changing * `TooManyBlannkLines` : Respects both settings. * `BlankLinesTopLevel`: Respects `lines-after-imports`. Doesn't need to respect `lines-between-types` because it only applies to classes and functions The downside of this approach is that `isort` and the blank line rules emit a diagnostic when there are too many blank lines. The fixes aren't identical, the blank line is less opinionated, but blank lines accepts the fix of `isort`. <details> <summary>Outdated approach</summary> Fixes #10077 (comment) This PR changes the blank line rules to not enforce the number of blank lines after imports (top-level) if isort is enabled and leave it to isort to enforce the right number of lines (depends on the `isort.lines-after-imports` and `isort.lines-between-types` settings). The reason to give `isort` precedence over the blank line rules is that they are configurable. Users that always want to blank lines after imports can use `isort.lines-after-imports=2` to enforce that (specifically for imports). This PR does not fix the incompatibility with the formatter in pyi files that only uses 0 to 1 blank lines. I'll address this separately. </details> ## Review The first commit is a small refactor that simplified implementing the fix (and makes it easier to reason about what's mutable and what's not). ## Test Plan I added a new test and verified that it fails with an error that the fix never converges. I verified the snapshot output after implementing the fix. --------- Co-authored-by: Hoël Bagard <34478245+hoel-bagard@users.noreply.github.com>
- Loading branch information
1 parent
d441338
commit 46ab9de
Showing
16 changed files
with
1,565 additions
and
248 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
crates/ruff_linter/resources/test/fixtures/pycodestyle/.editorconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# These rules test for intentional "odd" formatting. Using a formatter fixes that | ||
[E{1,2,3}*.py] | ||
generated_code = true | ||
ij_formatter_enabled = false | ||
|
||
[W*.py] | ||
generated_code = true | ||
ij_formatter_enabled = false |
62 changes: 62 additions & 0 deletions
62
crates/ruff_linter/resources/test/fixtures/pycodestyle/E30_isort.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import json | ||
|
||
|
||
|
||
from typing import Any, Sequence | ||
|
||
|
||
class MissingCommand(TypeError): ... # noqa: N818 | ||
|
||
|
||
class BackendProxy: | ||
backend_module: str | ||
backend_object: str | None | ||
backend: Any | ||
|
||
|
||
if __name__ == "__main__": | ||
import abcd | ||
|
||
|
||
abcd.foo() | ||
|
||
def __init__(self, backend_module: str, backend_obj: str | None) -> None: ... | ||
|
||
if TYPE_CHECKING: | ||
import os | ||
|
||
|
||
|
||
from typing_extensions import TypeAlias | ||
|
||
|
||
abcd.foo() | ||
|
||
def __call__(self, name: str, *args: Any, **kwargs: Any) -> Any: | ||
... | ||
|
||
if TYPE_CHECKING: | ||
from typing_extensions import TypeAlias | ||
|
||
def __call__2(self, name: str, *args: Any, **kwargs: Any) -> Any: | ||
... | ||
|
||
|
||
def _exit(self) -> None: ... | ||
|
||
|
||
def _optional_commands(self) -> dict[str, bool]: ... | ||
|
||
|
||
def run(argv: Sequence[str]) -> int: ... | ||
|
||
|
||
def read_line(fd: int = 0) -> bytearray: ... | ||
|
||
|
||
def flush() -> None: ... | ||
|
||
|
||
from typing import Any, Sequence | ||
|
||
class MissingCommand(TypeError): ... # noqa: N818 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.