There are many tools for linting and formatting Python codes:
| package | usage |
|---|---|
| isort | sort imports |
| black | format code |
| pylint | lint code |
| pep8 | lint code |
| autoflake | lint code |
| ruff | lint and format code |
Ruff
Basic configuration:
[tool.ruff]
line-length = 120
[tool.ruff.lint]
select = ["E501", "I"]
[tool.ruff.format]
docstring-code-format = true
docstring-code-line-length = 88
Since Ruff format doesn’t support sorting import currently, we need to run the linter to sort import:
ruff check --select I --fix
ruff format