Skip to content

Commit e45ca30

Browse files
committed
chore: add a cyclomatic complexity plugin to pylint
This commit add a feature commented by @jaonoctus on a [\selfcustody#847 comment](https://github.com/selfcustody/krux/pull/847/changes#r3029819808), where an review about multiple lines review could be avoided automatically if we apply the `mccabe` plugin to `pylint`. E.g, visually complexity could lead humans to interpret some lines as complex given a experience of how code should be or not to be; some standars could say that 25 lines could be the limit of a readability. But a cyclomatic complexity on a function could be used as a "how real complex is the function" and "it should be really refactored?". Tested with `max-complexity=13` and `max-complexity=20` in tags `v26.03.0`, branches `main`, `develop` and `feat/stackbit-1248-vertical`. For more details about values a wikipedia short ref: * 1–10: Simple procedure: `little risk`; * 11–20: More complex: `moderate risk`; * 21–50: Complex: `high risk`. * > 50: Untestable code: `very high risk`; For now, this commit found 7 `too-complex` functions on source code base.
1 parent e531811 commit e45ca30

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ black.ref = "format"
8484
format-test.ref = "format-tests"
8585

8686
# pylint tasks
87-
lint-src = "pylint src"
87+
lint-src = "pylint --load-plugins=pylint.extensions.mccabe --max-complexity=20 src"
8888
lint-scripts = "pylint firmware/font/*.py firmware/scripts/*.py i18n/*.py"
8989
lint = ["lint-src", "lint-scripts"]
9090
# aliases
@@ -101,6 +101,7 @@ test-clean = """python -c 'import shutil, os; os.path.exists("htmlcov") and shut
101101
test-cov = "pytest --cache-clear --cov src/krux --cov-report html ./tests --cov-context=test --cov-report term-missing"
102102
test-verbose = "pytest --cache-clear --cov src/krux --cov-report html --show-capture all --capture tee-sys -r A ./tests"
103103
test-simple = "pytest --cache-clear ./tests"
104+
104105
# aliases
105106
tests = ["test-clean", "test-cov"]
106107
test.ref = "tests"

0 commit comments

Comments
 (0)