fix(lint): make the reflow guards token-accurate instead of textual
The transforms guard themselves against comments and raw strings before
joining or rewriting a line, because pulling text up past a `//` buries it
and reflowing a multi-line literal changes the string. Those guards were
substring probes over the raw line, so they answered the wrong question:
Line(n).contains("//") fires on // inside a string literal
Line(n).contains("R\"") fires on the characters R" inside a literal, and
MISSES a raw string opened on an earlier line
Both misfire on this repo's own sources. "MARKER" ends in R", and any string
mentioning a lint-disable directive contains //. Two wrapped call sites in
tests/Lint were being left unjoined for exactly these reasons; they join now,
and the results are in this commit.
Replaced by LineHasComment() (added with the token layer) and a new
LineHasMultiLineToken(), which reports whether any token actually covering
that line spans a line boundary — a raw string or a block comment. Backed by
a per-line bitmap derived from the token cache and invalidated with it.
The guards themselves stay: joining across a real comment or a real
multi-line literal is still unsafe, and there are tests for both. What
changes is that they now fire on comments and literals rather than on the
characters that spell them.
format-concat gets narrower as a result. It used to refuse any line
containing R" and ask for a manual fix; now only a literal that genuinely
spans lines does that, because a single-line raw string reduces to R"…" in
the stripped view, fails the plain-literal test, and travels through as an
argument with its spelling intact.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
04bc58b2fa
commit
78fbf8f80c
5 changed files with 87 additions and 16 deletions
|
|
@ -214,6 +214,14 @@ export namespace Crafter {
|
|||
// True when a comment token starts on `line`. Replaces `Line(n).contains("//")`,
|
||||
// which false-positives on a `//` inside a string literal.
|
||||
CRAFTER_API bool LineHasComment(std::size_t line);
|
||||
// True when `line` (1-based) is touched by a token that spans more
|
||||
// than one line — a raw string or a block comment. A transform that
|
||||
// joins, splits or rewrites such a line changes what is inside that
|
||||
// token, so this is the guard to consult before reflowing anything.
|
||||
// Replaces `Line(n).contains("R\"")`, which both misses raw strings
|
||||
// opened on an earlier line and fires on the characters R" appearing
|
||||
// inside an ordinary literal.
|
||||
CRAFTER_API bool LineHasMultiLineToken(std::size_t line);
|
||||
|
||||
// Driver wiring — set by RunLint before each check call. Not for rules.
|
||||
std::string activeRule;
|
||||
|
|
@ -221,6 +229,9 @@ export namespace Crafter {
|
|||
std::optional<std::string> commentStrippedCache;
|
||||
std::optional<LintSuppressions> suppressionsCache;
|
||||
std::optional<std::vector<LintToken>> tokenCache;
|
||||
// Per-line flag, 0-based, for LineHasMultiLineToken. Derived from
|
||||
// tokenCache and invalidated with it.
|
||||
std::optional<std::vector<bool>> spannedLineCache;
|
||||
};
|
||||
|
||||
// A named lint rule: `check` runs once per (rule, file) over the project's
|
||||
|
|
|
|||
Loading…
Reference in a new issue