Skip to content

Instantly share code, notes, and snippets.

@MaxymVlasov
Last active January 5, 2024 10:40
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save MaxymVlasov/da500c2b402dfea886e432234faff120 to your computer and use it in GitHub Desktop.
Save MaxymVlasov/da500c2b402dfea886e432234faff120 to your computer and use it in GitHub Desktop.
# How to install:
# pre-commit install --install-hooks && pre-commit install --install-hooks -t commit-msg
# How temporary skip one of hooks: https://pre-commit.com/#temporarily-disabling-hooks
repos:
#######
# ALL #
#######
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
# Git style
- id: check-added-large-files
- id: check-merge-conflict
- id: check-vcs-permalinks
- id: forbid-new-submodules
- id: no-commit-to-branch
# Common errors
- id: check-yaml
args: [--allow-multiple-documents]
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: check-executables-have-shebangs
# Cross platform
- id: check-case-conflict
- id: mixed-line-ending
args: [--fix=lf]
# Security
- id: detect-aws-credentials
args: ['--allow-missing-credentials']
- id: detect-private-key
# Git style
# You can simplify this process, installing commitizen globally and then add alias:
# sudo pip3 install -U Commitizen
# gcz='cz commit'
# https://github.com/commitizen-tools/commitizen#installation
- repo: https://github.com/commitizen-tools/commitizen
rev: master
hooks:
- id: commitizen
stages: [commit-msg]
- repo: https://github.com/milin/giticket
rev: '868d937'
hooks:
- id: giticket
args: ['--format={ticket}: {commit_msg}']
- repo: https://github.com/jorisroovers/gitlint
rev: v0.12.0
hooks:
- id: gitlint
# More security
- repo: https://github.com/mattlqx/pre-commit-sign
rev: v1.1.1
hooks:
- id: sign-commit
#############
# TERRAFORM #
#############
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.31.0
hooks:
- id: terraform_fmt
- id: terraform_docs
- id: terraform_validate
##############
# TERRAGRUNT #
##############
- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.12
hooks:
- id: terragrunt-hclfmt
########
# CHEF #
########
# - repo: https://github.com/belminf/pre-commit-chef # Need installed 'gem'. sudo apt install ruby. And then fail
# rev: v0.1.1
# hooks:
# - id: cookstyle
# - id: foodcritic
# args:
# - --tags ~chef15
# - --epic-fail chef14
- repo: https://github.com/mattlqx/pre-commit-ruby
rev: v1.2.6
hooks:
- id: rubocop
- id: foodcritic
- id: rspec
- id: chef-cookbook-version
- repo: https://github.com/pre-commit/mirrors-ruby-lint # Need installed 'gem'. sudo apt install ruby
rev: v2.3.1-1
hooks:
- id: ruby-lint
##########
# PYTHON #
##########
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.2.0
hooks:
- id: reorder-python-imports
language_version: python3
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.0.1
hooks:
- id: add-trailing-comma
language_version: python3
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.2
hooks:
- id: autopep8
language_version: python3
args:
- -i
- --max-line-length=100
# Usage: http://pylint.pycqa.org/en/latest/user_guide/message-control.html
- repo: https://github.com/PyCQA/pylint
rev: pylint-2.5.2
hooks:
- id: pylint
language_version: python3
args:
- --disable=import-error # E0401. Locally you could not have all imports.
- --disable=fixme # W0511. 'TODO' notations.
- --disable=bad-continuation # Will be removed in pylint-2.6.0. Use wemake-python-styleguide.
- --disable=logging-fstring-interpolation # Conflict with "use a single formatting" WPS323
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.770
hooks:
- id: mypy
language_version: python3
args: [
--ignore-missing-imports,
--disallow-untyped-calls,
--warn-redundant-casts,
]
- repo: https://gitlab.com/pycqa/flake8.git
rev: 3.8.2
hooks:
- id: flake8
language_version: python3
additional_dependencies:
- flake8-2020
- flake8-docstrings
- flake8-pytest-style
- wemake-python-styleguide
args:
- --max-returns=2 # Default settings
- --max-arguments=4 # Default settings
# https://www.flake8rules.com/
# https://wemake-python-stylegui.de/en/latest/pages/usage/violations/index.html
- --extend-ignore=
WPS305, <!-- Found `f` string -->
E501, <!-- line too long (> 79 characters). Use 100 -->
I, <!-- opt out of using isort in favor of reorder-python-imports -->
RST, <!-- Conflict with DAR -->
#########
# SHELL # (AND OTHER)
#########
# - repo: https://github.com/jumanjihouse/pre-commit-hooks
# rev: 2.1.6
# hooks:
# - id: git-check # Configure in .gitattributes
# - id: git-dirty # Configure in .gitignore
# - id: markdownlint # Configure in .mdlrc
# - id: require-ascii
# - id: script-must-have-extension
# - id: script-must-not-have-extension
# - id: shellcheck
# - id: shfmt
# args: ['-l', '-i', '2', '-ci', '-sr', '-w']
# exclude: |
# (?x)
# # Comment
# (path/to/file/one
# # Comment 2
# |another/file.sh
# )
- repo: git://github.com/detailyang/pre-commit-shell
rev: v1.0.6
hooks:
- id: shell-lint
args: [--format=json]
- repo: https://github.com/syntaqx/git-hooks
rev: v0.0.17
hooks:
- id: forbid-binary
- id: shellcheck
- id: shfmt
- repo: https://github.com/openstack/bashate
rev: 2.0.0
hooks:
- id: bashate
language_version: python3
args:
- --max-line-length=100
@MaxymVlasov
Copy link
Author

MaxymVlasov commented Aug 10, 2019

Install pre-commit hooks globally

DIR=~/.git-template
git config --global init.templateDir ${DIR}
pre-commit init-templatedir -t pre-commit ${DIR}
pre-commit init-templatedir -t commit-msg ${DIR}

=====

Starting from pre-commit > 0.18.3 (now have no tag, pip install git+) can be used next installation syntax:

pre-commit install --install-hooks -t pre-commit -t commit-msg

via pre-commit/pre-commit#1139

@MaxymVlasov
Copy link
Author

MaxymVlasov commented Aug 10, 2019

Universal hooks for Terraform

# See more at https://tinyurl.com/pre-commit-config

repos:
#######
# ALL #
#######
- repo: git://github.com/pre-commit/pre-commit-hooks
  rev: v2.5.0
  hooks:
    # Git style
    - id: check-added-large-files
    - id: check-merge-conflict
    - id: check-vcs-permalinks
    - id: forbid-new-submodules
    - id: no-commit-to-branch

    # Common errors
    - id: end-of-file-fixer
    - id: trailing-whitespace
      args: [--markdown-linebreak-ext=md]

    # Cross platform
    - id: check-case-conflict

    # Security
    - id: detect-aws-credentials
      args: ['--allow-missing-credentials']
    - id: detect-private-key


#############
# TERRAFORM #
#############
- repo: git://github.com/antonbabenko/pre-commit-terraform
  rev: v1.31.0
  hooks:
    - id: terraform_fmt
    - id: terraform_docs
    - id: terraform_validate

@MaxymVlasov
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment