Anthony Sottile | be8b296 | 2014-03-22 18:40:47 -0700 | [diff] [blame] | 1 | [](https://travis-ci.org/pre-commit/pre-commit-hooks) |
Anthony Sottile | 46251c9 | 2017-02-01 08:30:58 -0800 | [diff] [blame] | 2 | [](https://coveralls.io/github/pre-commit/pre-commit-hooks?branch=master) |
Anthony Sottile | 9d1ac32 | 2015-02-27 07:58:59 -0800 | [diff] [blame] | 3 | [](https://ci.appveyor.com/project/asottile/pre-commit-hooks/branch/master) |
Anthony Sottile | be8b296 | 2014-03-22 18:40:47 -0700 | [diff] [blame] | 4 | |
Anthony Sottile | 27291ff | 2014-03-13 08:41:35 -0700 | [diff] [blame] | 5 | pre-commit-hooks |
| 6 | ========== |
| 7 | |
| 8 | Some out-of-the-box hooks for pre-commit. |
| 9 | |
Anthony Sottile | cd74dc1 | 2014-03-13 09:26:06 -0700 | [diff] [blame] | 10 | See also: https://github.com/pre-commit/pre-commit |
Anthony Sottile | 24609de | 2014-06-18 06:47:14 -0700 | [diff] [blame] | 11 | |
| 12 | |
| 13 | ### Using pre-commit-hooks with pre-commit |
| 14 | |
| 15 | Add this to your `.pre-commit-config.yaml` |
| 16 | |
| 17 | - repo: git://github.com/pre-commit/pre-commit-hooks |
Anthony Sottile | 92e1570 | 2018-02-28 09:14:40 -0800 | [diff] [blame^] | 18 | sha: v1.2.3 # Use the ref you want to point at |
Anthony Sottile | 24609de | 2014-06-18 06:47:14 -0700 | [diff] [blame] | 19 | hooks: |
| 20 | - id: trailing-whitespace |
| 21 | # - id: ... |
| 22 | |
| 23 | |
| 24 | ### Hooks available |
| 25 | |
Alexander Dupuy | a6023ac | 2015-05-10 10:00:54 +0200 | [diff] [blame] | 26 | - `autopep8-wrapper` - Runs autopep8 over python source. |
Anthony Sottile | 44fbe61 | 2015-10-18 12:36:14 -0700 | [diff] [blame] | 27 | - Ignore PEP 8 violation types with `args: ['-i', '--ignore=E000,...']` or |
Anthony Sottile | ef7c425 | 2017-03-13 14:32:43 -0700 | [diff] [blame] | 28 | through configuration of the `[pycodestyle]` section in |
| 29 | setup.cfg / tox.ini. |
Anthony Sottile | 53f1dc0 | 2015-01-04 13:06:21 -0800 | [diff] [blame] | 30 | - `check-added-large-files` - Prevent giant files from being committed. |
Alexander Dupuy | a6023ac | 2015-05-10 10:00:54 +0200 | [diff] [blame] | 31 | - Specify what is "too large" with `args: ['--maxkb=123']` (default=500kB). |
Anthony Sottile | 1f262da | 2017-12-04 17:28:46 -0800 | [diff] [blame] | 32 | - If `git-lfs` is installed, lfs files will be skipped |
| 33 | (requires `git-lfs>=2.2.1`) |
Anthony Sottile | 8a8aaf5 | 2015-08-04 13:45:41 -0700 | [diff] [blame] | 34 | - `check-ast` - Simply check whether files parse as valid python. |
Ben Webber | 35996b7 | 2017-11-26 00:17:47 +0000 | [diff] [blame] | 35 | - `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 Webber | 7758676 | 2017-11-30 18:27:16 +0000 | [diff] [blame] | 37 | - Allows calling constructors from the `builtins` (`__builtin__`) namespace (`builtins.list()`). |
Ben Webber | 35996b7 | 2017-11-26 00:17:47 +0000 | [diff] [blame] | 38 | - Ignore this requirement for specific builtin types with `--ignore=type1,type2,…`. |
| 39 | - Forbid `dict` keyword syntax with `--no-allow-dict-kwargs`. |
Anthony Sottile | fe9c404 | 2016-03-18 10:59:31 -0700 | [diff] [blame] | 40 | - `check-byte-order-marker` - Forbid files which have a UTF-8 byte-order marker |
Alexander Dupuy | a6023ac | 2015-05-10 10:00:54 +0200 | [diff] [blame] | 41 | - `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 Kuehl | 13991f0 | 2017-07-02 21:00:28 -0700 | [diff] [blame] | 45 | - `check-executables-have-shebangs` - Checks that non-binary executables have a |
| 46 | proper shebang. |
Anthony Sottile | 48294fb | 2014-08-19 17:33:08 -0700 | [diff] [blame] | 47 | - `check-json` - Attempts to load all json files to verify syntax. |
Guy Kisel | 779a429 | 2015-03-13 16:30:14 -0700 | [diff] [blame] | 48 | - `check-merge-conflict` - Check for files that contain merge conflict strings. |
Anthony Sottile | 64943e8 | 2016-01-15 07:47:33 -0800 | [diff] [blame] | 49 | - `check-symlinks` - Checks for symlinks which do not point to anything. |
Anthony Sottile | 9db0a74 | 2017-10-06 23:32:11 -0700 | [diff] [blame] | 50 | - `check-vcs-permalinks` - Ensures that links to vcs websites are permalinks. |
Anthony Sottile | ddc9208 | 2015-01-17 10:21:44 -0800 | [diff] [blame] | 51 | - `check-xml` - Attempts to load all xml files to verify syntax. |
Anthony Sottile | 24609de | 2014-06-18 06:47:14 -0700 | [diff] [blame] | 52 | - `check-yaml` - Attempts to load all yaml files to verify syntax. |
Anthony Sottile | e87b81a | 2017-10-12 15:47:20 -0700 | [diff] [blame] | 53 | - `--allow-multiple-documents` - allow yaml files which use the |
| 54 | [multi-document syntax](http://www.yaml.org/spec/1.2/spec.html#YAML) |
Anthony Sottile | 24609de | 2014-06-18 06:47:14 -0700 | [diff] [blame] | 55 | - `debug-statements` - Check for pdb / ipdb / pudb statements in code. |
Daniel Roschka | b0d4cdb | 2016-12-30 08:41:24 +0100 | [diff] [blame] | 56 | - `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 Roschka | 5369731 | 2016-12-30 16:53:09 +0100 | [diff] [blame] | 59 | - `--credentials-file` - additional AWS CLI style configuration file in a |
Daniel Roschka | b0d4cdb | 2016-12-30 08:41:24 +0100 | [diff] [blame] | 60 | non-standard location to fetch configured credentials from. Can be repeated |
| 61 | multiple times. |
Alexander Dupuy | a6023ac | 2015-05-10 10:00:54 +0200 | [diff] [blame] | 62 | - `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 Sottile | 24609de | 2014-06-18 06:47:14 -0700 | [diff] [blame] | 65 | - `end-of-file-fixer` - Makes sure files end in a newline and only a newline. |
Anthony Sottile | 03bf17f | 2016-04-27 11:18:14 -0700 | [diff] [blame] | 66 | - `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) |
Dan | eebb2e6 | 2017-07-27 15:09:31 -0700 | [diff] [blame] | 68 | - `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 Dupuy | a6023ac | 2015-05-10 10:00:54 +0200 | [diff] [blame] | 69 | - `flake8` - Run flake8 on your python files. |
Chris Kuehl | 4b928ab | 2016-11-30 10:10:29 -0800 | [diff] [blame] | 70 | - `forbid-new-submodules` - Prevent addition of new git submodules. |
Morgan Courbet | fc8a5b2 | 2017-06-13 21:38:14 +0200 | [diff] [blame] | 71 | - `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 Dupuy | a6023ac | 2015-05-10 10:00:54 +0200 | [diff] [blame] | 76 | - `name-tests-test` - Assert that files in tests/ end in `_test.py`. |
| 77 | - Use `args: ['--django']` to match `test*.py` instead. |
Evan Felix | a859266 | 2017-03-20 10:36:51 -0700 | [diff] [blame] | 78 | - `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 Dupuy | a6023ac | 2015-05-10 10:00:54 +0200 | [diff] [blame] | 80 | - `pyflakes` - Run pyflakes on your python files. |
Anthony Sottile | 96fb7fa | 2016-12-07 10:44:07 -0800 | [diff] [blame] | 81 | - `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 Sottile | b4a9600 | 2016-08-22 14:23:23 -0700 | [diff] [blame] | 84 | - `--autofix` - automatically format json files |
Anthony Sottile | 96fb7fa | 2016-12-07 10:44:07 -0800 | [diff] [blame] | 85 | - `--indent ...` - Control the indentation (either a number for a number of spaces or a string of whitespace). Defaults to 4 spaces. |
Anthony Sottile | b4a9600 | 2016-08-22 14:23:23 -0700 | [diff] [blame] | 86 | - `--no-sort-keys` - when autofixing, retain the original key ordering (instead of sorting the keys) |
Anthony Sottile | 96fb7fa | 2016-12-07 10:44:07 -0800 | [diff] [blame] | 87 | - `--top-keys comma,separated,keys` - Keys to keep at the top of mappings. |
Cameron Paul | b83ea59 | 2014-12-16 12:22:37 -0800 | [diff] [blame] | 88 | - `requirements-txt-fixer` - Sorts entries in requirements.txt |
Daniel Gallagher | b6eff3d | 2017-06-23 16:26:00 -0700 | [diff] [blame] | 89 | - `sort-simple-yaml` - Sorts simple YAML files which consist only of top-level keys, preserving comments and blocks. |
Anthony Sottile | 24609de | 2014-06-18 06:47:14 -0700 | [diff] [blame] | 90 | - `trailing-whitespace` - Trims trailing whitespace. |
Alexander Dupuy | a6023ac | 2015-05-10 10:00:54 +0200 | [diff] [blame] | 91 | - 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 Sottile | 24609de | 2014-06-18 06:47:14 -0700 | [diff] [blame] | 95 | |
| 96 | ### As a standalone package |
| 97 | |
| 98 | If you'd like to use these hooks, they're also available as a standalone |
| 99 | package. |
| 100 | |
| 101 | Simply `pip install pre-commit-hooks` |