Introduce a python linter
Address this issue #1082 (closed)
For this branch I chose to go with flake8
over pylint because:
- it's faster
- it's easier to write compliant code
- it's less annoying with naming conventions
- it's widely adopted
for some insights read this thread.
This merge request does
- add
flake8
as dev requirements - run on diff lines as a
pre-commit hook
- run on
gitlab-ci
(diff with master)
setup.cfg
Flake8 configuration in We will need to adujst the configuation for our needs as we gain experience.
[flake8]
exclude = .git
ignore = E501,W503,E203
E501,W503,E203 disabled because formatting is handled by black.
How to run flake8
# Run in current directory/file
$ flake8 /path/to/files/
# Run on local changes
$ git diff -U0 | flake8 --diff
# Run on staged changes
$ git diff -U0 --cached | flake8 --diff
Tips
- in-line ignore errors with
# noqa
comment
example = lambda: 'example' # noqa: E731
- ignore entire file by adding
# flake8: noqa
to the file - count errors per error code by adding option
--statistics