-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[pycodestyle] Add an autofix for E402
#22212
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
37 commits
Select commit
Hold shift + click to select a range
e70d297
Add reference project
PeterJCLaw 3328deb
Update block output
PeterJCLaw bb28d91
More demo
PeterJCLaw cb4619d
More demo details
PeterJCLaw c075114
WIP E402 fix
PeterJCLaw 1bc2431
First attempt to preserve comments
PeterJCLaw 126a95c
Enable more fixes in the test project
PeterJCLaw 30d94e2
Some more imports to make it visible when editor import organisation …
PeterJCLaw 2062d76
Include E402 fixing in editor import organising
PeterJCLaw 3a74298
Remove unused import
PeterJCLaw 9b82555
Remove comment-out code
PeterJCLaw 2a40051
Improve handling of lines around moved imports
PeterJCLaw 1a7dee2
Remove debug files from previous approach
PeterJCLaw e161ff9
First pass at supporting fixing E402 in notebooks too
PeterJCLaw fd07fd5
Add fix title for E402 fixer
PeterJCLaw b633b7f
Update snapshot tests for E402 fixer
PeterJCLaw 913a236
Comment about unsafe fixes in the organise imports action
PeterJCLaw e623668
Drop demo project now it's no longer needed
PeterJCLaw 60e386f
Add tests for e402 fixer
PeterJCLaw 47df7c1
Ensure fixes for E402 are only moved to after future imports
PeterJCLaw f99f1cb
Merge branch 'main' into e402-fixer
PeterJCLaw 7ff8f51
Only enable E402 fixer in preview mode
PeterJCLaw 25e4fde
Reinstate non-preview files
PeterJCLaw f4f8196
Merge branch 'main' into e402-fixer
PeterJCLaw 1a4b053
Rebuild snapshots for newer cargo-insta
PeterJCLaw 0a34521
Group imports
PeterJCLaw 4d73f92
Avoid allocation we don't need
PeterJCLaw 8582e57
Clarify helper function name
PeterJCLaw 6271fc9
Add notes on fix safety
PeterJCLaw 671fbf2
Remove redundant code from snapshot tests
PeterJCLaw 66a1fe8
Improve comment
PeterJCLaw 33b5efb
Drop attempted support for notebooks
PeterJCLaw 53e2818
No need to run these new fixer tests non-preview
PeterJCLaw a5a1ebf
Merge branch 'main' into e402-fixer
PeterJCLaw 0a70b5c
Update snapshots following #26161
PeterJCLaw 31b7cf5
Merge branch 'main' into e402-fixer
PeterJCLaw a13c73f
Simplify import insertion logic dropping partial notebook support
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
crates/ruff_linter/resources/test/fixtures/pycodestyle/E402_comments.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,25 @@ | ||
| import os | ||
|
|
||
| print("something") | ||
|
|
||
| import last | ||
|
|
||
| import late # comment-late | ||
|
|
||
| from late_paren1 import ( # comment-late_paren1 | ||
| value | ||
| ) | ||
|
|
||
| from late_paren2 import ( | ||
| value # comment-late_paren2 | ||
| ) | ||
|
|
||
| from late_paren3 import ( | ||
| value | ||
| ) # comment-late_paren3 | ||
|
|
||
| from late_paren4 import ( | ||
| value1, | ||
| value2, # comment-late_paren4 | ||
| value3, | ||
| ) |
5 changes: 5 additions & 0 deletions
5
crates/ruff_linter/resources/test/fixtures/pycodestyle/E402_docstring.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,5 @@ | ||
| """module docstring""" | ||
|
|
||
| print("something") | ||
|
|
||
| import os |
5 changes: 5 additions & 0 deletions
5
crates/ruff_linter/resources/test/fixtures/pycodestyle/E402_future.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,5 @@ | ||
| from __future__ import annotations | ||
|
|
||
| print("something") | ||
|
|
||
| import os |
5 changes: 5 additions & 0 deletions
5
crates/ruff_linter/resources/test/fixtures/pycodestyle/E402_shebang.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,5 @@ | ||
| #!/usr/bin/python3 | ||
|
|
||
| print("something") | ||
|
|
||
| import os |
9 changes: 9 additions & 0 deletions
9
crates/ruff_linter/resources/test/fixtures/pycodestyle/E402_shebang_docstring_and_future.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,9 @@ | ||
| #!/usr/bin/python3 | ||
|
|
||
| """docstring""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| print("something") | ||
|
|
||
| import os |
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
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
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.