-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[isort] Exclude pragma comments from line length calculation (I001)
#27313
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0a495f5
exclude pragma from line length calculation
ericbuehl 541630e
use preview::is_trailing_pragma_in_line_length_enabled
ericbuehl 37da6e7
additional test case
ericbuehl 5163d3a
generalize add_comment
ericbuehl b1ae663
missing files
ericbuehl afe5732
is_pragma_excluded_from_import_width_enabled
ericbuehl c581601
Merge branch 'main' into eb-pragma-line-length
ericbuehl f1d6066
Merge branch 'main' into eb-pragma-line-length
ntBre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
crates/ruff_linter/resources/test/fixtures/isort/fit_line_length_merged_pragma.py
This file contains hidden or 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,17 @@ | ||
| # Separate statement-level and alias-level comments that isort merges onto one line | ||
| # when collapsing. The merged comment token is 89 columns with the `# explain` prefix | ||
| # counted, so the import must not end up on an overlong single line. | ||
| from aaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaa import ( # explain | ||
| x # noqa: TID251 | ||
| ) | ||
|
|
||
| # A single mixed comment on an already-collapsed 102-column line. The code plus the | ||
| # non-pragma prefix is 86 columns. | ||
| from bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb import x # explain # noqa: TID251 | ||
|
|
||
| # Separate comments with the pragma first: when isort collapses this import in preview, | ||
| # the merged comment token is pragma-prefixed, so E501 strips it entirely and the | ||
| # collapsed 104-column line is fine. | ||
| from ccccccccccccccccccccccccccccccc.ccccccccccccccccccccccccccccccc import ( # noqa: TID251 | ||
| x # explain | ||
| ) |
6 changes: 6 additions & 0 deletions
6
crates/ruff_linter/resources/test/fixtures/isort/fit_line_length_mixed_pragma.py
This file contains hidden or 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,6 @@ | ||
| # The next import fits on one line once the trailing pragma is excluded from the width | ||
| # (the `# keep this` prefix still counts); in preview it should not be wrapped. | ||
| from aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa import x # keep this # noqa: TID251 | ||
| # The next import exceeds the line length even without the trailing pragma | ||
| # (code plus the `# keep this` prefix is 89 columns); it must always be wrapped. | ||
| from bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb import x # keep this # noqa: TID251 |
13 changes: 13 additions & 0 deletions
13
crates/ruff_linter/resources/test/fixtures/isort/fit_line_length_pragma.py
This file contains hidden or 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,13 @@ | ||
| # The next import fits on one line once the pragma comment is excluded from the width; | ||
| # in preview it should not be wrapped (the `# noqa` must stay effective). | ||
| from aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa import x # noqa: TID251 | ||
| # The next import exceeds the line length even without the pragma comment; | ||
| # it must still be wrapped. | ||
| from bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb import x # noqa: TID251 | ||
|
|
||
|
|
||
| def f(): | ||
| # The next import fits on one line once the pragma comment is excluded from the | ||
| # width, so in preview it should not be wrapped. | ||
| from cccccccccccccccccccccccccccccc.ccccccccccccccccccccccccccccccccccccc import bar # noqa: PLC0415 | ||
| bar() |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
17 changes: 17 additions & 0 deletions
17
...pshots/ruff_linter__rules__isort__tests__fit_line_length_merged_pragma_fixed_preview.snap
This file contains hidden or 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,17 @@ | ||
| --- | ||
| source: crates/ruff_linter/src/rules/isort/mod.rs | ||
| expression: transformed.source_code() | ||
| --- | ||
| # Separate statement-level and alias-level comments that isort merges onto one line | ||
| # when collapsing. The merged comment token is 89 columns with the `# explain` prefix | ||
| # counted, so the import must not end up on an overlong single line. | ||
| from aaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaa import x # explain # noqa: TID251 | ||
|
|
||
| # A single mixed comment on an already-collapsed 102-column line. The code plus the | ||
| # non-pragma prefix is 86 columns. | ||
| from bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb import x # explain # noqa: TID251 | ||
|
|
||
| # Separate comments with the pragma first: when isort collapses this import in preview, | ||
| # the merged comment token is pragma-prefixed, so E501 strips it entirely and the | ||
| # collapsed 104-column line is fine. | ||
| from ccccccccccccccccccccccccccccccc.ccccccccccccccccccccccccccccccc import x # noqa: TID251 # explain |
23 changes: 23 additions & 0 deletions
23
...apshots/ruff_linter__rules__isort__tests__fit_line_length_merged_pragma_fixed_stable.snap
This file contains hidden or 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,23 @@ | ||
| --- | ||
| source: crates/ruff_linter/src/rules/isort/mod.rs | ||
| expression: transformed.source_code() | ||
| --- | ||
| # Separate statement-level and alias-level comments that isort merges onto one line | ||
| # when collapsing. The merged comment token is 89 columns with the `# explain` prefix | ||
| # counted, so the import must not end up on an overlong single line. | ||
| from aaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaa import ( # explain | ||
| x, # noqa: TID251 | ||
| ) | ||
|
|
||
| # A single mixed comment on an already-collapsed 102-column line. The code plus the | ||
| # non-pragma prefix is 86 columns. | ||
| from bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb import ( | ||
| x, # explain # noqa: TID251 | ||
| ) | ||
|
|
||
| # Separate comments with the pragma first: when isort collapses this import in preview, | ||
| # the merged comment token is pragma-prefixed, so E501 strips it entirely and the | ||
| # collapsed 104-column line is fine. | ||
| from ccccccccccccccccccccccccccccccc.ccccccccccccccccccccccccccccccc import ( # noqa: TID251 | ||
| x, # explain | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.