Add a code linting tool chain
- use flake8 as the main and pylint as the auxiliary linter
- install flake8 with the following plug-ins:
+ flake8-annotations => enforce type annotations for functions/classes
+ flake8-black => ensure black would not make any changes
+ flake8-expression-complexity
+ wemake-python-styleguide, which packages the following:
* darglint * flake8-bandit * flake8-broken-line
* flake8-bugbear * flake8-commas * flake8-comprehensions
* flake8-debugger * flake8-docstrings * flake8-eradicate
* flake8-isort * flake8-rst-docstrings * flake8-string-format
* flake8-quotes * pep8-naming
- configure flake8 & friends in a rather explicit and strict way
- isort needed to be downgraded to ^4.3.21 due to a conflict with
pylint and wemake-python-styleguide:
+ provide TODO's to remove the parts that "fix" isort
- use mypy for static type checking
- add a nox session "lint" that runs flake8, mypy, and pylint
- lint all source files
This commit is contained in:
parent
bb6de05709
commit
c7989e0040
4 changed files with 938 additions and 24 deletions
144
setup.cfg
144
setup.cfg
|
|
@ -2,6 +2,111 @@
|
|||
# black's settings are in pyproject.toml => [tool.black]
|
||||
|
||||
|
||||
[flake8]
|
||||
# Include error classes only explicitly
|
||||
# to avoid forward compatibility issues.
|
||||
select =
|
||||
# =============
|
||||
# flake8's base
|
||||
# =============
|
||||
# mccabe => cyclomatic complexity
|
||||
C901,
|
||||
# pycodestyle => PEP8 compliance
|
||||
E, W,
|
||||
# pyflakes => basic errors
|
||||
F4, F5, F6, F7, F8, F9
|
||||
# ========================
|
||||
# wemake-python-styleguide
|
||||
# Source: https://wemake-python-stylegui.de/en/latest/pages/usage/violations/index.html
|
||||
# ========================
|
||||
WPS1, WPS2, WPS3, WPS4, WPS5, WPS6,
|
||||
# darglint => docstring matches implementation
|
||||
DAR0, DAR1, DAR2, DAR3, DAR4, DAR5,
|
||||
# flake8-bandit => common security issues
|
||||
S1, S2, S3, S4, S5, S6, S7,
|
||||
# flake8-broken-line => no \ to end a line
|
||||
N400,
|
||||
# flake8-bugbear => opinionated bugs and design flaws
|
||||
B0, B3, B9,
|
||||
# flake8-commas => better comma placements
|
||||
C8,
|
||||
# flake8-comprehensions => better comprehensions
|
||||
C4,
|
||||
# flake8-debugger => no debugger usage
|
||||
T100,
|
||||
# flake8-docstrings => PEP257 compliance
|
||||
D1, D2, D3, D4,
|
||||
# flake8-eradicate => no commented out code
|
||||
E800,
|
||||
# flake8-isort => isort would make changes
|
||||
I0,
|
||||
# flake8-rst-docstrings => valid rst in docstrings
|
||||
RST2, RST3, RST4,
|
||||
# flake8-string-format => unify usage of str.format()
|
||||
P1, P2, P3,
|
||||
# flake8-quotes => use double quotes everywhere (complying with black)
|
||||
Q0,
|
||||
# pep8-naming
|
||||
N8,
|
||||
# =====
|
||||
# other
|
||||
# =====
|
||||
# flake8-annotations => enforce type checking for functions
|
||||
ANN0, ANN2, ANN3,
|
||||
# flake8-black => complain if black would make changes
|
||||
BLK1, BLK9,
|
||||
# flake8-expression-complexity => not too many expressions at once
|
||||
ECE001,
|
||||
|
||||
# By default, flake8 ignores some errors.
|
||||
# Instead, do not ignore anything.
|
||||
ignore =
|
||||
|
||||
# If --ignore is passed on the command
|
||||
# line, still ignore the following:
|
||||
extend-ignore =
|
||||
# Comply with black's style.
|
||||
# Source: https://github.com/psf/black/blob/master/docs/compatible_configs.md#flake8
|
||||
E203, W503,
|
||||
# f-strings are ok.
|
||||
WPS305,
|
||||
|
||||
per-file-ignores =
|
||||
noxfile.py:
|
||||
# TODO (isort): Check if still too many module members.
|
||||
WPS202,
|
||||
# TODO (isort): Remove after simplifying the nox session "lint".
|
||||
WPS213,
|
||||
# No overuse of string constants (e.g., '--version').
|
||||
WPS226,
|
||||
|
||||
# Explicitly set mccabe's maximum complexity to 10 as recommended by
|
||||
# Thomas McCabe, the inventor of the McCabe complexity, and the NIST.
|
||||
# Source: https://en.wikipedia.org/wiki/Cyclomatic_complexity#Limiting_complexity_during_development
|
||||
max-complexity = 10
|
||||
|
||||
# Comply with black's style.
|
||||
# Source: https://github.com/psf/black/blob/master/docs/the_black_code_style.md#line-length
|
||||
max-line-length = 88
|
||||
|
||||
# Preview the code lines that cause errors.
|
||||
show-source = true
|
||||
|
||||
# ===================================
|
||||
# wemake-python-styleguide's settings
|
||||
# ===================================
|
||||
allowed-domain-names =
|
||||
result,
|
||||
min-name-length = 3
|
||||
max-name-length = 40
|
||||
# darglint
|
||||
strictness = long
|
||||
# flake8-docstrings
|
||||
docstring-convention = google
|
||||
# flake8-eradicate
|
||||
eradicate-aggressive = true
|
||||
|
||||
|
||||
[isort]
|
||||
atomic = true
|
||||
case_sensitive = true
|
||||
|
|
@ -24,3 +129,42 @@ use_parentheses = true
|
|||
# Source: https://google.github.io/styleguide/pyguide.html#313-imports-formatting
|
||||
force_single_line = true
|
||||
single_line_exclusions = typing
|
||||
|
||||
|
||||
[mypy]
|
||||
cache_dir = .cache/mypy
|
||||
|
||||
[mypy-nox.*]
|
||||
ignore_missing_imports = true
|
||||
|
||||
|
||||
[pylint.FORMAT]
|
||||
# Comply with black's style.
|
||||
max-line-length = 88
|
||||
|
||||
[pylint.MESSAGES CONTROL]
|
||||
disable =
|
||||
# We use TODO's to indicate locations in the source base
|
||||
# that must be worked on in the near future.
|
||||
fixme,
|
||||
# Comply with black's style.
|
||||
bad-continuation, bad-whitespace,
|
||||
# =====================
|
||||
# flake8 de-duplication
|
||||
# Source: https://pylint.pycqa.org/en/latest/faq.html#i-am-using-another-popular-linter-alongside-pylint-which-messages-should-i-disable-to-avoid-duplicates
|
||||
# =====================
|
||||
# mccabe
|
||||
too-many-branches,
|
||||
# pep8-naming
|
||||
bad-classmethod-argument, bad-mcs-classmethod-argument,
|
||||
invalid-name, no-self-argument,
|
||||
# pycodestyle
|
||||
bad-indentation, bare-except, line-too-long, missing-final-newline,
|
||||
multiple-statements, trailing-whitespace, unnecessary-semicolon, unneeded-not,
|
||||
# pydocstyle
|
||||
missing-class-docstring, missing-function-docstring, missing-module-docstring,
|
||||
# pyflakes
|
||||
undefined-variable, unused-import, unused-variable,
|
||||
|
||||
[pylint.REPORTS]
|
||||
score = no
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue