Repository navigation
fix(lint): SingletonElisionChecker was a silent no-op; add warn-only severity - #3752
Conversation
…severity Closes #3482. The issue asked to wire SingletonElisionChecker into `bash lint`. That wiring was already on master -- registered in supported_checker_names(), constructed in create_checkers(), listed by --list-checkers. The reason it reported nothing was a bug in the checker itself. Root cause, in the name extraction: let head = &code[..end_pos]; // "int x " -- end_pos stops before '=' let name = head.rsplit(|c| !alnum && c != '_').next() // -> "" if name.is_empty() { continue; } `end_pos` lands just before the `=`/`;`/`[`, so for the ordinary spelling `int x = 0;` the head keeps a trailing space. rsplit then splits on that space and hands back the empty tail, so the name came out empty and every line was skipped. Since virtually all real declarations put a space before the initializer, the checker reported zero violations tree-wide while ci/scan_singleton_elision.py found 101. Trimming the head fixes it: 76 violations across 23 files now surface. That fix alone breaks the build, which is why the second half ships with it. There was no severity concept in the Rust linter -- any violation meant exit 1 -- so turning detection back on would have failed CI on 76 pre-existing globals. Added a warn-only list: findings are printed and labelled, but do not affect the exit code. The list is duplicated in Rust (lint_core/warn_only.rs) and Python (run_all_checkers.py) because both layers decide an exit status independently -- the Rust binary for its own run, the Python orchestrator after re-tallying. If they drift the stricter one wins silently, so ci/tests/test_warn_only_checkers_sync.py asserts they match, with a non-empty guard so the parser cannot pass vacuously. Validated: - warn-only path: `bash lint` exits 0 while reporting all 76 - blocking path still fails: emptying the warn list gives exit 1, and an injected real violation fails `bash lint --cpp` with exit 1 - 558 passed / 39 skipped in ci/tests; 24/25 Rust tests pass The one failing Rust test (rust_lint_source_files_stay_under_one_thousand_lines) is pre-existing on master: checkers/unity_build.rs is 1205 lines, untouched here. My own additions did push processor_registry_cli.rs to 1038, so the warn-only policy and reporting were extracted into lint_core/warn_only.rs, bringing it back to 982. Note for #3492 (promote to hard-fail): it would have been a no-op promotion before this -- passing trivially while guarding nothing. Co-Authored-By: Claude <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Python and Rust lint pipelines now classify selected checker violations as warn-only, report them without failing CI, synchronize their checker lists, and trim SingletonElisionChecker declaration text before extracting variable names. ChangesWarn-only lint handling
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant run_cli
participant is_warn_only
participant print_text_results
participant CI
run_cli->>is_warn_only: classify checker violations
run_cli->>print_text_results: render grouped results
print_text_results->>CI: report warn-only and blocking findings
run_cli->>CI: return blocking exit status
Possibly related issues
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ci/lint_cpp/run_all_checkers.py`:
- Around line 364-370: Update the success-reporting branch in the checker’s
result-summary flow to distinguish runs with warn-only violations from
completely clean runs. When warn_only_violations is greater than zero and no
blocking findings exist, print wording equivalent to the Rust runner’s “No
blocking … violations” instead of “All C++ linting checks passed!”, while
preserving the existing clean-success message for zero violations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: d24c4e1f-fe98-4df7-beee-254389dbe972
📒 Files selected for processing (6)
ci/lint_cpp/run_all_checkers.pyci/lint_cpp_rs/src/checkers/singleton_elision.rsci/lint_cpp_rs/src/lib.rsci/lint_cpp_rs/src/lint_core/processor_registry_cli.rsci/lint_cpp_rs/src/lint_core/warn_only.rsci/tests/test_warn_only_checkers_sync.py
…xist Review follow-up. With blocking violations at zero but warn-only findings present, the Python summary still printed "All C++ linting checks passed!" -- which is how a warn-only rollout quietly gets forgotten. Mirrors the Rust runner's wording instead: "No blocking C++ lint violations." Co-Authored-By: Claude <[email protected]>
Closes #3482.
The wiring was already done; the checker was broken
The issue asks to register
SingletonElisionCheckersobash lintruns it. That registration is already on master — it's insupported_checker_names(), constructed increate_checkers(), and shows up in--list-checkers. It reported nothing because of a bug in the checker itself.Root cause, in the name extraction:
end_poslands just before the=/;/[, so for the ordinary spellingint x = 0;the head retains a trailing space.rsplitsplits on that space and returns the empty tail, the name comes out empty, and the guard skips the line.Since essentially every real declaration puts a space before the initializer, this made the checker a universal no-op — zero violations tree-wide, while
ci/scan_singleton_elision.pyfound 101. Trimming the head fixes it: 76 violations across 23 files now surface.I confirmed the diagnosis rather than inferring it — the checker was selected and did process files (
FASTLED_LINT_PROFILE=1showed1 files x 1 checkers), the binary was current (rebuild was a no-op, and it already contained the message string), and a three-line synthetic global still produced nothing. Instrumenting the loop showed execution reaching name-extraction but never thepush.Why warn-only ships in the same PR
The detection fix alone breaks the build. There was no severity concept in the Rust linter at all — any violation meant exit 1 — so re-enabling detection would have failed CI on 76 pre-existing globals. That's exactly why the issue specifies warn severity; it just didn't exist yet.
Added a warn-only list: findings are printed and labelled, but don't affect the exit code.
The duplicated list
WARN_ONLY_CHECKERSexists in bothlint_core/warn_only.rsandrun_all_checkers.pybecause both layers independently decide an exit status — the Rust binary for its own run, and the Python orchestrator after re-tallying the same findings. Making only one warn-aware isn't enough; I hit precisely that (Rust exited 0,bash lintstill failed).Since drift means the stricter layer wins silently,
ci/tests/test_warn_only_checkers_sync.pyasserts the two match, plus a non-empty guard so the regex can't make the comparison pass vacuously. That test earned its keep immediately: it caught my own drift when I moved the constant into a new module.Validation
bash lintexits 0 while reporting all 76bash lint --cpp→ exit 1558 passed, 39 skippedinci/tests; 24/25 Rust tests passThe one failing Rust test (
rust_lint_source_files_stay_under_one_thousand_lines) is pre-existing on master —checkers/unity_build.rsis 1205 lines and untouched here; I verified it fails identically with my changes stashed. My additions did pushprocessor_registry_cli.rsto 1038, so the warn-only policy and reporting moved intolint_core/warn_only.rs, bringing it back to 982.Note for #3492
#3492 proposes promoting this checker to hard-fail. Before this PR that would have been a no-op promotion — passing trivially while guarding nothing. It's now meaningful, and gated on the 76 findings reaching zero via the #3481 sub-issues.
🤖 Generated with Claude Code
Summary by CodeRabbit