Skip to content
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

[isort] Omit trailing whitespace in unsorted-imports (I001) #15518

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dylwil3
Copy link
Collaborator

@dylwil3 dylwil3 commented Jan 15, 2025

Summary

The fix range for sorting imports accounts for trailing whitespace, but we should only show the trimmed range to the user when displaying the diagnostic. So this PR changes the diagnostic range.

Closes #15504

Test Plan

Reviewed snapshot changes

@dylwil3 dylwil3 added the diagnostics Related to reporting of diagnostics. label Jan 15, 2025
@dylwil3
Copy link
Collaborator Author

dylwil3 commented Jan 15, 2025

Questions:

  1. Is it kosher to have the fix range larger than the diagnostic range? Is there some logic that assumes containment goes the other way?
  2. Is this a breaking change because of suppression comments?
  3. Would you like me to include end of line comments?

@dylwil3 dylwil3 requested a review from BurntSushi January 15, 2025 22:31
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+5 -5 violations, +0 -0 fixes in 1 projects; 54 projects unchanged)

bokeh/bokeh (+5 -5 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

- examples/server/app/gapminder/data.py:5:1: I001 [*] Import block is un-sorted or un-formatted
+ examples/server/app/gapminder/data.py:5:5: I001 [*] Import block is un-sorted or un-formatted
- src/bokeh/model/model.py:46:1: I001 [*] Import block is un-sorted or un-formatted
+ src/bokeh/model/model.py:46:5: I001 [*] Import block is un-sorted or un-formatted
- src/bokeh/model/util.py:167:1: I001 [*] Import block is un-sorted or un-formatted
+ src/bokeh/model/util.py:167:5: I001 [*] Import block is un-sorted or un-formatted
- src/bokeh/server/connection.py:28:1: I001 [*] Import block is un-sorted or un-formatted
+ src/bokeh/server/connection.py:28:5: I001 [*] Import block is un-sorted or un-formatted
- tests/test_cross.py:34:1: I001 [*] Import block is un-sorted or un-formatted
+ tests/test_cross.py:34:5: I001 [*] Import block is un-sorted or un-formatted

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
I001 10 5 5 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+5 -5 violations, +0 -0 fixes in 1 projects; 54 projects unchanged)

bokeh/bokeh (+5 -5 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- examples/server/app/gapminder/data.py:5:1: I001 [*] Import block is un-sorted or un-formatted
+ examples/server/app/gapminder/data.py:5:5: I001 [*] Import block is un-sorted or un-formatted
- src/bokeh/model/model.py:46:1: I001 [*] Import block is un-sorted or un-formatted
+ src/bokeh/model/model.py:46:5: I001 [*] Import block is un-sorted or un-formatted
- src/bokeh/model/util.py:167:1: I001 [*] Import block is un-sorted or un-formatted
+ src/bokeh/model/util.py:167:5: I001 [*] Import block is un-sorted or un-formatted
- src/bokeh/server/connection.py:28:1: I001 [*] Import block is un-sorted or un-formatted
+ src/bokeh/server/connection.py:28:5: I001 [*] Import block is un-sorted or un-formatted
- tests/test_cross.py:34:1: I001 [*] Import block is un-sorted or un-formatted
+ tests/test_cross.py:34:5: I001 [*] Import block is un-sorted or un-formatted

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
I001 10 5 5 0 0

@dylwil3 dylwil3 added the rule Implementing or modifying a lint rule label Jan 15, 2025
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

I kind of liked that the old range included the entire line instead of just the expression range. It would be nice if we can preserve that behavior

@@ -30,7 +30,7 @@ force_single_line.py:1:1: I001 [*] Import block is un-sorted or un-formatted
25 | |
26 | | # comment 9
27 | | from baz import * # comment 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly incorrect but I think I liked the old one better

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I like the new one since it's a little more specific. But I do feel like the old one is more aesthetically pleasing.

@@ -30,7 +30,7 @@ force_single_line.py:1:1: I001 [*] Import block is un-sorted or un-formatted
25 | |
26 | | # comment 9
27 | | from baz import * # comment 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I like the new one since it's a little more specific. But I do feel like the old one is more aesthetically pleasing.

7 | | from my_first_party import my_first_party_object
8 | |
9 | | from . import my_local_folder_object
| |____________________________________^ I001
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

|
32 | import sys; import os # isort:skip
33 | import sys; import os # isort:skip # isort:skip
34 | import sys; import os
| ^^^^^^^^^^^^^^^^^^^^^^^^^ I001
| ^^^^^^^^^^^^^^^^^^^^^ I001
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another nice improvement I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostics Related to reporting of diagnostics. rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

diagnostic rendering for import lint I001 is sub-optimal in some cases
3 participants