[note] Python Ruff
基本使用
$ uv add --dev ruff
# ruff format [directory]
$ uvx ruff format app # format app 資料夾
# https://docs.astral.sh/ruff/linter/
# ruff check --select I --fix [directory]
$ uvx ruff check --select I --fix app # 只 fix I 這個 rule
$ uvx ruff check --fix app # 使用所有 select 中有定義的 rule
目前 ruff 的 format 不支援 sorting imports(reference)
Configuration
# pyproject.toml
# https://docs.astral.sh/ruff/settings/
[tool.ruff]
target-version = "py39"
fix = true
line-length = 120
exclude = [
"path_not_want_to_format",
]
[tool.ruff.lint]
# https://docs.astral.sh/ruff/rules/
select = [
"E", # pycodestyle-error
"F", # Pyflakes
"W", # pycodestyle-warning
"I", # isort
"B", # bugbear
"Q" # quotes
]
[tool.ruff.format]
quote-style = "single"