Skip to content

Commit

Permalink
update pre-commit to use ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
entorb committed Jan 23, 2024
1 parent b69b769 commit e1971af
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 76 deletions.
104 changes: 28 additions & 76 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -34,15 +42,15 @@ 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
args: ["--remove"]
- 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]
Expand All @@ -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
Expand All @@ -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
28 changes: 28 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e1971af

Please sign in to comment.