1: ---
2: title: "Example"
3: ---
4:
5: This file contains some issues for the linter to identify.
6:
7: ```{python}
8: # Function with low complexity
9: def simple_addition(a, b):
10: return a + b
11: ```
12:
13: There's another function to check below:
14:
15: ```{python}
16: # Function with moderate complexity
17: def check_number(num, flag, extra):
18: if num > 100:
19: if flag:
20: if extra:
21: return "Huge and flagged and extra"
22: else:
23: return "Huge and flagged"
24: else:
25: if extra:
26: return "Huge and extra"
27: else:
28: return "Huge"
29: elif num > 50:
30: if flag:
31: return "Medium and flagged"
32: else:
33: return "Medium"
34: elif num > 10:
35: if extra:
36: return "Small and extra"
37: else:
38: return "Small"
39: else:
40: if flag or extra:
41: return "Tiny but special"
42: else:
43: return "Tiny"
44: ```
radon
Computes four different code metrics:
radon-cc
: cyclomatic complexity (measures the number of independent paths through code).radon-mi
: maintainability index (estimates ease of maintenance).radon-raw
: raw metrics (counts lines, comments, blanks, etc.).radon-hal
: halstead metrics (quantifies code complexity based on operators (symbols) and operands (variables)).
See the radon documentation for more details.
Example Quarto .qmd
file:
Run radon using lintquarto
lintquarto -l radon-cc -p complexity_example.qmd
=============================================================
Running radon-cc...
=============================================================
/home/runner/work/lintquarto/lintquarto/docs/pages/tools/examples/complexity_example.qmd
F 17:0 check_number - C
F 9:0 simple_addition - A
lintquarto -l radon-mi -p complexity_example.qmd
=============================================================
Running radon-mi...
=============================================================
/home/runner/work/lintquarto/lintquarto/docs/pages/tools/examples/complexity_example.qmd - A
lintquarto -l radon-raw -p complexity_example.qmd
=============================================================
Running radon-raw...
=============================================================
/home/runner/work/lintquarto/lintquarto/docs/pages/tools/examples/complexity_example.qmd
LOC: 31
LLOC: 29
SLOC: 29
Comments: 2
Single comments: 2
Multi: 0
Blank: 0
- Comment Stats
(C % L): 6%
(C % S): 7%
(C + M % L): 6%
lintquarto -l radon-hal -p complexity_example.qmd
=============================================================
Running radon-hal...
=============================================================
/home/runner/work/lintquarto/lintquarto/docs/pages/tools/examples/complexity_example.qmd:
h1: 3
h2: 8
N1: 5
N2: 10
vocabulary: 11
length: 15
calculated_length: 28.75488750216347
volume: 51.89147427955947
difficulty: 1.875
effort: 97.296514274174
time: 5.405361904120777
bugs: 0.01729715809318649