summaryrefslogtreecommitdiffstats
path: root/tools/lint/docs/linters/flake8.rst
blob: 5ef17d41d49d830a6c18c0552795bf133f0b064d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Flake8
======

`Flake8`_ is a popular lint wrapper for python. Under the hood, it runs three other tools and
combines their results:

* `pep8`_ for checking style
* `pyflakes`_ for checking syntax
* `mccabe`_ for checking complexity


Run Locally
-----------

The mozlint integration of flake8 can be run using mach:

.. parsed-literal::

    $ mach lint --linter flake8 <file paths>

Alternatively, omit the ``--linter flake8`` and run all configured linters, which will include
flake8.


Configuration
-------------

Only directories explicitly whitelisted will have flake8 run against them. To enable flake8 linting
in a source directory, it must be added to the ``include`` directive in ```tools/lint/flake8.lint``.
If you wish to exclude a subdirectory of an included one, you can add it to the ``exclude``
directive.

The default configuration file lives in ``topsrcdir/.flake8``. The default configuration can be
overriden for a given subdirectory by creating a new ``.flake8`` file in the subdirectory. Be warned
that ``.flake8`` files cannot inherit from one another, so all configuration you wish to keep must
be re-defined.

.. warning::

    Only ``.flake8`` files that live in a directory that is explicitly included in the ``include``
    directive will be considered. See `bug 1277851`_ for more details.

For an overview of the supported configuration, see `flake8's documentation`_.

.. _Flake8: https://flake8.readthedocs.io/en/latest/
.. _pep8: http://pep8.readthedocs.io/en/latest/
.. _pyflakes: https://github.com/pyflakes/pyflakes
.. _mccabe: https://github.com/pycqa/mccabe
.. _bug 1277851: https://bugzilla.mozilla.org/show_bug.cgi?id=1277851
.. _flake8's documentation: https://flake8.readthedocs.io/en/latest/config.html