seri::diary

日常

メモ: いつも忘れるPython + uv + ruffのVSCodeの設定2025年9月版

いつも忘れてどっかからコピペしているのでメモしておく.Ruffを使うようになってfomatter/linterの設定がめちゃくちゃ楽になってほんと助かる.

VSCodeのsettings.json

Formatter

{
  "[python]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.fixAll.ruff": "always",
      "source.organizeImports.ruff": "always"
    },
    "editor.defaultFormatter": "charliermarsh.ruff"
  },
  "editor.formatOnSave": true,
  "editor.formatOnSaveMode": "file"
}

Ruffの設定

[tool.ruff]
lint.select = [
    "F", # Flake8
    "B", # Black
    "I", # isort
    "E", # error
    "W",  # warning
    "UP",
]
lint.ignore = []
lint.fixable = ["ALL"]
exclude = [
    ".ruff_cache",
    ".venv"
]
line-length = 120
indent-width = 4
target-version = "py313"

[tool.ruff.format]
quote-style = "single"