From f77093abbd8fd9968bbcad11b775de4215451c6c Mon Sep 17 00:00:00 2001 From: Torben <59419684+entorb@users.noreply.github.com> Date: Tue, 23 Jan 2024 20:24:31 +0100 Subject: [PATCH] update pre-commit to use ruff --- .flake8 | 20 -------- .pre-commit-config.yaml | 104 +++++++++++----------------------------- .ruff.toml | 28 +++++++++++ 3 files changed, 56 insertions(+), 96 deletions(-) delete mode 100644 .flake8 create mode 100644 .ruff.toml diff --git a/.flake8 b/.flake8 deleted file mode 100644 index b342fa4..0000000 --- a/.flake8 +++ /dev/null @@ -1,20 +0,0 @@ -[flake8] -max-line-length = 88 - -# CM001 Redundant comment found -# D103 Missing docstring in public function -# D200 One-line docstring should fit on one line with quotes -# D400 First line should end with a period -# E203 black-formatter-specific -# E501 length of line -# E741 ambiguous variable name 'l' -# SIM113 Use enumerate for 'i' -# SCS109 open() vs os.open() -# SCS108 `assert` statements should not be present in production code -# S101 Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. -extend-ignore = CM001 D200 E203 E501 E741 SCS109 SIM113 RST213 SCS108 S101 D103 - -# inline-ignore via comment "noqa: SIM115" etc. - -# asserts (in tests are ok), also allow print() instead of logger -# per-file-ignores = tests/*: SCS108 S101 T201 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 867a765..54f69aa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,17 +3,24 @@ # register as git commit-hook to run automatically # pre-commit install # run manually -# pre-commit run -a +# pre-commit run --all-files # or # pre-commit run --files myFile1.py myFile2.py # update hooks to latest version # pre-commit autoupdate +# ruff replaces flake8 +# ruff-format replaces black, isort, add-trailing-comma + +exclude: | + (?x)^( + .*.vscode/launch.json | + )$ + repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - # see https://github.com/pre-commit/pre-commit-hooks - id: check-added-large-files args: ["--maxkb=500"] - id: check-ast @@ -26,6 +33,7 @@ repos: - id: check-shebang-scripts-are-executable - id: check-symlinks - id: check-toml + - id: check-vcs-permalinks - id: check-xml - id: check-yaml - id: debug-statements @@ -34,8 +42,7 @@ repos: - id: detect-private-key # conflict with black below # - id: double-quote-string-fixer - # not: since it conflicts with python gen. json files - # - id: end-of-file-fixer + - id: end-of-file-fixer - id: file-contents-sorter - id: fix-byte-order-marker - id: fix-encoding-pragma @@ -43,6 +50,7 @@ repos: - id: forbid-new-submodules # - id: forbid-submodules # args: ['--fix=lf'] + - id: mixed-line-ending - id: name-tests-test # - id: no-commit-to-branch # args: [--branch, staging] @@ -53,44 +61,18 @@ repos: # - id: sort-simple-yaml - id: trailing-whitespace - - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.37.0 - hooks: - - id: markdownlint - args: ["--disable", "MD013"] - - # - repo: https://github.com/markdownlint/markdownlint - # rev: v0.12.0 - # hooks: - # - id: markdownlint - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.0.292" + rev: "v0.1.14" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format - - repo: https://github.com/asottile/add-trailing-comma - rev: v3.1.0 - hooks: - - id: add-trailing-comma - - - repo: https://github.com/psf/black - rev: 23.9.1 - hooks: - - id: black - - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.38.0 hooks: - - id: isort - args: ["--profile", "black", "--filter-files"] - - # no, black is enough - # - repo: https://github.com/pre-commit/mirrors-autopep8 - # rev: v2.0.1 - # hooks: - # - id: autopep8 + - id: markdownlint + args: ["--disable", "MD013"] - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.10.0 @@ -107,59 +89,29 @@ repos: - id: rst-inline-touching-normal - id: text-unicode-replacement-char - # problem: collides with black. since it splits multiple 'from imports' - # - repo: https://github.com/asottile/reorder_python_imports - # rev: v3.9.0 - # hooks: - # - id: reorder-python-imports - - repo: https://github.com/asottile/pyupgrade - rev: v3.14.0 + rev: v3.15.0 hooks: - id: pyupgrade args: ["--py310-plus"] - # not for only for projects where type hints have been added + # only for projects where type hints have been added # - repo: https://github.com/pre-commit/mirrors-mypy # rev: v0.991 # hooks: # - id: mypy - - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 - hooks: - - id: flake8 - additional_dependencies: - # NOTE: entries are copy of .flake8-config-file -> for auto-install - # Bugs - - flake8-bugbear - - flake8-secure-coding-standard - - flake8-bandit - - flake8-builtins - - # Clean Code - - flake8-comprehensions - - flake8-simplify - # - flake8-eradicate - - flake8-commas - - # Limitations - - flake8-blind-except - - flake8-logging-format - # - flake8-print - - # Documentation - - flake8-comments - - flake8-docstrings - - flake8-rst-docstrings - - # Test-Improvements - - flake8-assertive - # - repo: https://github.com/codespell-project/codespell # rev: "v2.2.2" # hooks: # - id: codespell + # - repo: https://github.com/henryykt/pre-commit-perl + # rev: v0.0.5 + # hooks: + # # - id: perlcritic + # - id: perltidy + # # - id: perlimports + default_language_version: python: python3.10 diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..e005d71 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,28 @@ +fix = true # auto-fix findings +line-length = 88 # same as Black +target-version = "py310" # Python 3.10 + +select = ["ALL"] # activate all rules +# select = ["E4", "E7", "E9", "F"] # these are the defaults +# extend-select = ["B", "Q", "E", "W"] +extend-ignore = [ + "COM812", # missing-trailing-comma, + "D200", # fits-on-one-line" + "D211", # blank-line-before-class + "D212", # multi-line-summary-second-line + "ERA", # commented-out code + "FIX002", # line-contains-todo + "ISC001", # implicit-str-concat + "PD901", # df name + "PGH003", # blanket-type-ignore + "RET504", # unnecessary-assign + "T201", # print + "TD002", # missing-todo-author + "TD003", # missing-todo-link +] + +[lint] + +[format] +line-ending = "lf" # force lf +preview = false # enable the unstable preview style formatting