Code Quality Rules¶
CytoScnPy detects common Python code quality issues and maintains alignment with industry-standard linting codes (Flake8, Bugbear, Pylint).
Enable quality analysis with the --quality flag:
Rule ID Prefixes¶
| Prefix | Category |
|---|---|
CSP-L | Best Practices |
CSP-Q | Complexity & Maintainability Metrics |
CSP-C | Maintainability Limits (Args/Length) |
CSP-P | Performance |
Individual rule pages are available for Best Practices and Performance. Maintainability rules are summarized in this index.
Best Practices¶
| ID | Rule | Description |
|---|---|---|
| CSP-L001 | MutableDefaultArgumentRule | Detects mutable default arguments (lists, dicts, sets). |
| CSP-L002 | BareExceptRule | Detects except: blocks without a specific exception class. |
| CSP-L003 | DangerousComparisonRule | Detects comparisons to True, False, or None using == instead of is. |
Maintainability & Complexity¶
| ID | Rule | Description | Config |
|---|---|---|---|
CSP-Q301 | ComplexityRule | Function cyclomatic complexity (McCabe) exceeds threshold. | max_complexity |
CSP-Q302 | NestingRule | Code block is nested too deeply. | max_nesting |
CSP-Q303 | Maintainability Index Gate | File MI below threshold (only emitted when min_mi is set). | min_mi |
CSP-Q304 | CognitiveComplexityRule | Cognitive complexity exceeds fixed threshold (default 15). | Fixed threshold (not configurable) |
CSP-Q305 | CohesionRule | Class lacks cohesion (LCOM4 > 1). | Fixed threshold (not configurable) |
CSP-C303 | ArgumentCountRule | Function has too many arguments. | max_args |
CSP-C304 | FunctionLengthRule | Function is too long (line count). | max_lines |
Performance¶
| ID | Rule | Description |
|---|---|---|
| CSP-P001 | MembershipInListRule | Membership test in list literal or list comprehension (use set). |
| CSP-P002 | FileReadMemoryRiskRule | read() / readlines() loads entire file into RAM. |
| CSP-P003 | StringConcatInLoopRule | Accumulated + string concatenation inside loops. |
| CSP-P004 | UselessCastRule | Unnecessary list()/tuple() wrapping range()/map()/filter(). |
| CSP-P005 | RegexLoopRule | re.compile() or ast.parse() called inside loops. |
| CSP-P006 | AttributeChainHoistingRule | Deep attribute access inside loops (hoist to local). |
| CSP-P007 | PureCallHoistingRule | Pure builtin calls in loops with invariant arguments. |
| CSP-P008 | ExceptionFlowInLoopRule | try/except used as control flow in loops (KeyError/AttributeError). |
| CSP-P009 | IncorrectDictIteratorRule | .items() used while discarding key/value (use .keys()/.values()). |
| CSP-P010 | GlobalUsageInLoopRule | Global/constant usage inside loops (hoist to local). |
| CSP-P011 | MemoryviewOverBytesRule | Slicing bytes in loops (use memoryview() for zero-copy). |
| CSP-P012 | UseTupleOverListRule | Constant list literal is immutable (prefer tuple). |
| CSP-P013 | ComprehensionSuggestionRule | Loop can be replaced by list/set/dict comprehension. |
| CSP-P015 | PandasChunksizeRiskRule | pandas.read_csv() without chunksize/nrows/iterator. |
Configuration¶
You can tune the thresholds for quality rules in your .cytoscnpy.toml:
[cytoscnpy]
max_complexity = 15 # Default: 10
max_nesting = 4 # Default: 3
max_args = 6 # Default: 5
max_lines = 100 # Default: 50
min_mi = 40.0 # Default: unset (no MI gate)
Suppression¶
Use standard suppression comments. You can suppress all findings or target specific rule IDs: