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
Here the lib.bar import is identified as 'lib.bar' as Known(FirstParty)
$ ruff check --select I -v --no-cache proj/src/foo.py[2024-11-20][20:28:25][ruff::resolve][DEBUG] Using configuration file (via parent) at: /home/david/projects/bugreport_ruff_toml_dir/pyproject.toml[2024-11-20][20:28:25][ruff_workspace::pyproject][DEBUG] `project.requires_python` in `pyproject.toml` will not be used to set `target_version` when using `ruff.toml`.[2024-11-20][20:28:25][ruff::commands::check][DEBUG] Identified files to lint in: 5.248828ms[2024-11-20][20:28:25][ruff::diagnostics][DEBUG] Checking: /home/david/projects/bugreport_ruff_toml_dir/proj/src/foo.py[2024-11-20][20:28:25][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'banana' as Known(ThirdParty) (NoMatch)[2024-11-20][20:28:25][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'lib.bar' as Known(FirstParty) (SourceMatch("/home/david/projects/bugreport_ruff_toml_dir/proj"))[2024-11-20][20:28:25][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'itertools' as Known(StandardLibrary) (KnownStandardLibrary)[2024-11-20][20:28:25][ruff::commands::check][DEBUG] Checked 1 files in: 1.36171msproj/src/foo.py:1:1: I001 [*] Import block is un-sorted or un-formatted |1 | / import banana2 | | import lib.bar3 | | import itertools | = help: Organize importsFound 1 error.[*] 1 fixable with the `--fix` option.
Thanks for your feedback on your ruff experience. I can see how this can be surprising. The behavior is intentional (not speaking about the linked issue) but probably hard to find. It is explained in the documentation of the src setting.
You can explicitly set the src setting to exclude the lib folder.
Adding an
ruff.toml
to your project file structure affects how ruff finds and categorizes imports, and therefore how rule I001 behaves.version:
ruff 0.7.4
Detailed description
Without ruff.toml
Project structure:
File content:
Here
lib.bar
is identified as'lib.bar' as Known(ThirdParty)
With an empty ruff.toml
Here the
lib.bar
import is identified as'lib.bar' as Known(FirstParty)
Additional wishes
This issue would have been easier to debug if
ruff check -v
also listed:ruff.toml
has been visittedpyproject.toml
has been visitted (even though ignore due to missing ruff section)The text was updated successfully, but these errors were encountered: