Skip to content

Move replace_token to component as replace_all#60

Merged
edwardtfn merged 11 commits intomainfrom
v9999.99.9
Mar 22, 2026
Merged

Move replace_token to component as replace_all#60
edwardtfn merged 11 commits intomainfrom
v9999.99.9

Conversation

@edwardtfn
Copy link
Copy Markdown
Owner

@edwardtfn edwardtfn commented Mar 22, 2026

Summary by CodeRabbit

  • Refactor

    • Introduced a shared in-place string replacement utility and migrated date/time formatting to use it for consistent token handling.
  • Bug Fixes

    • Fixed token-replacement issues that could cause repeated or non-terminating substitutions, improving time/date rendering.
  • Chores

    • Added a C++ formatting configuration and CI step to enforce/apply it; extensive codebase reformatting for consistent style.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 22, 2026

Warning

Rate limit exceeded

@edwardtfn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4c3e214f-63bd-42eb-a627-daed97e6dce8

📥 Commits

Reviewing files that changed from the base of the PR and between 193e979 and a8ee023.

📒 Files selected for processing (1)
  • .test/unit/test_addon_climate.cpp
📝 Walkthrough

Walkthrough

Added an in-place string helper nspanel_easy::replace_all, switched datetime token substitutions to use it, added a .clang-format plus a CI step to apply/commit formatting, and applied widespread whitespace/indent-only reformatting across component sources and unit tests.

Changes

Cohort / File(s) Summary
String Utility
components/nspanel_easy/text.h, components/nspanel_easy/text.cpp
New void replace_all(std::string& str, const char* token, const char* value) added (no-op on empty token; advances search past inserted value). Nearby helper functions were reindented; no other logic changes.
Datetime Formatting Update
esphome/nspanel_esphome_datetime.yaml
Replaced local replace_token lambda with calls to nspanel_easy::replace_all(...) for time/date token substitutions; behavior preserved.
Formatting config & CI
.clang-format, .github/workflows/validate_clang_format.yml
Added .clang-format; workflow now installs clang-format, formats components/nspanel_easy and .test/unit sources, and conditionally auto-commits formatting changes.
Widespread formatting edits
components/nspanel_easy/..., .test/unit/*
Large-scale whitespace/indentation/style-only updates across headers, sources, and tests (namespace de-indentation, pointer/reference spacing, macro spacing, initializer reflow). No functional changes beyond the new utility and YAML swap.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

"I nibble tokens, hop and peep,
I tidy strings while others sleep.
Tiny paws swap what should be swapped,
No crumbs left where tokens popped.
🥕 — a rabbit cheers, code well hopped!"

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 24.19% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: extracting a replace_token lambda from YAML into a reusable replace_all function in the component.

✏️ 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 v9999.99.9

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@components/nspanel_easy/text.cpp`:
- Around line 181-189: The replace_all function can infinite-loop if token is an
empty string; add a guard at the start of replace_all(std::string& str, const
char* token, const char* value) to return immediately (or no-op) when token_len
== 0 to avoid calling str.find("") repeatedly; ensure the early-return occurs
before computing/searching and keep the existing replacement logic unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0fdec0d6-b191-4b86-ab1d-92b23809b3d1

📥 Commits

Reviewing files that changed from the base of the PR and between c923e64 and bab9ca0.

📒 Files selected for processing (3)
  • components/nspanel_easy/text.cpp
  • components/nspanel_easy/text.h
  • esphome/nspanel_esphome_datetime.yaml

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/validate_clang_format.yml:
- Line 23: The workflow uses github.head_ref alone (ref: ${{ github.head_ref
}}), which is null for workflow_dispatch runs; change that ref to use a fallback
expression such as ref: ${{ github.head_ref || github.ref }} so checkout targets
the PR branch when present and falls back to the workflow ref (or SHA) for
workflow_dispatch; update the checkout step that currently references
github.head_ref to use this fallback expression.
- Around line 30-32: The find | xargs pipeline is fragile to filenames with
spaces/newlines and to empty input; update the invocation that uses find, xargs,
and clang-format so find emits null-delimited results (use find ... -print0) and
xargs consumes them safely with the null flag and the no-op-if-empty flag (use
xargs -0 --no-run-if-empty or equivalent), passing the file list into
clang-format --style=file -i; change the pipeline that currently uses find ... |
xargs clang-format to use these flags to ensure robustness.
- Around line 34-39: Guard the "Commit clang-format fixes" auto-commit step
(uses: stefanzweifel/git-auto-commit-action@v6) so it only runs for same-repo
pull requests or workflow_dispatch runs by adding a proper if expression with
the ${{ }} delimiters; for example use if: ${{ github.event_name ==
'workflow_dispatch' || (github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository) }} to
prevent attempts to push from forked PRs where GITHUB_TOKEN is read-only.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aa25443d-5ef0-4eb5-9033-e26c4df6c279

📥 Commits

Reviewing files that changed from the base of the PR and between c2761b6 and f3d7745.

📒 Files selected for processing (2)
  • .clang-format
  • .github/workflows/validate_clang_format.yml
✅ Files skipped from review due to trivial changes (1)
  • .clang-format

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
.test/unit/test_addon_climate.cpp (1)

6-8: Add explicit <set> include to avoid transitive-include fragility.

This file uses std::set but does not include <set> directly. It currently relies on indirect headers, which is brittle across toolchain/header changes.

Suggested diff
 `#include` <gtest/gtest.h>
 `#include` <string>
+#include <set>

Also applies to: 94-96, 119-121, 324-337

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.test/unit/test_addon_climate.cpp around lines 6 - 8, This test file and
several other ranges use std::set but rely on transitive includes; add an
explicit `#include` <set> at the top of .test/unit/test_addon_climate.cpp (near
the existing `#include` <string> / `#include` <gtest/gtest.h>) and similarly add
explicit <set> includes where referenced in the other noted ranges (lines 94-96,
119-121, 324-337) so the tests no longer break if indirect headers change;
search for uses of std::set in the file to ensure every translation unit that
uses it includes <set> directly.
.test/unit/test_base.cpp (1)

8-10: Include <cstdint> explicitly for uint32_t.

delay(uint32_t ms) currently relies on transitive includes for fixed-width integer types. Add <cstdint> directly in this file for robust compilation.

Suggested diff
 `#include` <gtest/gtest.h>
 `#include` <gmock/gmock.h>
+#include <cstdint>
 `#include` <string>
 `#include` <map>

Also applies to: 29-29

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.test/unit/test_base.cpp around lines 8 - 10, Add an explicit include for
the fixed-width integer header so uint32_t is defined: add `#include` <cstdint> to
the top of this test file (and any other test files where delay(uint32_t ms) is
declared/used) to avoid relying on transitive includes; search for usages of
delay(uint32_t) or references to uint32_t and ensure those files include
<cstdint>.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.test/unit/test_addon_climate.cpp:
- Around line 6-8: This test file and several other ranges use std::set but rely
on transitive includes; add an explicit `#include` <set> at the top of
.test/unit/test_addon_climate.cpp (near the existing `#include` <string> /
`#include` <gtest/gtest.h>) and similarly add explicit <set> includes where
referenced in the other noted ranges (lines 94-96, 119-121, 324-337) so the
tests no longer break if indirect headers change; search for uses of std::set in
the file to ensure every translation unit that uses it includes <set> directly.

In @.test/unit/test_base.cpp:
- Around line 8-10: Add an explicit include for the fixed-width integer header
so uint32_t is defined: add `#include` <cstdint> to the top of this test file (and
any other test files where delay(uint32_t ms) is declared/used) to avoid relying
on transitive includes; search for usages of delay(uint32_t) or references to
uint32_t and ensure those files include <cstdint>.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 096b9531-00d5-4514-ad21-76942ba5807c

📥 Commits

Reviewing files that changed from the base of the PR and between f3d7745 and 3b416da.

📒 Files selected for processing (40)
  • .test/unit/test_addon_climate.cpp
  • .test/unit/test_addon_upload_tft.cpp
  • .test/unit/test_base.cpp
  • components/nspanel_easy/addon_climate.cpp
  • components/nspanel_easy/addon_climate.h
  • components/nspanel_easy/addon_upload_tft.cpp
  • components/nspanel_easy/addon_upload_tft.h
  • components/nspanel_easy/base.cpp
  • components/nspanel_easy/base.h
  • components/nspanel_easy/ha_components.cpp
  • components/nspanel_easy/ha_components.h
  • components/nspanel_easy/hardware.h
  • components/nspanel_easy/hw_display.cpp
  • components/nspanel_easy/hw_display.h
  • components/nspanel_easy/icons.h
  • components/nspanel_easy/macros.h
  • components/nspanel_easy/nextion_components.cpp
  • components/nspanel_easy/nextion_components.h
  • components/nspanel_easy/nspanel_easy.h
  • components/nspanel_easy/page_alarm.h
  • components/nspanel_easy/page_climate.cpp
  • components/nspanel_easy/page_climate.h
  • components/nspanel_easy/page_entities.cpp
  • components/nspanel_easy/page_entities.h
  • components/nspanel_easy/page_home.h
  • components/nspanel_easy/page_media_player.cpp
  • components/nspanel_easy/page_media_player.h
  • components/nspanel_easy/page_notification.cpp
  • components/nspanel_easy/page_notification.h
  • components/nspanel_easy/page_qrcode.h
  • components/nspanel_easy/page_utilities.cpp
  • components/nspanel_easy/page_utilities.h
  • components/nspanel_easy/pages.cpp
  • components/nspanel_easy/pages.h
  • components/nspanel_easy/text.cpp
  • components/nspanel_easy/text.h
  • components/nspanel_easy/versioning.cpp
  • components/nspanel_easy/versioning.h
  • components/nspanel_easy/weather.cpp
  • components/nspanel_easy/weather.h
✅ Files skipped from review due to trivial changes (37)
  • components/nspanel_easy/icons.h
  • components/nspanel_easy/page_entities.h
  • components/nspanel_easy/page_media_player.h
  • components/nspanel_easy/addon_climate.cpp
  • components/nspanel_easy/addon_upload_tft.h
  • components/nspanel_easy/pages.cpp
  • components/nspanel_easy/versioning.cpp
  • components/nspanel_easy/page_climate.cpp
  • components/nspanel_easy/hw_display.h
  • components/nspanel_easy/nspanel_easy.h
  • components/nspanel_easy/page_notification.h
  • components/nspanel_easy/page_notification.cpp
  • components/nspanel_easy/page_entities.cpp
  • components/nspanel_easy/ha_components.cpp
  • components/nspanel_easy/hw_display.cpp
  • components/nspanel_easy/page_media_player.cpp
  • components/nspanel_easy/weather.cpp
  • components/nspanel_easy/page_alarm.h
  • components/nspanel_easy/addon_upload_tft.cpp
  • components/nspanel_easy/addon_climate.h
  • components/nspanel_easy/base.h
  • components/nspanel_easy/page_qrcode.h
  • components/nspanel_easy/nextion_components.cpp
  • components/nspanel_easy/macros.h
  • components/nspanel_easy/base.cpp
  • components/nspanel_easy/ha_components.h
  • components/nspanel_easy/text.cpp
  • components/nspanel_easy/page_climate.h
  • components/nspanel_easy/hardware.h
  • components/nspanel_easy/versioning.h
  • components/nspanel_easy/page_utilities.cpp
  • components/nspanel_easy/weather.h
  • components/nspanel_easy/page_utilities.h
  • components/nspanel_easy/nextion_components.h
  • components/nspanel_easy/pages.h
  • components/nspanel_easy/page_home.h
  • components/nspanel_easy/text.h

@edwardtfn edwardtfn merged commit 280696c into main Mar 22, 2026
30 checks passed
@edwardtfn edwardtfn deleted the v9999.99.9 branch March 22, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant