blob: 8d21a68353146b9439cac1bd51a91adb6f67e7e2 [file] [log] [blame] [view]
Anthony Sottilebe8b2962014-03-22 18:40:47 -07001[![Build Status](https://travis-ci.org/pre-commit/pre-commit-hooks.svg?branch=master)](https://travis-ci.org/pre-commit/pre-commit-hooks)
Anthony Sottile46251c92017-02-01 08:30:58 -08002[![Coverage Status](https://coveralls.io/repos/github/pre-commit/pre-commit-hooks/badge.svg?branch=master)](https://coveralls.io/github/pre-commit/pre-commit-hooks?branch=master)
Anthony Sottile9d1ac322015-02-27 07:58:59 -08003[![Build status](https://ci.appveyor.com/api/projects/status/dfcpng35u4g0r0t1/branch/master?svg=true)](https://ci.appveyor.com/project/asottile/pre-commit-hooks/branch/master)
Anthony Sottilebe8b2962014-03-22 18:40:47 -07004
Anthony Sottile27291ff2014-03-13 08:41:35 -07005pre-commit-hooks
6==========
7
8Some out-of-the-box hooks for pre-commit.
9
Anthony Sottilecd74dc12014-03-13 09:26:06 -070010See also: https://github.com/pre-commit/pre-commit
Anthony Sottile24609de2014-06-18 06:47:14 -070011
12
13### Using pre-commit-hooks with pre-commit
14
15Add this to your `.pre-commit-config.yaml`
16
17 - repo: git://github.com/pre-commit/pre-commit-hooks
Anthony Sottile92e15702018-02-28 09:14:40 -080018 sha: v1.2.3 # Use the ref you want to point at
Anthony Sottile24609de2014-06-18 06:47:14 -070019 hooks:
20 - id: trailing-whitespace
21 # - id: ...
22
23
24### Hooks available
25
Alexander Dupuya6023ac2015-05-10 10:00:54 +020026- `autopep8-wrapper` - Runs autopep8 over python source.
Anthony Sottile44fbe612015-10-18 12:36:14 -070027 - Ignore PEP 8 violation types with `args: ['-i', '--ignore=E000,...']` or
Anthony Sottileef7c4252017-03-13 14:32:43 -070028 through configuration of the `[pycodestyle]` section in
29 setup.cfg / tox.ini.
Anthony Sottile53f1dc02015-01-04 13:06:21 -080030- `check-added-large-files` - Prevent giant files from being committed.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020031 - Specify what is "too large" with `args: ['--maxkb=123']` (default=500kB).
Anthony Sottile1f262da2017-12-04 17:28:46 -080032 - If `git-lfs` is installed, lfs files will be skipped
33 (requires `git-lfs>=2.2.1`)
Anthony Sottile8a8aaf52015-08-04 13:45:41 -070034- `check-ast` - Simply check whether files parse as valid python.
Ben Webber35996b72017-11-26 00:17:47 +000035- `check-builtin-literals` - Require literal syntax when initializing empty or zero Python builtin types.
36 - Allows calling constructors with positional arguments (e.g., `list('abc')`).
Ben Webber77586762017-11-30 18:27:16 +000037 - Allows calling constructors from the `builtins` (`__builtin__`) namespace (`builtins.list()`).
Ben Webber35996b72017-11-26 00:17:47 +000038 - Ignore this requirement for specific builtin types with `--ignore=type1,type2,…`.
39 - Forbid `dict` keyword syntax with `--no-allow-dict-kwargs`.
Anthony Sottilefe9c4042016-03-18 10:59:31 -070040- `check-byte-order-marker` - Forbid files which have a UTF-8 byte-order marker
Alexander Dupuya6023ac2015-05-10 10:00:54 +020041- `check-case-conflict` - Check for files with names that would conflict on a
42 case-insensitive filesystem like MacOS HFS+ or Windows FAT.
43- `check-docstring-first` - Checks for a common error of placing code before
44 the docstring.
Chris Kuehl13991f02017-07-02 21:00:28 -070045- `check-executables-have-shebangs` - Checks that non-binary executables have a
46 proper shebang.
Anthony Sottile48294fb2014-08-19 17:33:08 -070047- `check-json` - Attempts to load all json files to verify syntax.
Guy Kisel779a4292015-03-13 16:30:14 -070048- `check-merge-conflict` - Check for files that contain merge conflict strings.
Anthony Sottile64943e82016-01-15 07:47:33 -080049- `check-symlinks` - Checks for symlinks which do not point to anything.
Anthony Sottile9db0a742017-10-06 23:32:11 -070050- `check-vcs-permalinks` - Ensures that links to vcs websites are permalinks.
Anthony Sottileddc92082015-01-17 10:21:44 -080051- `check-xml` - Attempts to load all xml files to verify syntax.
Anthony Sottile24609de2014-06-18 06:47:14 -070052- `check-yaml` - Attempts to load all yaml files to verify syntax.
Anthony Sottilee87b81a2017-10-12 15:47:20 -070053 - `--allow-multiple-documents` - allow yaml files which use the
54 [multi-document syntax](http://www.yaml.org/spec/1.2/spec.html#YAML)
Anthony Sottile24609de2014-06-18 06:47:14 -070055- `debug-statements` - Check for pdb / ipdb / pudb statements in code.
Daniel Roschkab0d4cdb2016-12-30 08:41:24 +010056- `detect-aws-credentials` - Checks for the existence of AWS secrets that you
57 have set up with the AWS CLI.
58 The following arguments are available:
Daniel Roschka53697312016-12-30 16:53:09 +010059 - `--credentials-file` - additional AWS CLI style configuration file in a
Daniel Roschkab0d4cdb2016-12-30 08:41:24 +010060 non-standard location to fetch configured credentials from. Can be repeated
61 multiple times.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020062- `detect-private-key` - Checks for the existence of private keys.
63- `double-quote-string-fixer` - This hook replaces double quoted strings
64 with single quoted strings.
Anthony Sottile24609de2014-06-18 06:47:14 -070065- `end-of-file-fixer` - Makes sure files end in a newline and only a newline.
Anthony Sottile03bf17f2016-04-27 11:18:14 -070066- `fix-encoding-pragma` - Add `# -*- coding: utf-8 -*-` to the top of python files.
67 - To remove the coding pragma pass `--remove` (useful in a python3-only codebase)
Daneebb2e62017-07-27 15:09:31 -070068- `file-contents-sorter` - Sort the lines in specified files (defaults to alphabetical). You must provide list of target files as input to it. Note that this hook WILL remove blank lines and does NOT respect any comments.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020069- `flake8` - Run flake8 on your python files.
Chris Kuehl4b928ab2016-11-30 10:10:29 -080070- `forbid-new-submodules` - Prevent addition of new git submodules.
Morgan Courbetfc8a5b22017-06-13 21:38:14 +020071- `mixed-line-ending` - Replaces or checks mixed line ending.
72 - `--fix={auto,crlf,lf,no}`
73 - `auto` - Replaces automatically the most frequent line ending. This is the default argument.
74 - `crlf`, `lf` - Forces to replace line ending by respectively CRLF and LF.
75 - `no` - Checks if there is any mixed line ending without modifying any file.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020076- `name-tests-test` - Assert that files in tests/ end in `_test.py`.
77 - Use `args: ['--django']` to match `test*.py` instead.
Evan Felixa8592662017-03-20 10:36:51 -070078- `no-commit-to-branch` - Protect specific branches from direct checkins.
79 - Use `args: -b <branch> ` to set the branch. `master` is the default if no argument is set.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020080- `pyflakes` - Run pyflakes on your python files.
Anthony Sottile96fb7fa2016-12-07 10:44:07 -080081- `pretty-format-json` - Checks that all your JSON files are pretty. "Pretty"
82 here means that keys are sorted and indented. You can configure this with
83 the following commandline options:
Anthony Sottileb4a96002016-08-22 14:23:23 -070084 - `--autofix` - automatically format json files
Anthony Sottile96fb7fa2016-12-07 10:44:07 -080085 - `--indent ...` - Control the indentation (either a number for a number of spaces or a string of whitespace). Defaults to 4 spaces.
Anthony Sottileb4a96002016-08-22 14:23:23 -070086 - `--no-sort-keys` - when autofixing, retain the original key ordering (instead of sorting the keys)
Anthony Sottile96fb7fa2016-12-07 10:44:07 -080087 - `--top-keys comma,separated,keys` - Keys to keep at the top of mappings.
Cameron Paulb83ea592014-12-16 12:22:37 -080088- `requirements-txt-fixer` - Sorts entries in requirements.txt
Daniel Gallagherb6eff3d2017-06-23 16:26:00 -070089- `sort-simple-yaml` - Sorts simple YAML files which consist only of top-level keys, preserving comments and blocks.
Anthony Sottile24609de2014-06-18 06:47:14 -070090- `trailing-whitespace` - Trims trailing whitespace.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020091 - Markdown linebreak trailing spaces preserved for `.md` and`.markdown`;
92 use `args: ['--markdown-linebreak-ext=txt,text']` to add other extensions,
93 `args: ['--markdown-linebreak-ext=*']` to preserve them for all files,
94 or `args: ['--no-markdown-linebreak-ext']` to disable and always trim.
Anthony Sottile24609de2014-06-18 06:47:14 -070095
96### As a standalone package
97
98If you'd like to use these hooks, they're also available as a standalone
99package.
100
101Simply `pip install pre-commit-hooks`