Treat dot-prefixed top-level keys as block boundaries in the line scanners - #2652
Treat dot-prefixed top-level keys as block boundaries in the line scanners#2652bdraco wants to merge 3 commits into
Conversation
|
@esphbot review |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
🟢 Approval recommended
The changes are small, targeted, and backed by new regression tests covering the dot-prefixed key boundary and integration-extraction behavior.
Pull request overview
Fixes backend YAML “line scanner” handling so dot-prefixed top-level keys (ESPHome’s convention for ignored anchor containers) correctly terminate the preceding block during text splices, and are excluded from the “direct integrations” list used by the device drawer.
Changes:
- Treat column-0 dot-prefixed keys as top-level block boundaries in
block_end_indexand_locate_singleton_block, preventing splices from absorbing anchor blocks. - Skip dot-prefixed top-level keys in
extract_directly_referenced_integrations, matching ESPHome core behavior. - Add focused regression tests covering both the splice boundary behavior and the integrations extractor behavior.
File summaries
| File | Description |
|---|---|
| tests/test_yaml_helpers.py | Adds regression tests ensuring splices stop before dot-prefixed anchor containers and validates updated line-scan helpers. |
| tests/test_directly_referenced_integrations.py | Adds a test asserting dot-prefixed top-level keys are excluded from the “direct integrations” list. |
| esphome_device_builder/helpers/yaml/writing_layout.py | Updates singleton-block scanning to treat dot-prefixed keys as terminating the current block. |
| esphome_device_builder/helpers/yaml/scan.py | Updates block_end_index to recognize dot-prefixed top-level keys as block starts/boundaries. |
| esphome_device_builder/helpers/device_yaml/_parsing.py | Skips dot-prefixed top-level keys when extracting directly referenced integrations. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2652 +/- ##
=======================================
Coverage 99.72% 99.72%
=======================================
Files 279 279
Lines 23591 23598 +7
=======================================
+ Hits 23527 23534 +7
Misses 64 64
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@esphbot review |
|
|
esphbot
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
Confirmed resolved. |
PR Review — Treat dot-prefixed top-level keys as block boundaries in the line scannersPrior suggestion is resolved; the fix is correct and well-scoped. Merge-ready with one non-blocking nit. The follow-up commit (3afa872) does exactly what was asked: The rest holds up on re-read.
Checklist
ℹ️ Triage summary1 pre-existing finding(s) on unchanged code suppressed (freeze). Automated review by Kōan (Claude) |
esphbot
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
What does this implement/fix?
Backend side of the dot-prefixed key blind spot from #2651. ESPHome ignores top-level keys starting with a dot, the documented way to park YAML anchors. Two line scanners only ended a top-level block at an alphabetic column-0 line, so a dot-prefixed key did not terminate the block above it; a component add or migration nudge on such a file could splice into the wrong place.
The rule now has one home:
is_ignored_top_level_keyandopens_top_level_blockinhelpers/yaml/scan.py.block_end_indexand_locate_singleton_blocktreat a column-0 dot key as a block boundary, matching the scanners that already handled it; column-0 comments deliberately keep their current behaviour. The two resolved-config dict walks skip dot keys too:extract_directly_referenced_integrations(defense in depth, the loaded-integrations intersection already kept dot keys out of the drawer) and the automations_iter_instance_targetswalk, so a dot-parked instance can no longer resolve as aComponentTarget.The editor rendering bug reported in the issue is fixed in the companion frontend PR.
Related issue or feature (if applicable):
Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocsmaintenancecidependenciesFrontend coordination
Checklist
ruff,codespell, yaml/json/python checks).tests/where applicable.components.index.json/definitions/components/*.jsonhave not been hand-edited (regenerate viascript/sync_components.pyif a sync is needed).docs/ARCHITECTURE.mdand/ordocs/API.md.