Skip to content

fix(style): read a trailing comment as a comment, not as a member - #72

Merged
Reefact merged 1 commit into
mainfrom
claude/lint-layout-trailing-comment
Aug 11, 2026
Merged

fix(style): read a trailing comment as a comment, not as a member#72
Reefact merged 1 commit into
mainfrom
claude/lint-layout-trailing-comment

Conversation

@Reefact

@Reefact Reefact commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Summary

A wrapped suppression closing with a trailing // comment was passed over in silence — in both modes, with exit 0. That is the one outcome indistinguishable from a clean tree, which is the failure this checker and its test exist to prevent.

Reproduced

class Wrapped {
    [SuppressMessage("Category", "RULE0011",
        Justification = "Wrapped, and closing with a comment after it.")] // a note
    void WrappedThenAComment() { }
}
$ tools/style/lint-layout.sh Wrapped.cs        →  Nothing to report.   exit 0
$ tools/style/lint-layout.sh --fix Wrapped.cs  →  Nothing to report.   exit 0

The checker asks two questions of the line the attribute closes on: does the attribute end here ()] anywhere), and does the line end here ()] at the end). The second answered no, because a comment followed — so the site was filed as the shape the checker admits it cannot read, a )] with a member after it, and produced no record at all. Not a report, not a decline: nothing. So --fix also had nothing to exit non-zero for.

A wrapped suppression could therefore escape the rule entirely by carrying a note.

Type of change

  • Bug fix
  • New feature
  • Breaking change to the public API
  • Refactoring
  • Analyzer / diagnostic change
  • Tests
  • Documentation
  • Build / CI / tooling

Changes

  • closesLine also accepts )] followed by only a // comment. A // runs to the end of the line, so nothing can be hiding behind it and joining up to that line is safe. A /* is deliberately still unread — a member can follow its close on the same line, and telling that apart is parsing C# again.
  • Two cases join the checker's own test: the wrapped-then-comment site it now rewrites, and a block-comment-then-member site it must still leave alone. Both counts the test asserts move with them (ten sites, ten lines removed).
  • CLAUDE.md, CONTRIBUTING.md and docs/for-users/CONTRIBUTING.fr.md all enumerate the shapes the checker stays silent on. A trailing comment is now named as not one of them, since reading it as one is what cost the rule its teeth.

Scope

The repository carried no site of either shape — lint-layout.sh over the tree is still "Nothing to report." — so no C# changes with this.

No changelog entry: the checker is a repository tool, not something the packages ship, and the changelog documents the packages.

Testing

  • tools/style/lint-layout.test.sh — passes; fails without the fix on the new case
  • tools/style/lint-layout.sh over the tree — nothing to report
  • dotnet test — documentation suite green (192), which is what the CONTRIBUTING translation pairing runs through
  • tests/PackageSmokeTest/run.sh — not run: no packaging, analyzer or entry-point change; nothing under src/ is touched

Public API

  • No change to the public surface
  • The surface changed and the baseline was updated in the same commit

Documentation

  • README / docs/ updated
  • The French counterpart was updated to match
  • CHANGELOG.md and docs/for-users/CHANGELOG.fr.md both updated
  • No documentation change required

🤖 Generated with Claude Code

https://claude.ai/code/session_01M5U2BZXpHQr7YcfNHVx9dA


Generated by Claude Code

A wrapped suppression closing with a trailing `//` comment was passed
over in silence. The checker asks two questions of the line the
attribute closes on: does the attribute end here, and does the line end
here. The second answered no — a comment followed — so the site was
filed as the one shape the checker admits it cannot read, a `)]` with a
member after it, and produced no record at all.

That is the outcome this checker exists to avoid. Both modes said
"Nothing to report." and exited 0, which is exactly what a clean tree
says, so a wrapped suppression could escape the rule entirely by
carrying a note, and --fix had nothing to decline and so nothing to exit
non-zero for.

A `//` is not a member. It runs to the end of the line, so nothing can
be hiding behind it and joining up to that line is safe. A `/*` still
is not read: a member can follow its close on the same line, and telling
that apart is parsing C# again.

Two cases join the checker's own test — the wrapped-then-comment site it
now rewrites, and the block-comment site it must still leave alone —
along with the two counts they move. The repository itself carried no
site of either shape, so nothing else changes.

CLAUDE.md and CONTRIBUTING.md, in both languages, enumerate the shapes
the checker stays silent on. A trailing comment is now named as not one
of them, since reading it as one is what cost the rule its teeth.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M5U2BZXpHQr7YcfNHVx9dA
@Reefact
Reefact merged commit 6999337 into main Aug 11, 2026
10 checks passed
@Reefact
Reefact deleted the claude/lint-layout-trailing-comment branch August 11, 2026 19:25
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.

2 participants