From f01485f9841bddc70b64e113de91f36d4ac6f231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maksymilian=20P=C5=82ywaczyk?= Date: Thu, 23 Nov 2023 22:11:44 +0100 Subject: [PATCH] Add ruff to pre-commit hooks, create pyproject.toml file for configurate black and ruff linters --- .pre-commit-config.yaml | 15 +++++++++-- pyproject.toml | 59 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c82f7a6..eeeda53 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,15 @@ files: 'api/' repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + rev: v4.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer + exclude: requirements.txt - id: check-yaml - id: check-added-large-files - + - id: detect-private-key + - id: check-merge-conflict - repo: https://github.com/psf/black rev: 22.10.0 hooks: @@ -17,3 +19,12 @@ repos: rev: 5.12.0 hooks: - id: isort + args: ["--profile", "black", "--filter-files"] + +- repo: + https://github.com/charliermarsh/ruff-pre-commit + # Ruff version. + rev: v0.1.2 + hooks: + - id: ruff + args: [ --fix, --exit-non-zero-on-fix ] \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..27a3cb6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,59 @@ +[tool.black] +line-length = 88 +include = '\.pyi?$' +skip-string-normalization = true +exclude = ''' +/( + \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist +)/ +''' +[tool.ruff] +# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. +select = ["E", "F"] +ignore = [] + +# Allow autofix for all enabled rules (when `--fix`) is provided. +fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"] +unfixable = [] + +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", + "alembic/*" +] + +# Same as Black. +line-length = 88 + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +# Assume Python 3.10. +target-version = "py310" \ No newline at end of file