Skip to content

The configuration-snippet exemption does not reach a tag or a quoted value, which is most of an ESPHome snippet #1710

Closed

Description

@ptr727

SNIPPET is ^\S+:\s+\S+$, so the exemption reaches a key and one whitespace-free value and nothing else. The case it was written for, a copy-pasteable ESPHome packages: block, does not survive contact with a YAML tag or a quoted friendly name, and both are in almost every snippet in ESPHome-Config.

Probe

A YAML file, committed, scanned with the gate at main:

# Case A, no indent, single-token value.
# board: board.yaml

# Case B, indented, single-token value.
#   board: board.yaml

# Case C, indented, YAML tag value.
#   board: !include board.yaml

# Case D, quoted value carrying a space.
# label: "Compressor 1"

# Case E, unquoted value carrying a space.
# label: Compressor 1

A and B are exempt. C, D and E each report comment-case, telling the author to capitalize a key a reader pastes.

Why this is not the documented cost

The change states the space bound deliberately: "A value carrying a space is not exempt, which keeps the shape to a key-value line." Case C is the one that shape did not anticipate. !include board.yaml is a single YAML value, and it splits on a space only because the tag and its argument are written apart. There is no reading of that line under which the author has written prose.

Cases D and E are the stated bound landing on a real snippet rather than on a marker comment. An ESPHome friendly name carries a space by construction.

What it costs today

The author's only remedies are to corrupt the snippet, to reword the value so it has no space, or to leave a finding standing. In ESPHome-Config all three were reached in one sweep: a !include example was rewritten into prose, and an example label was changed to "Compressor-1" to remove the space. Neither edit made the documentation better, and the second changes the value a reader copies.

Shapes to consider

  • A tag or directive value, so the value is the rest of the line rather than one token.
  • A quoted value, so a value inside matching quotes is one value whatever it contains.
  • A key-value line with a trailing comment, sda: GPIO15 # a strapping pin, which reports today.

Each widens the exemption, and the change's own accounting of what an exemption costs applies to any of them. The narrowest that clears the reported case is the quoted-value one plus reading a tag's argument as part of its value.

Adjacent, reported here rather than separately

A PEP 723 inline metadata block is not a key-value shape at all and reports comment-wrap twice:

# /// script
# requires-python = ">=3.9"
# dependencies = ["bleak>=0.22"]
# ///

uv parses that block verbatim, so no reformatting is available to the author. TOOL_DIRECTIVE carries no entry for it. Splitting it out is fine if the snippet shapes above are decided first.

Activity

  1. ptr727 commented on Sep 20, 2026

    @ptr727
    OwnerAuthor

    Reproduced at main (4f0418b), and the shape of the remedy is decided: stop growing the per-syntax exemption list.

    Reproduction

    A committed YAML file holding no prose at all, scanned whole-tree:

    6 violation(s) across 2 file(s)
      comment-case     4
      comment-wrap     2
    meta.py:1: comment-wrap
    meta.py:2: comment-wrap
    snip.yaml:8:  comment-case   #   board: !include board.yaml
    snip.yaml:11: comment-case   # label: "Compressor 1"
    snip.yaml:14: comment-case   # label: Compressor 1
    snip.yaml:17: comment-case   # sda: GPIO15 # a strapping pin
    

    Cases A and B are exempt as documented. Every other line reports, and none of the six findings is on a sentence. The PEP 723 block reports twice.

    Why the enumeration is not the fix

    The exemption has grown four times already, SNIPPET, SNIPPET_END, the tool directive, and the lone key-colon shape. This issue proposes four more shapes plus PEP 723 as a fifth. There is no reason to expect that set to be the last, because "is this comment line code" cannot be decided without parsing the embedded language, and the embedded language is arbitrary.

    The failure also lands in the worst available place. The author's remedies are to corrupt the snippet, reword the value, or leave the finding. This issue records two of those being taken in one sweep: a !include example rewritten into prose, and "Compressor 1" changed to "Compressor-1", which changes the value a reader pastes. The gate made the documentation wrong.

    The decided remedy, two halves

    Both are needed, and each is insufficient alone.

    1. Widen the anchor from a key plus one whitespace-free value to a key, a separator, and the rest of the line, accepting = beside :. This alone covers all four reported shapes: the YAML tag, the quoted value, the unquoted value carrying a space, and the trailing comment.
    2. Promote the exemption from the line to the contiguous comment run. A line in the run that is not key-value at all then rides along, which is what reaches # /// script, its closing # ///, and a bare structural line such as a closing brace.

    Half 1 without half 2 leaves a PEP 723 block reporting on its opener. Half 2 without half 1 leaves a two-line ESPHome snippet with no anchor to promote from, since neither board: !include board.yaml nor label: "Compressor 1" matches today's narrow shape. That second case is the one this issue is about, so block scoping on its own would not have closed it.

    A run needs two or more matching lines before it is exempt. Widening the anchor hands the exemption to a marker comment, note: obsolete and todo: refactor being the same shape as a configuration line, which the current documentation already names as the accepted cost of the narrow shape. A marker comment is one line and a configuration block is not, so the count is what separates them.

    The residual cost, stated rather than left to be found: a genuine single-line snippet standing alone in its own comment run still reports. That is accepted.

    Scope

    #1711 is decided to land in the same pull request, being the same rule family and the same file.

    Sequenced after the pull request currently in review, so this is direction recorded where the work lands rather than work started.

  2. added a commit that references this issue on Sep 21, 2026
    c5cdaca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions