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

Implement import sorting #633

Merged
merged 10 commits into from Nov 11, 2022
Merged

Implement import sorting #633

merged 10 commits into from Nov 11, 2022

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Nov 7, 2022

This PR implements isort-like import sorting behavior. The intent is to mirror isort when used with the following configuration:

[tool.isort]
profile = "black"
combine_as_imports = true

The main limitations in the current approach are as follows:

  1. We still have no way of reconciling conflicting autofix errors. So if you have unused and unsorted imports, Ruff will only fix one of the two in the first pass (probably the unsorted imports, since that block comes first), and you'll have to run Ruff again to fix the other.
  2. We don't have any comment-handling, so all comments are removed entirely

For now, this is implemented via an entirely separator visitor, mostly to make the code easier to reason about. I need to benchmark the impact of that choice.

Resolves: #465.

@charliermarsh charliermarsh force-pushed the charlie/isort branch 8 times, most recently from 0d68d43 to 6de2898 Compare November 10, 2022 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import-sorting (a ruff approximation of isort)
1 participant