Flake8 extension to calculate per-line complexity and total code density.
$ pip install jones-complexity
$ python -m jones_complexity --max-line-complexity 5 your_file.py
$ flake8 --max-line-complexity 15 --max-jones-score 8 yourproject
We do not make any assumptions on the required configuration,
so if no explicit configuration is provided, this plugin will be silent.
Enable it by setting --max-jones-score
or --max-line-complexity
options.
Because
if user.get_full_name().toUpper().split(' ')[0] == 'ALICE':
return True
is harder to read and maintain than
if first_name == 'Alice':
return True
Shamelessly named after myself, in the tradition of McCabe and Halstead.
We support two options:
--max-line-complexity
which sets the maximum complexity for a single line--max-jones-score
which sets maximum median complexity inside a moduleYou can provide options via:
flake8
usagesflake8
, setup.cfg
and .flake8
files are supported, see docsItself:
$ python -m jones_complexity jones_complexity.py
[
"jones_complexity.py:46:1: J901 Line 46 is too complex (13)",
"jones_complexity.py:40:1: J901 Line 40 is too complex (12)",
...
"jones_complexity.py:154:1: J901 Line 154 is too complex (2)",
"jones_complexity.py:170:1: J901 Line 170 is too complex (2)"
]
Jones Score: 3
$ python -m jones_complexity pyesprima.py
Line counts:
[
"pyesprima.py:4191:1: J901 Line 4191 is too complex (265)",
"pyesprima.py:41:1: J901 Line 41 is too complex (189)",
"pyesprima.py:4195:1: J901 Line 4195 is too complex (189)",
"pyesprima.py:4189:1: J901 Line 4189 is too complex (164)",
...
"pyesprima.py:4963:1: J901 Line 4963 is too complex (2)",
"pyesprima.py:4978:1: J901 Line 4978 is too complex (2)",
"pyesprima.py:4996:1: J901 Line 4996 is too complex (2)"
]
Jones Score: 9.0