max-statements in Javascript ESLint offers a really good enforcement for small, modualized and readable functions. I was hoping to find something similar in Python Flake8 lint but so far I've had no luck. Is there a way of configuring Flake8 to encourage small functions?
Asked
Active
Viewed 369 times
1
-
Looks like there's a cyclomatic complexity checker, but it's disabled by default. `--max-complexity` is the command line flag for it or `max-complexity =` in a config file. A value of 10 is recommended. It's not *quite* the same but can encourage similar habits. – kindall Dec 04 '16 at 07:47
1 Answers
3
To expand on @kindall's comment,
Flake8 does not provide a statement checker, but it does have two ways of calculating cyclomatic complexity of functions and methods.
Cyclomatic complexity uses statements and branches to determine the complexity of a function so this will likely result in even simpler functions than what you might see in JavaScript. This is because if/elif/else
structures will add to the complexity, as will for
and while
loops.
To enable the "built-in" cyclomatic complexity enforcement, you can use --max-complexity
. There are, however, alternatives to the mccabe
project. For example, if you pip install radon
that adds it's own cyclomatic complexity checking to Flake8 and will run when you run Flake8.

Ian Stapleton Cordasco
- 26,944
- 4
- 67
- 72