Skip to content

Commit

Permalink
Fixed #32165 -- Added pre-commit hooks
Browse files Browse the repository at this point in the history
* Added pre-commit hooks for isort, flake8 and eslint
* Added documentation on how to install and use the tool
  • Loading branch information
smithdc1 authored and carltongibson committed Dec 23, 2020
1 parent 3a0ed0c commit 3bca95c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.6.4
hooks:
- id: isort
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v7.16.0
hooks:
- id: eslint
26 changes: 26 additions & 0 deletions docs/internals/contributing/writing-code/coding-style.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ Coding style

Please follow these coding standards when writing code for inclusion in Django.

.. _coding-style-pre-commit:

Pre-commit checks
=================

`pre-commit <https://pre-commit.com>`_ is a framework for managing pre-commit
hooks. These hooks help to identify simple issues before committing code for
review. By checking for these issues before code review it allows the reviewer
to focus on the change itself, and it can also help to reduce the number CI
runs.

To use the tool, first install ``pre-commit`` and then the git hooks::

.. console::

$ pip install pre-commit
$ pre-commit install

On the first commit ``pre-commit`` will install the hooks, these are
installed in their own environments and will take a short while to
install on the first run. Subsequent checks will be significantly faster.
If the an error is found an appropriate error message will be displayed.
If the error was with ``isort`` then the tool will go ahead and fix them for
you. Review the changes and re-stage for commit if you are happy with
them.

.. _coding-style-python:

Python style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ All code changes

* Does the :doc:`coding style
</internals/contributing/writing-code/coding-style>` conform to our
guidelines? Are there any ``flake8`` errors?
guidelines? Are there any ``flake8`` errors? You can install the
:ref:`pre-commit <coding-style-pre-commit>` hooks to automatically catch
these errors.
* If the change is backwards incompatible in any way, is there a note
in the release notes (``docs/releases/A.B.txt``)?
* Is Django's test suite passing?
Expand Down

0 comments on commit 3bca95c

Please sign in to comment.