⏺ All tests pass. The new deep-nesting lint is now active.#283
⏺ All tests pass. The new deep-nesting lint is now active.#283
Conversation
Summary:
- Added MAX_NESTING_DEPTH = 4 constant
- Added structural analysis that counts if/else nesting depth in the AST
- Triggers a hint when nesting reaches 4+ levels
- Found 4 issues in the lisp examples, including the 7-level monster in eval-builtin-with-env
The lint suggests using cond or extracting to helper words. That 7-level function is a perfect candidate for cond:
# Current (7 levels of if/else):
dup "+" string.equal? if drop eval-add-with-env else
dup "-" string.equal? if drop eval-sub-with-env else
...7 levels deep...
then
then
# With cond (flat):
[ dup "+" string.equal? ] [ drop eval-add-with-env ]
[ dup "-" string.equal? ] [ drop eval-sub-with-env ]
[ dup "*" string.equal? ] [ drop eval-mul-with-env ]
...
[ true ] [ drop drop slist ]
7 cond
Code Review - PR #283: Deep Nesting LintGreat work adding structural analysis to the linter! This is a valuable addition that will help improve code quality. Here's my detailed feedback: ✅ Strengths
🔍 Code Quality Issues1. Inconsistent nesting calculation for quotations (lint.rs:298-303)The current implementation treats quotations as "starting fresh" with a nesting count of 0. However, this may not align with user expectations in all cases. Current behavior: Statement::Quotation { body, .. } => {
// Quotations start fresh nesting count (they're separate code blocks)
body.iter()
.map(|s| Self::if_nesting_depth(s, 0))
.max()
.unwrap_or(0)
}Question to consider: Should a quotation containing deeply nested ifs be flagged even if it's inside another if? The current implementation would reset the count, potentially missing complex nested logic. Consider whether this is the desired behavior or if quotations should inherit some context. 2. Missing test coverage
|
| Category | Rating | Notes |
|---|---|---|
| Code Quality | ⭐⭐⭐⭐☆ | Clean implementation, needs tests |
| Correctness | ⭐⭐⭐⭐☆ | Logic appears sound, edge cases need verification |
| Performance | ⭐⭐⭐⭐⭐ | Efficient O(n) traversal |
| Security | ⭐⭐⭐⭐⭐ | No concerns |
| Test Coverage | ⭐⭐☆☆☆ | Missing tests for new functionality |
| Documentation | ⭐⭐⭐☆☆ | Inline comments good, needs broader docs |
Overall: Approve with minor changes recommended
The core implementation is solid and addresses a real code quality issue. The main gap is test coverage. Once tests are added and the quotation behavior is clarified, this will be ready to merge.
Great job identifying the 7-level nesting monster in eval-builtin-with-env - that's exactly the kind of issue this lint should catch! 🎯
PR Review: Deep Nesting LintSummaryThis PR adds a structural lint that detects deeply nested if/else chains (≥4 levels) and suggests using Code Quality: ✅ StrongStrengths:
Minor observations:
Architecture: ✅ Well-designedThe lint integrates seamlessly into the existing architecture:
Design decisions:
Correctness: ✅ Appears soundThe nesting calculation logic is correct:
Edge cases handled:
Performance: ✅ Good
Potential Issues:
|
Summary:
The lint suggests using cond or extracting to helper words. That 7-level function is a perfect candidate for cond:
Current (7 levels of if/else):
dup "+" string.equal? if drop eval-add-with-env else
dup "-" string.equal? if drop eval-sub-with-env else ...7 levels deep... then then
With cond (flat):
[ dup "+" string.equal? ] [ drop eval-add-with-env ]
[ dup "-" string.equal? ] [ drop eval-sub-with-env ]
[ dup "*" string.equal? ] [ drop eval-mul-with-env ]
...
[ true ] [ drop drop slist ]
7 cond