ruff isort (I): Sort Imports in CI
Ruff includes an isort-compatible import sorter under the I rule family, fixable with ruff check --fix.
You do not need standalone isort with Ruff; enable the I rules and Ruff both flags and fixes import order.
What it does
The I rule family (I001 unsorted imports, I002 missing required import) checks import ordering and grouping. ruff check --fix rewrites imports into the correct order. The [tool.ruff.lint.isort] table tunes grouping, known-first-party packages, and combining behavior.
Common usage
# enable import sorting
[tool.ruff.lint]
extend-select = ["I"]
[tool.ruff.lint.isort]
known-first-party = ["myapp"]
combine-as-imports = trueConfig keys
| Key | What it does |
|---|---|
| I (rule family) | Enable import sorting checks |
| [tool.ruff.lint.isort] known-first-party | Packages treated as first-party |
| known-third-party | Packages forced into the third-party group |
| combine-as-imports | Merge multiple as-imports from one module |
| force-single-line | One import per line |
In CI
Enable I in config so import order is enforced consistently, and let developers run ruff check --fix to sort. Drop standalone isort from the pipeline to avoid two tools disagreeing about order.
Common errors in CI
I001 "Import block is un-sorted or un-formatted" fails CI when imports are not ordered; ruff check --fix resolves it. Conflicting results between Ruff and a leftover isort step usually trace to different known-first-party settings; configure one tool, not both. If sorting is not enforced, the I family is probably not selected.