Open3

python linter / formatter with VS Code

hyga2chyga2c

VS Codeでruff + black + mypyを利用する際のメモ

ruff

VS Codeのextention入れておけば pip install ruff or poetry add ruff --group devしなくても利用可能
https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff

black

VS Code Extention 利用にはblackのインストール必要(pip install black or poetry add black --group dev)
https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter

mypy

mypy type cheker+Pylanceを入れておけば型ヒント関係はおおよそカバーできるはず。
https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker
https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance

hyga2chyga2c

setup.json 暫定

    "[python]": {
        "editor.codeActionsOnSave": {
            "source.fixAll": true,
            "source.organizeImports": true
        },
        "editor.defaultFormatter": "ms-python.black-formatter"
    },
    "python.analysis.typeCheckingMode": "basic",
    "python.languageServer": "Pylance",
hyga2chyga2c

pyproject.toml 暫定

[tool.ruff]
select = [
    "E",   # pycodestyle
    "F",   # pyflakes
    "D",   # pydocstyle
    "B",   # bugbear
    "Q",   # mypy
    "W",   # pycodestyle-warnings
    "N",   # pep8-naming
    "SIM", # flake8-simplify
    "TRY", # flake8-try
    "RUF", # flake8-ruff
    "I",   # isort
]
ignore = ["D400", "D415", "D100"]

unfixable = [
    "B",
    "SIM",  # flake8-simplify
    "TRY",  # flake8-try
    "RUF",  # flake8-ruff
    "F841", # local variable is assigned to but never used
    "F401", # imported but unused
]

line-length = 88 # Same as Black.

target-version = "py310" # Assume Python 3.10.

[tool.ruff.pydocstyle]
convention = "numpy"