Skip to content

feat(lint): enforce Public Settings Pattern for fl:: global setters (layer 5) - #2716

Merged
zackees merged 2 commits into
chore/cpp-style-public-settings-patternfrom
feat/public-settings-pattern-lint-checker
Jun 3, 2026
Merged

zackees merged 2 commits into
chore/cpp-style-public-settings-patternfrom
feat/public-settings-pattern-lint-checker

Conversation

@zackees

@zackees zackees commented Jun 3, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds ci/lint_cpp/public_settings_pattern_checker.py — a new FileContentChecker that enforces the Public Settings Pattern documented in agents/docs/cpp-standards.md → "Public Settings Pattern (Global Configuration via CFastLED)"
  • Registers it in the fl scope in ci/lint_cpp/run_all_checkers.py so it runs automatically via bash lint --cpp
  • 63 unit tests in ci/lint_cpp/test_public_settings_pattern_checker.py; all pass; bash lint --cpp exits clean

This is layer 5 of the six-layer enforcement plan introduced in PR #2715 (docs, CodeRabbit, architecture-reviewer-agent, /code_review skill, backfill wrappers, syntactic check ← this PR).

What it flags

Every public free function in src/fl/**/*.h matching ^(set|enable|disable|use)_[a-z] that is declared at namespace fl root scope and has no corresponding call-site in src/FastLED.h (i.e. no CFastLED wrapper method that delegates to it).

Violation message example:

fl::set_my_option(...) declared here is a public global setter but has no
CFastLED::setMyOption() wrapper in src/FastLED.h. New global setters must
follow the Public Settings Pattern — add an `inline` one-liner on CFastLED
that delegates to this free function. See exemplar at src/FastLED.h:1455
(setPowerModel -> fl::set_power_model).

Suppression: // nolint or // ok public_settings on the declaration line.

Carve-outs (not flagged)

Pattern Reason
fl::detail::*, fl::isr::*, any sub-namespace Not public fl:: API
Anonymous namespace { } File-local, not public
Class/struct member functions Per-object, not global state
set_rgb_2_rgbw_function, set_rgb_2_rgbww_function Function-pointer installers (explicit allowlist)
Non-const ptr/ref to user-defined type as first param Per-object mutator heuristic

