You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This could be by design, but I did not find a specific answer to the following question in the issues here. So I thought I'd ask.
Is there any option to force import sorting in ruff format in below's example? I am aware that ruff test.py --fix would solve this, but to me, this seems like an unnecessary second step. (Using a lsp integration this could mean a manual intervention when it could also be used in an on-save-hook, for example.) Am I maybe missing something in the conflicting lint rules?
Good question -- we have an open issue to document this better (#8367).
Right now, import sorting is part of the linter (ruff check and ruff check --fix) rather than the formatter ruff format). At present, the formatter doesn't do any import sorting -- just formatting. So it won't reorder and collapse imports. This is both for historical reasons and because unlike the rest of the formatter, it requires changing the AST and so (possibly) the behavior of your code.
More practically, what this means is that import sorting is performed via ruff check and ruff check --fix rather than ruff format. With the above configuration, ruff check --fix should give you isort-like import sorting, while ruff format will handle general code formatting.
Thank you for the prompt and helpful reply. This totally makes sense. Excuse me missing the issue and thanks for linking it.
I will just set up my on save hooks to run ruff check --select "I" --fix for the file in addition to a ruff format. Works fine for me. (I have to make use of Emacs' customizability in some way 😉 ). Maybe this help someone else finding this in the future.
This could be by design, but I did not find a specific answer to the following question in the issues here. So I thought I'd ask.
Is there any option to force import sorting in
ruff format
in below's example? I am aware thatruff test.py --fix
would solve this, but to me, this seems like an unnecessary second step. (Using alsp
integration this could mean a manual intervention when it could also be used in an on-save-hook, for example.) Am I maybe missing something in the conflicting lint rules?Given the following MWE:
we can see
ruff
will check for sorted inputs:Yet,
ruff format
will not sort importsisort
-style:$ ruff format test.py # 1 file left unchanged
This would be the expected outcome:
The text was updated successfully, but these errors were encountered: