Skip to content

docs(cpp): enforce Public Settings Pattern for global setters - #2715

Merged
zackees merged 4 commits into
masterfrom
chore/cpp-style-public-settings-pattern
Jun 4, 2026
Merged

zackees merged 4 commits into
masterfrom
chore/cpp-style-public-settings-pattern

Conversation

@zackees

@zackees zackees commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

Motivation

Triggered by PR #2711, which added fl::set_input_gamut(...) as a bare free function — following the pre-existing pattern of fl::set_rgbw_colorimetric_profile. Neither has a FastLED.setX() god-instance entry point, so users discover and document the wrong call site (the fl:: free function), and the library's public surface drifts out of sync with the documented exemplar (FastLED.setPowerModel → fl::set_power_model, src/FastLED.h:1455).

The codebase has the correct pattern (setPowerModel), but it wasn't written down. AI agents and humans both followed the unwrapped neighbor instead. This PR writes the rule down and adds enforcement at four layers so the drift stops.

Six-layer enforcement plan (this PR does layers 1–4)

Layer What Status
1. Documentation agents/docs/cpp-standards.md → "Public Settings Pattern" done in this PR
1b. Index CLAUDE.md table + Code Standards section pointer done in this PR
2. AI review .coderabbit.yaml path_instructions for src/fl/**/*.h, src/FastLED.h, src/fl/gfx/** done in this PR
3a. Architecture review architecture-reviewer-agent system prompt done in this PR
3b. Slash command /code_review checklist + summary counter done in this PR
4. Backfill exemplar CFastLED::setRgbwColorimetricProfile + getter done in this PR
4b. Backfill setInputGamut wait for PR #2711 to land OR fold into #2711 follow-up
5. Lint check cpp-linter-builder-agent writes a syntactic check dispatching in background

What the rule says

New library-wide configuration setters (fl::set_*, fl::enable_*, fl::disable_*, fl::use_* that mutate global / namespace-scope / static state) MUST be exposed on the CFastLED god instance as a thin inline delegator. The free function may exist for ADL / testability; the documented user-facing entry point is FastLED.setX(...).

Grandfathered (predate the rule — do not flag for these names alone):

Changes

  • agents/docs/cpp-standards.md — New "Public Settings Pattern" section with rules, the setPowerModel exemplar, grandfathered allowlist, and a "doesn't apply to" carve-out for helpers / per-object config / fl::detail::.
  • CLAUDE.md — Adds a row to the task table and a bullet under Code Standards so agents see the rule on entry.
  • .coderabbit.yaml — Adds path_instructions blocks teaching CodeRabbit to flag bare new fl::set_* free functions in src/fl/**/*.h that lack a CFastLED wrapper. Also covers src/FastLED.h (delegate-don't-embed) and src/fl/gfx/** (where the recent offender lives). Grandfathered names called out by name.
  • .claude/agents/architecture-reviewer-agent.md — Adds a "Public Settings Pattern enforcement" subsection under API Surface, with HIGH severity and the canned violation language.
  • .claude/commands/code_review.md — New rule block before "SIGNED INTEGER OVERFLOW", plus a "Public Settings Pattern violations" counter in the violations summary.
  • src/FastLED.h — Adds #include "fl/gfx/rgbw.h" and a "RGBW Colorimetric Configuration" group on CFastLED containing setRgbwColorimetricProfile(const fl::DiodeProfile*) and getRgbwColorimetricProfile(). Both are thin inline delegators to the existing free functions in fl::, matching the setPowerModel exemplar exactly.

Test plan

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added RGBW colorimetric profile configuration support via two new public methods for managing diode color profiles.
  • Chores

    • Updated code review standards and linting infrastructure to enforce consistency in global configuration API design.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR establishes the "Public Settings Pattern" architectural rule: library-wide configuration mutators in the fl:: namespace must be surfaced via thin CFastLED inline delegating wrappers. Documentation, review automation, a Python linter with comprehensive tests, and RGBW colorimetric profile wrappers enforce and exemplify this pattern.

Changes

Public Settings Pattern enforcement

Layer / File(s) Summary
Pattern definition and coding standards
agents/docs/cpp-standards.md, CLAUDE.md, .claude/agents/architecture-reviewer-agent.md
Added the Public Settings Pattern specification to C++ coding standards and agent guidance, requiring new global configuration setters to be exposed via CFastLED inline delegators to fl:: free functions, with no grandfathered exceptions.
Automated review rule enforcement
.claude/agents/architecture-reviewer-agent.md, .claude/commands/code_review.md, .coderabbit.yaml
Updated architecture reviewer prompt, code review checklist, and CodeRabbit path instructions to detect setter-like fl:: functions and flag HIGH-severity violations when CFastLED inline wrappers are missing.
Public settings pattern linter implementation
ci/lint_cpp/public_settings_pattern_checker.py
Implements PublicSettingsPatternChecker to scan src/fl/**/*.h for namespace-scope setter-like declarations, apply carve-outs (grandfathered names, per-object setters, function-pointer callbacks, suppression tokens), and cross-check src/FastLED.h for required CFastLED wrapper methods.
Linter unit test coverage
ci/lint_cpp/test_public_settings_pattern_checker.py
Comprehensive unittest suite validating file filtering, positive/negative detection, allowlist behavior, per-object and function-pointer carve-outs, comment exemptions, suppression tokens, cross-file wrapper checks, and tricky scope-parsing edge cases.
RGBW wrapper API and linter integration
src/FastLED.h, ci/lint_cpp/run_all_checkers.py
Adds CFastLED::setRgbwColorimetricProfile() and getRgbwColorimetricProfile() inline wrappers delegating to fl::set_rgbw_colorimetric_profile and fl::get_rgbw_colorimetric_profile; registers PublicSettingsPatternChecker in the unified lint runner.

Sequence Diagram(s)

sequenceDiagram
  participant Developer
  participant Linter
  participant FastLED_h
  participant Report
  Developer->>Linter: run checker on src/fl/**/*.h
  Linter->>Linter: scan for set_*/enable_*/disable_*/use_* functions
  Linter->>Linter: apply carve-outs & suppressions
  Linter->>FastLED_h: search for CFastLED wrapper methods
  FastLED_h-->>Linter: wrapper found or not found
  Linter->>Report: record violation with required wrapper name
  Report-->>Developer: HIGH-severity: missing CFastLED wrapper
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

The PR spans multiple file categories (docs, agent rules, Python linter with core logic + helpers, comprehensive test suite, and C++ API wrappers) with mixed complexity. The linter implementation requires careful review of scope tracking, carve-out heuristics, and cross-file wrapper detection; the test suite is extensive but systematic. Documentation and rule updates are straightforward and consistent across files.

Possibly related PRs

  • FastLED/FastLED#2689: Both PRs integrate with the C++ lint runner pipeline (ci/lint_cpp/run_all_checkers.py); this PR adds PublicSettingsPatternChecker while the related PR adds Rust integration.
  • FastLED/FastLED#2552: This PR's new CFastLED::setRgbwColorimetricProfile and getRgbwColorimetricProfile wrappers directly delegate to the related PR's fl::set_rgbw_colorimetric_profile and fl::get_rgbw_colorimetric_profile functions.
  • FastLED/FastLED#2711: The related PR adds fl::set_input_gamut with CFastLED::setInputGamut wrappers, exemplifying the Public Settings Pattern that this PR formally documents and enforces.

Poem

A Settings Pattern hops through code so bright,
Global knobs wrapped in the CFastLED light—
Free functions delegate, inline they stay,
No grandfathered exceptions lead astray! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the primary change: enforcing a Public Settings Pattern for global configuration setters through documentation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/cpp-style-public-settings-pattern

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.

@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 @.coderabbit.yaml:
- Around line 28-31: Remove the grandfathered symbol
fl::set_rgbw_colorimetric_profile from the allowlist entries: delete the list
item in .coderabbit.yaml and the mirrored occurrences in
agents/docs/cpp-standards.md, .claude/agents/architecture-reviewer-agent.md, and
.claude/commands/code_review.md so that only fl::set_input_gamut remains; this
aligns the policy with the newly backfilled CFastLED::setRgbwColorimetricProfile
implementation and ensures the enforcement no longer exempts the old name.
🪄 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

Run ID: 3b7e304b-3587-4304-8465-6238aac644f3

📥 Commits

Reviewing files that changed from the base of the PR and between d44fc1d and d51a8f6.

📒 Files selected for processing (6)
  • .claude/agents/architecture-reviewer-agent.md
  • .claude/commands/code_review.md
  • .coderabbit.yaml
  • CLAUDE.md
  • agents/docs/cpp-standards.md
  • src/FastLED.h

Comment thread .coderabbit.yaml Resolved
zackees added a commit that referenced this pull request Jun 3, 2026
…agma keep

Pre-existing IWYU violation flagged by the Stop hook's lint run. The
`IwyuPragmaBlockChecker` requires system headers like `freertos/*.h` to
carry an explicit `// IWYU pragma: keep` (or be wrapped in
`begin_keep`/`end_keep`) so IWYU doesn't propose dropping them.

Untouched by PR #2715's main work, but landing on the same branch under
the project's "fix all encountered errors immediately" policy.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 3, 2026
…al 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]>
zackees added a commit that referenced this pull request Jun 3, 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 3, 2026
…attern

