Skip to content

fix(lint): SingletonElisionChecker was a silent no-op; add warn-only severity - #3752

Merged
zackees merged 2 commits into
masterfrom
fix/3482-singleton-elision-detection
Jul 28, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/3482-singleton-elision-detection

Conversation

@zackees

@zackees zackees commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

Closes #3482.

The wiring was already done; the checker was broken

The issue asks to register SingletonElisionChecker so bash lint runs it. That registration is already on master — it's in supported_checker_names(), constructed in create_checkers(), and shows up in --list-checkers. It reported nothing because of 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; }                        // every line skipped

end_pos lands just before the = / ; / [, so for the ordinary spelling int x = 0; the head retains a trailing space. rsplit splits 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.py found 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=1 showed 1 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 the push.

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.

[SingletonElisionChecker] Found 76 violation(s) in 23 file(s): (warn-only — not failing CI)
⚠️  76 warn-only violation(s) — reported, not failing CI.

The duplicated list

WARN_ONLY_CHECKERS exists in both lint_core/warn_only.rs and run_all_checkers.py because 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 lint still failed).

Since drift means the stricter layer wins silently, ci/tests/test_warn_only_checkers_sync.py asserts 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

  • warn-only path: bash lint exits 0 while reporting all 76
  • blocking path intact: emptying the warn list → exit 1; an injected real violation fails bash lint --cpp → 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 and untouched here; I verified it fails identically with my changes stashed. My additions did push processor_registry_cli.rs to 1038, so the warn-only policy and reporting moved into lint_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

  • New Features
    • Added a warn-only policy for selected C++ lint checkers, reporting their findings without failing CI.
    • Updated command output to label warn-only results and emit a consolidated non-blocking summary.
  • Bug Fixes
    • Improved detection for declarations with whitespace before initializers so relevant lint findings are reliably reported.
  • Tests
    • Added tests to ensure Rust and Python warn-only checker lists stay synchronized and that the warn-only list is non-empty.

…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]>
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 817b6141-9f98-4bc0-9e2c-9e6cb4b04650

📥 Commits

Reviewing files that changed from the base of the PR and between e511911 and 746a9af.

📒 Files selected for processing (1)
  • ci/lint_cpp/run_all_checkers.py

📝 Walkthrough

Walkthrough

The 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.

Changes

Warn-only lint handling

Layer / File(s) Summary
Warn-only policy contract
ci/lint_cpp/run_all_checkers.py, ci/lint_cpp_rs/src/lint_core/warn_only.rs, ci/lint_cpp_rs/src/lib.rs, ci/tests/test_warn_only_checkers_sync.py
Defines synchronized warn-only checker lists, exposes the Rust policy, and verifies both lists remain identical and non-empty.
Reporting and exit handling
ci/lint_cpp/run_all_checkers.py, ci/lint_cpp_rs/src/lint_core/processor_registry_cli.rs, ci/lint_cpp_rs/src/lint_core/warn_only.rs
Separates warn-only findings from blocking violations, annotates their output, and returns a failing status only when blocking violations exist.
Singleton violation extraction
ci/lint_cpp_rs/src/checkers/singleton_elision.rs
Trims declaration text before extracting variable names, preserving violations for declarations with whitespace before initializers.

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
Loading

Possibly related issues

  • Issue 3492: Proposes promoting SingletonElisionChecker violations to hard-fail, contrary to this change’s warn-only classification.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning [#3482] The warn-only migration is implemented, but the registration/opt-in include path required to run SingletonElisionChecker via bash lint is not evidenced here. Register singleton_elision in the enabled checker list and add the requested --include/env opt-in path so bash lint executes it as specified.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: fixing SingletonElisionChecker and making it warn-only.
Out of Scope Changes check ✅ Passed The changes all support the lint warn-only migration or the SingletonElisionChecker fix and do not appear unrelated to the issue scope.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/3482-singleton-elision-detection

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between dd791b4 and e511911.

📒 Files selected for processing (6)
  • ci/lint_cpp/run_all_checkers.py
  • ci/lint_cpp_rs/src/checkers/singleton_elision.rs
  • ci/lint_cpp_rs/src/lib.rs
  • ci/lint_cpp_rs/src/lint_core/processor_registry_cli.rs
  • ci/lint_cpp_rs/src/lint_core/warn_only.rs
  • ci/tests/test_warn_only_checkers_sync.py

Comment thread ci/lint_cpp/run_all_checkers.py Resolved
…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]>
@zackees
zackees merged commit e74e8d7 into master Jul 28, 2026
15 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

lint: wire SingletonElisionChecker into bash lint (warn-only)

1 participant