Grandfathered allowlist (seeded from PR #2715 description)

These predate the rule and are NOT flagged:

Implementation notes

The scope tracker uses a per-{ scope stack (not a simple brace depth counter). This correctly handles enum bodies, inline function definitions, and nested namespaces without false namespace pops — a bug that would occur with the naive counter approach (verified by tracing src/fl/gfx/rgbww.h where enum { kDefaultCct = 2700 } closes before set_rgbww_colorimetric_profile is declared).

src/FastLED.h is loaded once at checker __init__ time; the wrapper lookup is a word-boundary regex scan that skips #include lines and pure comment lines.

Test plan

  • 63 unit tests covering: file filtering, positive violations, negative carve-outs, grandfathered allowlist, per-object heuristic, function-pointer carve-out, comment exemptions, suppression tokens, cross-file wrapper check, edge cases (enum bodies, inline functions, nested namespaces, scope recovery after sub-namespace closes)
  • bash lint --cpp passes clean on the full codebase

🤖 Generated with Claude Code

Adds `PublicSettingsPatternChecker` (ci/lint_cpp/public_settings_pattern_checker.py)
— layer 5 of the six-layer Public Settings Pattern enforcement plan introduced
in PR #2715 / docs commit d51a8f6.

What it checks:
  Every public free function declared at `namespace fl` root scope in
  `src/fl/**/*.h` whose name matches `^(set|enable|disable|use)_[a-z]`
  MUST have a matching `CFastLED::setX()` / `enableX()` / `disableX()`
  wrapper in `src/FastLED.h` that delegates to it.

Carve-outs (NOT flagged):
  - Sub-namespaces (fl::detail::, fl::isr::, fl::colorimetric_detail::, …)
  - Anonymous namespaces
  - Class/struct member functions (per-object setters)
  - Function-pointer installers (set_rgb_2_rgbw_function, set_rgb_2_rgbww_function)
  - Per-object mutators: non-const ptr/ref to user-defined type as first param
  - Lines suppressed with `// nolint` or `// ok public_settings`

Grandfathered allowlist (pre-rule offenders, not flagged):
  set_rgbw_colorimetric_profile, set_input_gamut (from #2715 description),
  enable_rgbw_colorimetric_lut, disable_rgbw_colorimetric_lut (#2545),
  set_rgbww_colorimetric_profile (#2558).

Implementation notes:
  - Uses a per-`{` scope stack (not a simple brace counter) so that enum
    bodies, inline function definitions, and nested namespaces are all tracked
    correctly without false namespace pops.
  - FastLED.h is loaded once at `__init__` time for cross-file wrapper lookup.
  - 63 unit tests; `bash lint --cpp` passes clean on the full codebase.
  - Registered in the `fl` scope in run_all_checkers.py.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 81bad945-a2bc-43dc-aa95-94a4ac58f6f6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/public-settings-pattern-lint-checker

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 and usage tips.

Pyright (--strict) flagged `first_param` as `list[Unknown]` since it's
initialized as a bare `[]`. The list only ever holds str characters
from iterating `params_raw` (a str), so the annotation is `list[str]`.

Drive-by while reviewing the agent-generated PR #2716.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 07ea2c4 into chore/cpp-style-public-settings-pattern Jun 3, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 3, 2026
zackees added a commit that referenced this pull request Jun 4, 2026
…layer 5) (#2716)

* feat(lint): enforce Public Settings Pattern for fl:: global setters

Adds `PublicSettingsPatternChecker` (ci/lint_cpp/public_settings_pattern_checker.py)
— layer 5 of the six-layer Public Settings Pattern enforcement plan introduced
in PR #2715 / docs commit d51a8f6.

What it checks:
  Every public free function declared at `namespace fl` root scope in
  `src/fl/**/*.h` whose name matches `^(set|enable|disable|use)_[a-z]`
  MUST have a matching `CFastLED::setX()` / `enableX()` / `disableX()`
  wrapper in `src/FastLED.h` that delegates to it.

Carve-outs (NOT flagged):
  - Sub-namespaces (fl::detail::, fl::isr::, fl::colorimetric_detail::, …)
  - Anonymous namespaces
  - Class/struct member functions (per-object setters)
  - Function-pointer installers (set_rgb_2_rgbw_function, set_rgb_2_rgbww_function)
  - Per-object mutators: non-const ptr/ref to user-defined type as first param
  - Lines suppressed with `// nolint` or `// ok public_settings`

Grandfathered allowlist (pre-rule offenders, not flagged):
  set_rgbw_colorimetric_profile, set_input_gamut (from #2715 description),
  enable_rgbw_colorimetric_lut, disable_rgbw_colorimetric_lut (#2545),
  set_rgbww_colorimetric_profile (#2558).

Implementation notes:
  - Uses a per-`{` scope stack (not a simple brace counter) so that enum
    bodies, inline function definitions, and nested namespaces are all tracked
    correctly without false namespace pops.
  - FastLED.h is loaded once at `__init__` time for cross-file wrapper lookup.
  - 63 unit tests; `bash lint --cpp` passes clean on the full codebase.
  - Registered in the `fl` scope in run_all_checkers.py.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* fix(lint): annotate first_param list type in public_settings checker

Pyright (--strict) flagged `first_param` as `list[Unknown]` since it's
initialized as a bare `[]`. The list only ever holds str characters
from iterating `params_raw` (a str), so the annotation is `list[str]`.

Drive-by while reviewing the agent-generated PR #2716.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
zackees added a commit that referenced this pull request Jun 4, 2026
* docs(cpp): enforce Public Settings Pattern for global setters

Codifies the long-implicit rule that new library-wide configuration
setters must be exposed on the `CFastLED` god instance (e.g.
`FastLED.setX(...)`) rather than as bare `fl::set_x(...)` free
functions. The free function may exist for ADL / testability, but
the documented call site is the god instance.

Motivated by PR #2711, which added `fl::set_input_gamut(...)` as a
free function only — following the unwrapped precedent of
`fl::set_rgbw_colorimetric_profile`. Neither has a `FastLED.setX()`
entry point, so users don't discover them. Both are now grandfathered
exceptions; new code must wrap.

Changes:
- `agents/docs/cpp-standards.md`: New "Public Settings Pattern" section
  with rules, exemplar (`setPowerModel` → `set_power_model`), and a
  grandfathered allowlist.
- `CLAUDE.md`: One-liner pointer in the task table and Code Standards
  section so agents see the rule on entry.
- `.coderabbit.yaml`: `path_instructions` for `src/fl/**/*.h`,
  `src/FastLED.h`, and `src/fl/gfx/**` telling CodeRabbit to flag bare
  new `fl::set_* / enable_* / disable_* / use_*` declarations without
  a matching `CFastLED` wrapper as HIGH severity, with the
  grandfathered allowlist honored.
- `.claude/agents/architecture-reviewer-agent.md`: API Surface check
  step gains a "Public Settings Pattern enforcement" subsection.
- `.claude/commands/code_review.md`: New rule block before "SIGNED
  INTEGER OVERFLOW", plus a counter in the violations summary.
- `src/FastLED.h`: Backfills `CFastLED::setRgbwColorimetricProfile()`
  and `getRgbwColorimetricProfile()` — thin `inline` delegators to the
  existing `fl::` free functions. `setInputGamut` is intentionally left
  for PR #2711 to add alongside its own free function (it isn't on
  master yet).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* docs(cpp): drop grandfathered allowlist; require wrapper for all global setters

Removes the grandfathered exceptions section from the Public Settings
Pattern docs. Both names that were allowlisted in the initial commit of
this PR were introduced after the policy itself was being defined, so
neither was historically grandfathered:

- `fl::set_rgbw_colorimetric_profile` is already wrapped on `CFastLED`
  (`CFastLED::setRgbwColorimetricProfile`) in this PR, so it no longer
  needs an exception.
- `fl::set_input_gamut` (#2710) is introduced in PR #2711 without a
  `CFastLED` wrapper. The wrapper must be added before that PR merges.

Updated files:
- `.coderabbit.yaml`
- `agents/docs/cpp-standards.md`
- `.claude/agents/architecture-reviewer-agent.md`
- `.claude/commands/code_review.md`

Addresses CodeRabbit review on PR #2715.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* feat(lint): enforce Public Settings Pattern for fl:: global setters (layer 5) (#2716)

* feat(lint): enforce Public Settings Pattern for fl:: global setters

Adds `PublicSettingsPatternChecker` (ci/lint_cpp/public_settings_pattern_checker.py)
— layer 5 of the six-layer Public Settings Pattern enforcement plan introduced
in PR #2715 / docs commit d51a8f6.

What it checks:
  Every public free function declared at `namespace fl` root scope in
  `src/fl/**/*.h` whose name matches `^(set|enable|disable|use)_[a-z]`
  MUST have a matching `CFastLED::setX()` / `enableX()` / `disableX()`
  wrapper in `src/FastLED.h` that delegates to it.

Carve-outs (NOT flagged):
  - Sub-namespaces (fl::detail::, fl::isr::, fl::colorimetric_detail::, …)
  - Anonymous namespaces
  - Class/struct member functions (per-object setters)
  - Function-pointer installers (set_rgb_2_rgbw_function, set_rgb_2_rgbww_function)
  - Per-object mutators: non-const ptr/ref to user-defined type as first param
  - Lines suppressed with `// nolint` or `// ok public_settings`

Grandfathered allowlist (pre-rule offenders, not flagged):
  set_rgbw_colorimetric_profile, set_input_gamut (from #2715 description),
  enable_rgbw_colorimetric_lut, disable_rgbw_colorimetric_lut (#2545),
  set_rgbww_colorimetric_profile (#2558).

Implementation notes:
  - Uses a per-`{` scope stack (not a simple brace counter) so that enum
    bodies, inline function definitions, and nested namespaces are all tracked
    correctly without false namespace pops.
  - FastLED.h is loaded once at `__init__` time for cross-file wrapper lookup.
  - 63 unit tests; `bash lint --cpp` passes clean on the full codebase.
  - Registered in the `fl` scope in run_all_checkers.py.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* fix(lint): annotate first_param list type in public_settings checker

Pyright (--strict) flagged `first_param` as `list[Unknown]` since it's
initialized as a bare `[]`. The list only ever holds str characters
from iterating `params_raw` (a str), so the annotation is `list[str]`.

Drive-by while reviewing the agent-generated PR #2716.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>

* docs(cpp): align grandfathered allowlist text with checker

CodeRabbit (#2715 thread on agents/docs/cpp-standards.md:262) flagged
that the "No grandfathered offenders" wording contradicted the actual
enforcement state: public_settings_pattern_checker.py still carries a
small GRANDFATHERED_NAMES allowlist for legacy bare setters that have
not yet received CFastLED wrappers (set_input_gamut,
enable_rgbw_colorimetric_lut, disable_rgbw_colorimetric_lut,
set_rgbww_colorimetric_profile).

Reconcile the policy text in cpp-standards.md, architecture-reviewer-
agent.md, and code_review.md to describe the transitional allowlist
explicitly: strict for *new* code, shrinking allowlist for legacy
names, entries removed as wrappers land. The behavior of the rule is
unchanged; only the documentation matches reality now.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the feat/public-settings-pattern-lint-checker branch August 21, 2026 19:15
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.

1 participant