`fl::set_input_gamut` (#2710) is a library-wide global setter. Under the
Public Settings Pattern in agents/docs/cpp-standards.md, every public
fl:: global setter must ship with a thin inline `CFastLED` wrapper that
becomes the documented user-facing call site. The two-arg and three-arg
overloads now have matching `CFastLED::setInputGamut` wrappers.

Removes the implicit grandfathered exception this function was relying
on in PR #2715 — that PR's follow-up commit explicitly dropped the
allowlist, so this wrapper is now required before merge rather than
deferred.

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

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

🧹 Nitpick comments (1)
ci/lint_cpp/test_public_settings_pattern_checker.py (1)

41-65: 💤 Low value

Test helper functions use default parameter values.

Per coding guidelines, Python function parameters must not have default values. These helpers use path: str = _FL_PATH and fastled_h: str = "". While this violates the strict guideline, it significantly improves test readability and is acceptable for internal test helpers. As per coding guidelines: "All function parameters MUST have explicit type annotations and MUST NOT have default values".

🤖 Prompt for 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.

In `@ci/lint_cpp/test_public_settings_pattern_checker.py` around lines 41 - 65,
The helper functions _make and _violations currently define default parameter
values (path: str = _FL_PATH, fastled_h: str = ""), which violates the
no-default-parameters rule; remove the defaults so signatures are _make(code:
str, path: str, fastled_h: str) and _violations(code: str, path: str, fastled_h:
str), then update all local test call sites to pass _FL_PATH and the fastled_h
string explicitly (or appropriate values) when invoking _make and _violations to
preserve existing behavior.
🤖 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.

Nitpick comments:
In `@ci/lint_cpp/test_public_settings_pattern_checker.py`:
- Around line 41-65: The helper functions _make and _violations currently define
default parameter values (path: str = _FL_PATH, fastled_h: str = ""), which
violates the no-default-parameters rule; remove the defaults so signatures are
_make(code: str, path: str, fastled_h: str) and _violations(code: str, path:
str, fastled_h: str), then update all local test call sites to pass _FL_PATH and
the fastled_h string explicitly (or appropriate values) when invoking _make and
_violations to preserve existing behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dadd1a1c-de0d-439f-89f2-cf44cd64adcc

📥 Commits

Reviewing files that changed from the base of the PR and between f30f04e and 07ea2c4.

📒 Files selected for processing (3)
  • ci/lint_cpp/public_settings_pattern_checker.py
  • ci/lint_cpp/run_all_checkers.py
  • ci/lint_cpp/test_public_settings_pattern_checker.py

zackees added a commit that referenced this pull request Jun 3, 2026
#2711)

* fix(rgbw): default source = native LED gamut + D65; named-gamut opt-in (#2710)

Closes #2710.

#2705 added the source-RGB → LED-XYZ transform with `kRgbwDefaultProfile`
defaulting to Rec709/sRGB primaries + D65. That silently clipped saturated
inputs to the sRGB sub-volume of the LED's native gamut — `RGB=(255,0,0)`
on a typical SK6812 strip drove the LED red diode to ~70 % of its
capability, leaving the rest unreachable through the public API.

Flips the default to **native LED gamut + D65 white**:
  - `kRgbwDefaultProfile.input_xy_r/g/b` now mirror the profile's own
    LED `xy_r/g/b` (was sRGB), so saturated inputs hit the LED gamut at
    full saturation.
  - `input_xy_w` stays at D65 so neutral inputs land on a standard
    daylight white.
  - Same applies to `kRgbwwDefaultProfile` (RGBWW warm + cool paths).

Adds a small opt-in API for users who explicitly want standard
color-space input semantics:

    enum class InputGamut : u8 {
        Native, Rec709, Rec2020, DciP3D65, DciP3D60
    };
    void set_input_gamut(DiodeProfile* profile, InputGamut g) noexcept;
    void set_input_gamut(DiodeProfile* profile, InputGamut g,
                         const float white_xy[2]) noexcept;

Users with sRGB content (ambilight, video bridges) write one line at
setup: `fl::set_input_gamut(&my_profile, fl::InputGamut::Rec709);`. The
white-override overload covers niche cases like D50 photography workflow
or D60 ACES theatrical mastering.

Tests
=====
- `default profile carries native-LED + D65 source space (#2710)` —
  asserts input_xy_* mirror xy_* and input_xy_w == D65.
- `source matrix matches published sRGB->XYZ matrix (Rec709 opt-in)` —
  the existing sRGB matrix-derivation check now opts into Rec709 via
  set_input_gamut() before building M_src.
- `set_input_gamut: Native copies LED primaries` — trashes input_xy_*
  then proves Native restores them from xy_*.
- `set_input_gamut: named gamuts populate canonical primaries` —
  hits Rec709 / Rec2020 / DCI-P3 D65 / DCI-P3 D60 and asserts canonical
  primary + white-point values.
- `set_input_gamut: white override honored` — covers the overload that
  takes a custom white (D50 in the test).
- `set_input_gamut: null profile is a no-op` — defensive guard parity
  with `set_rgbw_colorimetric_profile(nullptr)`.

Drive-by
========
Removes `compare_rgbw.py`, a one-off scratch comparison harness that
slipped into master via #2709's squash-merge despite being deleted on
the branch.

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

* chore(ci): apply ruff format drift

bash lint reformatted three CI files during PR #2711 review work. No
functional change — purely line-break/whitespace adjustments that ruff
flagged as drift from the current format profile.

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

* fix(rgbw): address CodeRabbit review on #2711

Three follow-ups from the CodeRabbit review:

1. **(major) Cache invalidation on in-place gamut mutation** —
   set_input_gamut() rewrites profile->input_xy_* in place, but the
   ColorimetricCacheHolder and LutStateHolder are keyed on (profile_ptr,
   cct). Without invalidation, the cache held stale M_src/LUT entries
   after a gamut switch on the currently active profile, producing
   deterministic wrong colors. Now the active per-process caches are
   evicted whenever set_input_gamut() mutates a profile that matches
   the cache key. No-op in the FASTLED_RGBW_COLORIMETRIC=0 build (no
   cache exists to invalidate).

2. **(contract) white_xy doc mismatch** — The header doc said the
   `white_xy` override "must point to a 2-float array" but the impl
   already accepted nullptr as "use the gamut's reference white"
   (equivalent to the 2-arg overload). Doc now matches behavior. Kept
   the raw-array signature instead of switching to fl::span<const
   float, 2> — the header sits low in the include graph and pulling
   fl/stl/span.h here would be a heavier change than the contract bug
   warrants; the 2-arg overload remains the recommended call site for
   the default-white path.

3. **(nitpick) RGBWW native-gamut guard** — Added an explicit test
   asserting kRgbwwDefaultProfile.warm_path / cool_path keep
   input_xy_* mirroring xy_* and input_xy_w pinned at D65. Symmetric
   to the existing assertion at rgbw_colorimetric.cpp:252-272; locks
   the native-LED-gamut contract on both warm and cool paths so future
   chromaticity retuning can't silently desync source from emitter.

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

* docs(cpp): wrap fl::set_input_gamut on CFastLED per Public Settings Pattern

`fl::set_input_gamut` (#2710) is a library-wide global setter. Under the
Public Settings Pattern in agents/docs/cpp-standards.md, every public
fl:: global setter must ship with a thin inline `CFastLED` wrapper that
becomes the documented user-facing call site. The two-arg and three-arg
overloads now have matching `CFastLED::setInputGamut` wrappers.

Removes the implicit grandfathered exception this function was relying
on in PR #2715 — that PR's follow-up commit explicitly dropped the
allowlist, so this wrapper is now required before merge rather than
deferred.

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 3, 2026
…agma keep

Same pre-existing IWYU violation as on PR #2715 — this branch was cut
from master before that fix landed, so the linter flags it again. Same
one-line fix: `// IWYU pragma: keep` on each freertos system header.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 4, 2026
…2717) (#2718)

* docs(cpp): add 8 code-gen rules from 2-week CodeRabbit survey

Closes #2717.

Adds 8 new rules to agents/docs/cpp-standards.md capturing the recurring
themes CodeRabbit flagged across 94 PRs (2026-05-20 → 2026-06-03, 59
with CodeRabbit activity, ~95 substantive findings). All 8 are
preventable at code-generation time with a written rule.

Rules added (in order, append-only at end of file):

1. Singleton-Stored Configuration: Own by Value, Never by Borrowed
   Pointer — prevents use-after-scope when callers pass a stack
   temporary to a `set_X(const T*)` that stashes the pointer in process
   state. Pairs with the Public Settings Pattern (PR #2715 — where the
   setter lives; this rule — how it stores the value).

2. In-Place Profile Mutation Bumps a Version — cache-invalidation
   contract for `set_X(T* obj, ...)` patterns. Without a version bump
   and key, derived-value caches keyed on `(obj_ptr, ...)` return
   stale data when the same pointer is mutated across frames.

3. Contract Change Fanout — broadens the existing "API Unit Change"
   rule (§595-604) from `_ms` / `_us` suffixes to any bound, enum
   range, or struct shape change. PRs must touch producer +
   validator + tests + docs + debug-metrics in one diff.

4. `fl::span` for Callback Typedefs and Small Fixed-Size Arrays —
   extends the existing span rule with two shapes that kept slipping
   through: `fl::function<...(const u8*, size_t)>` typedefs and
   `const float xy[2]` fixed-size arrays.

5. ISR-Shared State: `fl::atomic` or Critical Section, Never Bare
   `volatile` — uses `fl::atomic<T>` (not `std::atomic`, per the
   project-wide "prefer fl:: over std::" rule) with explicit memory
   order, OR `portENTER_CRITICAL_ISR` guarded access. Plain `volatile`
   is not sufficient on dual-core MCUs.

6. Unsigned Narrowing Cast Must Clamp — sibling to the existing
   Signed Integer Overflow rule. `static_cast<u8>(x)` wraps silently
   when x > 255 — defined behavior, wrong behavior. The signed-UB
   rule explicitly does NOT cover this case.

7. Test Mirrors Must Call Production Symbols, Not Redeclare Them —
   local lambda re-implementations in test files silently pass when
   the production code regresses. Test must `#include` and call the
   production symbol.

8. ASCII-Only in Source Files — emoji and Unicode math glyphs
   (`⚠️`, `×`, `−`, `ρ`, `∆`) in C++ comments and Python source
   confuse toolchains and obscure compile errors. Markdown (`*.md`)
   files exempt.

Rule dropped from the original recommendation: mirror the
KeyboardInterrupt pattern into `agents/docs/python-standards.md` — on
inspection the rule is already present there at lines 17-46. The
recurring violations come from agents reading other docs first; that
is a discovery problem, not a documentation gap.

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

* fix(iwyu): wrap freertos includes in lcd_spi clockless driver with pragma keep

Same pre-existing IWYU violation as on PR #2715 — this branch was cut
from master before that fix landed, so the linter flags it again. Same
one-line fix: `// IWYU pragma: keep` on each freertos system header.

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

* docs(cpp): address CodeRabbit nitpicks on PR #2718

Two "Quick win" nitpicks from CodeRabbit on the survey-rules PR:

1. **Rule 1 (Singleton-Stored Configuration)** — softens the "MUST take
   const T&" wording to allow `const T*` parameters when the pointer
   is used as a nullable-reset signal (nullptr → revert to default).
   The existing `set_rgbww_colorimetric_profile(const T*)` is the
   in-repo example of this idiom; it copies on non-null and resets on
   null, which is correct even though the parameter shape is `T*`.
   The HIGH-severity flag now fires only when BOTH parameter and
   storage are `const T*` (the actual use-after-scope shape).

2. **Rule 4 (`fl::span` for callback typedefs)** — adds a scoped
   exception for deferred legacy migrations. A `(ptr, size)` typedef
   may be retained temporarily when migrating all callers in one PR
   isn't tractable, provided the typedef site carries a comment
   pointing at the tracking issue and the exception is timeboxed.
   Cited example: `src/fl/stl/cstdio.h`. Without this carve-out the
   rule would push engineers toward unprincipled mixed APIs.

Both rules remain "use value semantics / spans by default" — the
exceptions are explicit, documented, and bounded.

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees and others added 3 commits June 4, 2026 10:42
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]>
…al 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]>
…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
zackees force-pushed the chore/cpp-style-public-settings-pattern branch from 07ea2c4 to 692a090 Compare June 4, 2026 17:43

@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 `@agents/docs/cpp-standards.md`:
- Around line 262-268: The policy text claiming "No grandfathered offenders"
conflicts with the current checker which honors GRANDFATHERED_NAMES and the PR
note that fl::set_input_gamut is temporarily grandfathered; update
agents/docs/cpp-standards.md (the paragraph around the "No grandfathered
offenders" rule) to reflect the actual enforcement state by either (A) removing
the absolute "no grandfathered" statement and documenting the temporary
grandfathering mechanism and its allowed names (referencing GRANDFATHERED_NAMES
and fl::set_input_gamut), or (B) if you intend to remove grandfathering, change
the checker ci/lint_cpp/public_settings_pattern_checker.py to eliminate the
GRANDFATHERED_NAMES path and then update the doc to state the strict
no-grandfather rule—make sure the doc text and the checker
(public_settings_pattern_checker.py and the specific GRANDFATHERED_NAMES symbol)
are consistent.
🪄 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

Run ID: 556ea304-2e35-4aca-9d3b-929327e05b9c

📥 Commits

Reviewing files that changed from the base of the PR and between 07ea2c4 and 692a090.

📒 Files selected for processing (9)
  • .claude/agents/architecture-reviewer-agent.md
  • .claude/commands/code_review.md
  • .coderabbit.yaml
  • CLAUDE.md
  • agents/docs/cpp-standards.md
  • ci/lint_cpp/public_settings_pattern_checker.py
  • ci/lint_cpp/run_all_checkers.py
  • ci/lint_cpp/test_public_settings_pattern_checker.py
  • src/FastLED.h
✅ Files skipped from review due to trivial changes (1)
  • CLAUDE.md
🚧 Files skipped from review as they are similar to previous changes (6)
  • ci/lint_cpp/run_all_checkers.py
  • .coderabbit.yaml
  • .claude/agents/architecture-reviewer-agent.md
  • src/FastLED.h
  • ci/lint_cpp/public_settings_pattern_checker.py
  • ci/lint_cpp/test_public_settings_pattern_checker.py

Comment thread agents/docs/cpp-standards.md Resolved
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]>
@zackees
zackees merged commit 8d1e04e into master Jun 4, 2026
13 of 14 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 4, 2026
@zackees
zackees deleted the chore/cpp-style-public-settings-pattern branch June 5, 2026 04:43
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