Skip to content

Instantly share code, notes, and snippets.

@martimors
Created March 31, 2022 08:42
Show Gist options
  • Save martimors/e30b5da503f5c02136fff11c22bc42ea to your computer and use it in GitHub Desktop.
Save martimors/e30b5da503f5c02136fff11c22bc42ea to your computer and use it in GitHub Desktop.
Sensible pre-commits to use with Python
# Apply to all files without committing:
# pre-commit run --all-files
# Update this file:
# pre-commit autoupdate
repos:
# format markdown files
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.6.1"
hooks:
- id: prettier
types: [ markdown ]
args: [ "--prose-wrap", "always", "--print-width", "100" ]
# Autofix coding style
- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
# Complain about coding style that black can't fix
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
- flake8-unused-arguments
- flake8-bugbear
- pep8-naming
- flake8-annotations
- flake8-builtins
- flake8-docstrings
- pandas-vet
- darglint
# Sort order of imports
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort
# Check typehints
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.942
hooks:
- id: mypy
args: [--ignore-missing-imports, --show-error-codes]
# Fix coding patterns from old Python versions
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
hooks:
- id: pyupgrade
args: [--py37-plus]
# Misc checks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-json
- id: check-yaml
args: [--allow-multiple-documents]
- id: debug-statements
- id: check-merge-conflict
- id: check-added-large-files
args: ['--maxkb=1000']
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key
# Linting on Dockerfile
- repo: https://github.com/AleksaC/hadolint-py
rev: v2.9.3
hooks:
- id: hadolint
# Check security issues
- repo: https://github.com/PyCQA/bandit
rev: '1.7.4'
hooks:
- id: bandit
args: ["--exclude", "tests"]
# Linting for sql files
- repo: https://github.com/sqlfluff/sqlfluff
rev: 0.11.2
hooks:
- id: sqlfluff-lint
- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle
additional_dependencies:
- toml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment