Skip to content

Instantly share code, notes, and snippets.

@saravanabalagi
Last active March 6, 2024 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saravanabalagi/7f2e7bbbe84b763eeffc17dcc906d25e to your computer and use it in GitHub Desktop.
Save saravanabalagi/7f2e7bbbe84b763eeffc17dcc906d25e to your computer and use it in GitHub Desktop.
Ruff all rules with description
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
hooks:
- id: nbstripout

Add config

  • Add the above files pyproject.toml and .pre-commit-config.yaml at the root of your repo
  • Add ruff and pre-commit dependencies
poetry add --group dev ruff
poetry add --group dev pre-commit
  • On commit, actions will be auto-triggered
  • Before commit, you can verify if things work as expected using
ruff check .                 # run ruff linter alone
ruff format .                # run ruff formatter alone
  • Add to ignore list if you don't need a certain rule
  • Check how all actions would run altogether on commit using
pre-commit run --all-files       # manually run all precommit actions on all files
pre-commit run --files=$FILES    # specify files to run
pre-commit run --all-files ruff  # run only ruff

When you clone

Make sure to run pre-commit install right after you clone

git clone your_awesome_python_repo

# Setup dependencies
poetry install

# Setup pre-commit hooks
pre-commit install
[tool.ruff.lint]
# for more info check
# https://docs.astral.sh/ruff/rules
select = [
"F", # Pyflakes
"E", # pycodestyle errors
"W", # pycodestyle warnings
"C90", # McCabe complexity
"I", # isort
"D", # pydocstyle
"UP", # pyupgrade
"YTT", # flake8-2020
"ANN", # flake8-annotations
"ASYNC", # flake8-async
"TRIO", # flake8-trio
"S", # flake8-bandit
"BLE", # flake8-blind-except
"FBT", # flake8-boolean-trap
"B", # flake8-bugbear
"A", # flake8-builtins
"COM", # flake8-commas
"CPY", # flake8-copyright
"C4", # flake8-comprehensions
"DTZ", # flake8-datetimez
"T10", # flake8-debugger
"DJ", # flake8-django
"EM", # flake8-errmsg
"EXE", # flake8-executable
"FA", # flake8-future-annotations
"ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"INP", # flake8-no-pep420
"PIE", # flake8-pie
"T20", # flake8-print
"PYI", # flake8-pyi
"PT", # flake8-pytest-style
"Q", # flake8-quotes
"RSE", # flake8-raise
"RET", # flake8-return
"SLF", # flake8-self
"SLOT", # flake8-slots
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"INT", # flake8-gettext
"ARG", # flake8-unused-arguments
"PTH", # flake8-use-pathlib
"TD", # flake8-todos
"FIX", # flake8-fixme
"ERA", # eradicate
"PD", # pandas-vet
"PGH", # pygrep-hooks
"PL", # Pylint
"TRY", # tryceratops
"FLY", # flynt
"NPY", # NumPy-specific rules
"AIR", # Airflow
"PERF", # Perflint
"FURB", # refurb
"LOG", # flake8-logging
"RUF", # Ruff-specific rules
]
ignore = [
# add ignored rules as desired
# "FBT002" # boolean-default-value-positional-argument
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment