Repository navigation
code static analysis - #48
Conversation
PR Summary by QodoAdd static-analysis starter modules and relax CI coverage threshold
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo
1. Wrong rules type hint
|
| def find_violations(code: List[str], rules: List[str]): | ||
| """ | ||
| This function takes a list of code lines and a list of rules, and returns a list of violations found in the code. | ||
| """ | ||
| violations = [] | ||
| for rule in rules: | ||
| pattern = rule["pattern"] | ||
| severity = rule["severity"] |
There was a problem hiding this comment.
1. Wrong rules type hint 🐞 Bug ≡ Correctness
find_violations() annotates rules as List[str] but indexes each rule as a dict (rule["pattern"], rule["severity"]), so a caller passing a list of strings (per the signature) will crash with TypeError. The module’s own example uses a list of dicts, confirming the signature is inconsistent with actual usage.
Agent Prompt
### Issue description
`Algorithms/static_analysis/rule_matcher.py::find_violations()` declares `rules: List[str]`, but treats each element as a mapping with `pattern` and `severity`. This creates an API contract mismatch and can cause runtime errors for any caller following the type hint.
### Issue Context
The module’s own `rules = [{"pattern": ..., "severity": ...}]` example shows the intended structure is a list of dict-like objects.
### Fix Focus Areas
- Algorithms/static_analysis/rule_matcher.py[3-19]
- Algorithms/static_analysis/rule_matcher.py[27-32]
### Suggested fix
- Update the signature to something like `rules: Sequence[Mapping[str, str]]` (or define a `TypedDict` for rule shape).
- Optionally add a small validation/guard for missing keys and raise a clear exception (e.g., `ValueError`) rather than a `KeyError`/`TypeError`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Go through common use cases for static analysis of programs.