blob: 177c4be7e0824776ff7a0fda09a930461ad8a221 [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
Anthony Sottileffcda222018-05-28 10:58:28 -070017 - repo: https://github.com/pre-commit/pre-commit-hooks
Anthony Sottilec8bad492018-12-26 09:48:02 -080018 rev: v2.1.0 # 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
Anthony Sottile53f1dc02015-01-04 13:06:21 -080026- `check-added-large-files` - Prevent giant files from being committed.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020027 - Specify what is "too large" with `args: ['--maxkb=123']` (default=500kB).
Anthony Sottile1f262da2017-12-04 17:28:46 -080028 - If `git-lfs` is installed, lfs files will be skipped
29 (requires `git-lfs>=2.2.1`)
Anthony Sottile8a8aaf52015-08-04 13:45:41 -070030- `check-ast` - Simply check whether files parse as valid python.
Ben Webber35996b72017-11-26 00:17:47 +000031- `check-builtin-literals` - Require literal syntax when initializing empty or zero Python builtin types.
32 - Allows calling constructors with positional arguments (e.g., `list('abc')`).
Ben Webber77586762017-11-30 18:27:16 +000033 - Allows calling constructors from the `builtins` (`__builtin__`) namespace (`builtins.list()`).
Ben Webber35996b72017-11-26 00:17:47 +000034 - Ignore this requirement for specific builtin types with `--ignore=type1,type2,…`.
35 - Forbid `dict` keyword syntax with `--no-allow-dict-kwargs`.
Anthony Sottilefe9c4042016-03-18 10:59:31 -070036- `check-byte-order-marker` - Forbid files which have a UTF-8 byte-order marker
Alexander Dupuya6023ac2015-05-10 10:00:54 +020037- `check-case-conflict` - Check for files with names that would conflict on a
38 case-insensitive filesystem like MacOS HFS+ or Windows FAT.
39- `check-docstring-first` - Checks for a common error of placing code before
40 the docstring.
Chris Kuehl13991f02017-07-02 21:00:28 -070041- `check-executables-have-shebangs` - Checks that non-binary executables have a
42 proper shebang.
Anthony Sottile48294fb2014-08-19 17:33:08 -070043- `check-json` - Attempts to load all json files to verify syntax.
Guy Kisel779a4292015-03-13 16:30:14 -070044- `check-merge-conflict` - Check for files that contain merge conflict strings.
Anthony Sottile64943e82016-01-15 07:47:33 -080045- `check-symlinks` - Checks for symlinks which do not point to anything.
Anthony Sottile9db0a742017-10-06 23:32:11 -070046- `check-vcs-permalinks` - Ensures that links to vcs websites are permalinks.
Anthony Sottileddc92082015-01-17 10:21:44 -080047- `check-xml` - Attempts to load all xml files to verify syntax.
Anthony Sottile24609de2014-06-18 06:47:14 -070048- `check-yaml` - Attempts to load all yaml files to verify syntax.
Anthony Sottilee87b81a2017-10-12 15:47:20 -070049 - `--allow-multiple-documents` - allow yaml files which use the
50 [multi-document syntax](http://www.yaml.org/spec/1.2/spec.html#YAML)
Anthony Sottile1bdd6992018-03-19 10:13:18 -070051 - `--unsafe` - Instead of loading the files, simply parse them for syntax.
Anthony Sottilea21def32018-03-19 09:28:18 -070052 A syntax-only check enables extensions and unsafe constructs which would
53 otherwise be forbidden. Using this option removes all guarantees of
54 portability to other yaml implementations.
55 Implies `--allow-multiple-documents`.
Anthony Sottile805530f2018-05-14 09:16:37 -070056- `debug-statements` - Check for debugger imports and py37+ `breakpoint()`
57 calls in python source.
Daniel Roschkab0d4cdb2016-12-30 08:41:24 +010058- `detect-aws-credentials` - Checks for the existence of AWS secrets that you
59 have set up with the AWS CLI.
60 The following arguments are available:
Ryan Delaney2d4833c2018-10-28 15:58:14 -070061 - `--credentials-file CREDENTIALS_FILE` - additional AWS CLI style
Ryan Delaney4b8eb6f2018-10-28 12:07:03 -070062 configuration file in a non-standard location to fetch configured
63 credentials from. Can be repeated multiple times.
Ryan Delaneyefc5b9e2018-10-28 12:05:42 -070064 - `--allow-missing-credentials` - Allow hook to pass when no credentials are
65 detected.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020066- `detect-private-key` - Checks for the existence of private keys.
67- `double-quote-string-fixer` - This hook replaces double quoted strings
68 with single quoted strings.
Anthony Sottile24609de2014-06-18 06:47:14 -070069- `end-of-file-fixer` - Makes sure files end in a newline and only a newline.
Anthony Sottile03bf17f2016-04-27 11:18:14 -070070- `fix-encoding-pragma` - Add `# -*- coding: utf-8 -*-` to the top of python files.
71 - To remove the coding pragma pass `--remove` (useful in a python3-only codebase)
Daneebb2e62017-07-27 15:09:31 -070072- `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 +020073- `flake8` - Run flake8 on your python files.
Chris Kuehl4b928ab2016-11-30 10:10:29 -080074- `forbid-new-submodules` - Prevent addition of new git submodules.
Morgan Courbetfc8a5b22017-06-13 21:38:14 +020075- `mixed-line-ending` - Replaces or checks mixed line ending.
76 - `--fix={auto,crlf,lf,no}`
77 - `auto` - Replaces automatically the most frequent line ending. This is the default argument.
78 - `crlf`, `lf` - Forces to replace line ending by respectively CRLF and LF.
79 - `no` - Checks if there is any mixed line ending without modifying any file.
Alexander Dupuya6023ac2015-05-10 10:00:54 +020080- `name-tests-test` - Assert that files in tests/ end in `_test.py`.
81 - Use `args: ['--django']` to match `test*.py` instead.
Evan Felixa8592662017-03-20 10:36:51 -070082- `no-commit-to-branch` - Protect specific branches from direct checkins.
Anthony Sottile3aa6c642018-10-10 11:15:13 -070083 - Use `args: [--branch, staging, --branch, master]` to set the branch.
84 `master` is the default if no argument is set.
Anthony Sottilebaec3082018-06-09 11:16:14 -070085 - `-b` / `--branch` may be specified multiple times to protect multiple
86 branches.
Anthony Sottile96fb7fa2016-12-07 10:44:07 -080087- `pretty-format-json` - Checks that all your JSON files are pretty. "Pretty"
88 here means that keys are sorted and indented. You can configure this with
89 the following commandline options:
Anthony Sottileb4a96002016-08-22 14:23:23 -070090 - `--autofix` - automatically format json files
Anthony Sottile96fb7fa2016-12-07 10:44:07 -080091 - `--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 -070092 - `--no-sort-keys` - when autofixing, retain the original key ordering (instead of sorting the keys)
Anthony Sottile96fb7fa2016-12-07 10:44:07 -080093 - `--top-keys comma,separated,keys` - Keys to keep at the top of mappings.
Michał Sochoń9e28aaf2018-03-26 00:02:23 +020094- `requirements-txt-fixer` - Sorts entries in requirements.txt and removes incorrect entry for `pkg-resources==0.0.0`
Daniel Gallagherb6eff3d2017-06-23 16:26:00 -070095- `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 -070096- `trailing-whitespace` - Trims trailing whitespace.
Anthony Sottile99453a52018-10-12 18:10:02 -070097 - To preserve Markdown [hard linebreaks](https://github.github.com/gfm/#hard-line-break)
98 use `args: [--markdown-linebreak-ext=md]` (or other extensions used
99 by your markdownfiles). If for some reason you want to treat all files
100 as markdown, use `--markdown-linebreak-ext=*`.
Anthony Sottile24609de2014-06-18 06:47:14 -0700101
Anthony Sottile526904b2018-10-11 17:19:35 -0700102### Deprecated / replaced hooks
103
104- `autopep8-wrapper`: instead use
105 [mirrors-autopep8](https://github.com/pre-commit/mirrors-autopep8)
106- `pyflakes`: instead use `flake8`
107
Anthony Sottile24609de2014-06-18 06:47:14 -0700108### As a standalone package
109
110If you'd like to use these hooks, they're also available as a standalone
111package.
112
113Simply `pip install pre-commit-hooks`