Skip to content

Commit 9fddec0

Browse files
committed
docs: Add class docstrings for LizardExtension in complexity-related modules
This commit introduces detailed docstrings for the LizardExtension classes in lizardcomplextags.py, lizardmccabe.py, and lizardmodified.py. The docstrings clarify the purpose and functionality of each extension, enhancing code documentation and maintainability.
1 parent 54ccbab commit 9fddec0

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lizard_ext/lizardcomplextags.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55

66

77
class LizardExtension(object): # pylint: disable=R0903
8+
"""
9+
Complex tags extension: records all complexity-adding keywords and their line numbers.
10+
Uses reader.conditions (combined set of all condition types) to track all
11+
complexity contributors: control flow, logical operators, case labels, and ternary.
12+
"""
813

914
# pylint: disable=W0221
1015
def __call__(self, tokens, reader):
1116
context = reader.context
17+
# Use combined conditions set - intentionally includes all types
1218
conditions = reader.conditions
1319
for token in tokens:
1420
yield token

lizard_ext/lizardmccabe.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414

1515

1616
class LizardExtension(ExtensionBase): # pylint: disable=R0903
17+
"""
18+
McCabe extension: only counts the first 'case' in a switch statement.
19+
Consecutive cases without code between them don't add to complexity.
20+
Works by detecting case tokens (conceptually from reader.case_keywords).
21+
"""
1722

1823
def _state_global(self, token):
19-
if token == "case":
24+
if token == "case": # Detect case keywords
2025
self._state = self._in_case
2126

2227
def _in_case(self, token):

lizard_ext/lizardmodified.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66

77

88
class LizardExtension(object): # pylint: disable=R0903
9+
"""
10+
Modified CCN extension: counts entire switch/case as 1 complexity.
11+
Adds +1 for 'switch', subtracts -1 for each 'case'.
12+
Works with switch/case keywords (conceptually from reader.case_keywords).
13+
"""
914

1015
def __call__(self, tokens, reader):
1116
for token in tokens:
12-
if token == 'switch':
17+
if token == 'switch': # Add complexity for switch statement
1318
reader.context.add_condition()
1419
if hasattr(reader.context, "add_nd_condition"):
1520
reader.context.add_nd_condition()
16-
elif token == 'case':
21+
elif token == 'case': # Subtract complexity for each case
1722
reader.context.add_condition(-1)
1823
if hasattr(reader.context, "add_nd_condition"):
1924
reader.context.add_nd_condition(-1)

0 commit comments

Comments
 (0)