blob: 55b49ff18f5d31ead3c71d28d8ac64e0d36047ba [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 Sottile71926652017-07-02 22:27:09 -070018 sha: v0.9.1 # 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 Sottile8a8aaf52015-08-04 13:45:41 -070032- `check-ast` - Simply check whether files parse as valid python.
Anthony Sottilefe9c4042016-03-18 10:59:31 -070033- `check-byte-order-marker` - Forbid files which have a UTF-8 byte-order marker
Alexander Dupuya6023ac2015-05-10 10:00:54 +020034- `check-case-conflict` - Check for files with names that would conflict on a
35 case-insensitive filesystem like MacOS HFS+ or Windows FAT.
36- `check-docstring-first` - Checks for a common error of placing code before
37 the docstring.
Chris Kuehl13991f02017-07-02 21:00:28 -070038- `check-executables-have-shebangs` - Checks that non-binary executables have a
39 proper shebang.
Anthony Sottile48294fb2014-08-19 17:33:08 -070040- `check-json` - Attempts to load all json files to verify syntax.
Guy Kisel779a4292015-03-13 16:30:14 -070041- `check-merge-conflict` - Check for files that contain merge conflict strings.
Anthony Sottile64943e82016-01-15 07:47:33 -080042- `check-symlinks` - Checks for symlinks which do not point to anything.
Anthony Sottileddc92082015-01-17 10:21:44 -080043- `check-xml` - Attempts to load all xml files to verify syntax.
Anthony Sottile24609de2014-06-18 06:47:14 -070044- `check-yaml` - Attempts to load all yaml files to verify syntax.
45- `debug-statements` - Check for pdb / ipdb / pudb statements in code.
Daniel Roschkab0d4cdb2016-12-30 08:41:24 +010046- `detect-aws-credentials` - Checks for the existence of AWS secrets that you
47 have set up with the AWS CLI.
48 The following arguments are available:
Daniel Roschka53697312016-12-30 16:53:09 +010049 - `--credentials-file` - additional AWS CLI style configuration file in a
Daniel Roschkab0d4cdb2016-12-30 08:41:24 +010050 non-standard location to fetch configured credentials from. Can be repeated
51 multiple times.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020052- `detect-private-key` - Checks for the existence of private keys.
53- `double-quote-string-fixer` - This hook replaces double quoted strings
54 with single quoted strings.
Anthony Sottile24609de2014-06-18 06:47:14 -070055- `end-of-file-fixer` - Makes sure files end in a newline and only a newline.
Anthony Sottile03bf17f2016-04-27 11:18:14 -070056- `fix-encoding-pragma` - Add `# -*- coding: utf-8 -*-` to the top of python files.
Daniel Gallagher5dd18192017-06-25 15:37:58 -070057- `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.
Anthony Sottile03bf17f2016-04-27 11:18:14 -070058 - To remove the coding pragma pass `--remove` (useful in a python3-only codebase)
Alexander Dupuya6023ac2015-05-10 10:00:54 +020059- `flake8` - Run flake8 on your python files.
Chris Kuehl4b928ab2016-11-30 10:10:29 -080060- `forbid-new-submodules` - Prevent addition of new git submodules.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020061- `name-tests-test` - Assert that files in tests/ end in `_test.py`.
62 - Use `args: ['--django']` to match `test*.py` instead.
Evan Felixa8592662017-03-20 10:36:51 -070063- `no-commit-to-branch` - Protect specific branches from direct checkins.
64 - Use `args: -b <branch> ` to set the branch. `master` is the default if no argument is set.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020065- `pyflakes` - Run pyflakes on your python files.
Anthony Sottile96fb7fa2016-12-07 10:44:07 -080066- `pretty-format-json` - Checks that all your JSON files are pretty. "Pretty"
67 here means that keys are sorted and indented. You can configure this with
68 the following commandline options:
Anthony Sottileb4a96002016-08-22 14:23:23 -070069 - `--autofix` - automatically format json files
Anthony Sottile96fb7fa2016-12-07 10:44:07 -080070 - `--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 -070071 - `--no-sort-keys` - when autofixing, retain the original key ordering (instead of sorting the keys)
Anthony Sottile96fb7fa2016-12-07 10:44:07 -080072 - `--top-keys comma,separated,keys` - Keys to keep at the top of mappings.
Cameron Paulb83ea592014-12-16 12:22:37 -080073- `requirements-txt-fixer` - Sorts entries in requirements.txt
Daniel Gallagherb6eff3d2017-06-23 16:26:00 -070074- `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 -070075- `trailing-whitespace` - Trims trailing whitespace.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020076 - Markdown linebreak trailing spaces preserved for `.md` and`.markdown`;
77 use `args: ['--markdown-linebreak-ext=txt,text']` to add other extensions,
78 `args: ['--markdown-linebreak-ext=*']` to preserve them for all files,
79 or `args: ['--no-markdown-linebreak-ext']` to disable and always trim.
Anthony Sottile24609de2014-06-18 06:47:14 -070080
81### As a standalone package
82
83If you'd like to use these hooks, they're also available as a standalone
84package.
85
86Simply `pip install pre-commit-hooks`