Skip to content

feat(lint): ban raw C printf-family in src/ — use fl::snprintf (#2773 item 1.5) - #2777

Merged
zackees merged 1 commit into
feat/2773-eliminate-c-snprintffrom
feat/2773-printf-lint
Jun 5, 2026
Merged

zackees merged 1 commit into
feat/2773-eliminate-c-snprintffrom
feat/2773-printf-lint

Conversation

@zackees

@zackees zackees commented Jun 5, 2026

Copy link
Copy Markdown
Member

Summary

Adds CstdioPrintfChecker to the unified ci/lint_cpp/ pipeline that
fails CI on direct C snprintf / printf / sprintf / fprintf /
vfprintf / vsnprintf / vprintf / vsprintf / vfiprintf calls
inside src/. Implements item 1.5 of the binary-size meta-issue:
#2773 — the regression guard for the cleanup landed in #2774.

Each such call drags newlib's _svfprintf_r (~11 KB on xtensa-esp-elf)
into libFastLED.a. The repo already ships fl::snprintf and
fl::printf at src/fl/stl/stdio.h:659 which route through
fl::sstream and don't need the libc engine.

Depends on #2774 — based on feat/2773-eliminate-c-snprintf so
the linter validates against clean code. If rebased on master before
#2774 merges, the linter would fail on the 12 pre-existing call sites
that PR migrates. After #2774 merges, this PR can be retargeted to
master.

Allowed forms (covered by tests)

  • fl::snprintf(...), fl::printf(...) — the FastLED wrappers.
  • obj.printf(...), ptr->printf(...) — member access.
  • SerialPort::printf(...), MyClass::snprintf(...) — user-defined
    class methods (qualified by an identifier other than std).
  • void printf(const char* fmt, ...) inside a class body — function
    declarations / definitions (the prefix ends with a type, not ::).
  • my_snprintf(...) — sub-word matches (defensive; \b already covers).

Banned forms (covered by tests)

  • bare snprintf(...), printf(...), fprintf(...), etc.
  • explicit ::printf(...) — root-namespace C call.
  • explicit std::snprintf(...) — C++ std namespace (still newlib).

Excluded paths (don't link newlib)

  • src/third_party/** — third-party code defines its own conventions.
  • src/fl/stl/stdio.{h,hpp} + src/fl/stl/cstdio.* — wrapper TUs that
    bridge at the C-API boundary.
  • src/platforms/wasm/** — Emscripten libc, console-write.
  • src/platforms/{posix,apple,win}/** — host-only test runners.
  • src/platforms/stub/** — host-only stub.

Opt-out

Append // ok cstdio - <reason> on the same line for genuine
platform-boundary cases.

Test plan

  • 26 unit tests (ci/lint_cpp/test_cstdio_printf_checker.py): every
    allowed/banned/opt-out/exclusion case → 26/26 pass.
  • Standalone runner against entire `src/`: zero violations after
    refactor(printf): replace C snprintf with fl::snprintf in libFastLED.a (#2773 batch-1 item 1.1) #2774's migration.
  • Full bash lint pipeline: clean.
  • Registered in ci/lint_cpp/run_all_checkers.py under the src
    scope alongside the existing CtypeGlobalChecker (same shape: ban
    C free-function APIs that have fl:: template wrappers).
  • CI green.

Files

Issue: #2773

🤖 Generated with Claude Code

…item 1.5)

Adds `CstdioPrintfChecker` to the unified `ci/lint_cpp/` pipeline that
fails CI on direct C `snprintf` / `printf` / `sprintf` / `fprintf` /
`vfprintf` / `vsnprintf` / `vprintf` / `vsprintf` / `vfiprintf` calls
inside `src/`. Implements item **1.5** of the binary-size meta-issue
(#2773) — the regression guard for the cleanup landed in #2774.

Each such call drags newlib's `_svfprintf_r` (~11 KB on xtensa-esp-elf)
into `libFastLED.a`. The repo already ships `fl::snprintf` and
`fl::printf` at `src/fl/stl/stdio.h:659` which route through
`fl::sstream` and don't need the libc engine.

## Allowed forms (verified by tests)

- `fl::snprintf(...)`, `fl::printf(...)` — the FastLED wrappers.
- `obj.printf(...)`, `ptr->printf(...)` — member access.
- `SerialPort::printf(...)`, `MyClass::snprintf(...)` — any
  user-defined class method (qualified by an identifier other than `std`).
- `void printf(const char* fmt, ...)` — function declarations / definitions
  inside a class body (the prefix ends with a type identifier, not `::`).
- `my_snprintf(...)` — sub-word matches (defensive; `\b` already covers).

## Banned forms (verified by tests)

- bare `snprintf(...)`, `printf(...)`, etc. — no prefix.
- explicit `::printf(...)` — root-namespace C call.
- explicit `std::snprintf(...)` — C++ std namespace (still newlib on xtensa).

## Excluded paths (don't link newlib)

- `src/third_party/**` — third-party code defines its own conventions.
- `src/fl/stl/stdio.{h,hpp}` + `src/fl/stl/cstdio.*` — wrapper TUs that
  bridge at the C-API boundary.
- `src/platforms/wasm/**` — Emscripten libc, console-write.
- `src/platforms/{posix,apple,win}/**` — host-only test runners.
- `src/platforms/stub/**` — host-only stub.

## Opt-out

Append `// ok cstdio - <reason>` on the same line for genuine
platform-boundary cases.

## Verification

- 26 unit tests covering every allowed/banned/opt-out/exclusion case
  (`ci/lint_cpp/test_cstdio_printf_checker.py`): 26/26 pass.
- Full `bash lint` pipeline: clean, zero violations on `src/` after
  #2774 lands the snprintf → fl::snprintf migration.
- Registered in `ci/lint_cpp/run_all_checkers.py` under the `src` scope
  alongside the existing `CtypeGlobalChecker` (same shape: ban C
  free-function APIs that have `fl::` template wrappers).

Depends on #2774 — if rebased on master before that PR merges, the
linter would fail on the 12 pre-existing `snprintf` call sites the
PR migrates.

Issue: #2773

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

coderabbitai Bot commented Jun 5, 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: 49704eec-e098-4a8d-9575-4c235bdeb177

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/2773-printf-lint

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.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 5, 2026
@zackees
zackees merged commit 55bde0a into feat/2773-eliminate-c-snprintf Jun 5, 2026
1 check passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 5, 2026
@zackees
zackees deleted the feat/2773-printf-lint 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