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
|
|
@ -156,8 +156,7 @@ int main() {
|
|||
Configuration cfg = FixtureConfig();
|
||||
cfg.AddLintRule("marker", [](LintContext& ctx) {
|
||||
const std::string& code = ctx.CommentStripped();
|
||||
for (std::size_t pos = code.find("MARKER"); pos != std::string::npos;
|
||||
pos = code.find("MARKER", pos + 1)) {
|
||||
for (std::size_t pos = code.find("MARKER"); pos != std::string::npos; pos = code.find("MARKER", pos + 1)) {
|
||||
std::size_t line = 1 + std::count(code.begin(), code.begin() + pos, '\n');
|
||||
ctx.Report(line, "MARKER in code");
|
||||
}
|
||||
|
|
@ -370,8 +369,7 @@ int main() {
|
|||
Configuration cfg = s.Config({"a"});
|
||||
AddTrimRule(cfg);
|
||||
RunLint(cfg, Mode(LintMode::Apply));
|
||||
Check(s.Read("a") == "// lint-disable-next-line trim\nkeep \ntrim\n",
|
||||
"suppressed line keeps its bytes; the unsuppressed one is fixed");
|
||||
Check(s.Read("a") == "// lint-disable-next-line trim\nkeep \ntrim\n", "suppressed line keeps its bytes; the unsuppressed one is fixed");
|
||||
}
|
||||
|
||||
// Multiple rule names on one directive (space- or comma-separated).
|
||||
|
|
|
|||
Loading…
Reference in a new issue