From 4acc1450981c1f0abee4b461e053dafcc9acc394 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Thu, 12 Nov 2026 21:32:34 -0800 Subject: [PATCH 1/8] Read a Markdown Code Span as Quoted Data and Pass a Semicolon Inside One Token The charset rules now blank a Markdown inline code span before judging a line, as they already skip a fenced block, so a string quoted verbatim from another source keeps its bytes. A code line is still read whole. The semicolon rule no longer reports a semicolon with a word character on both sides, such as the one in TL;DR, since it joins no clause. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/comment-and-doc-style/SKILL.md | 9 +++- .../.source-digests/comment-and-doc-style | 2 +- .../skills/comment-and-doc-style/SKILL.md | 9 +++- .github/actions/prose-gate/prose-gate.json | 2 +- .github/actions/prose-gate/prose_lint.py | 21 +++++++- .github/skills/comment-and-doc-style/SKILL.md | 9 +++- scripts/README.md | 4 +- tests/test_prose_lint.py | 51 +++++++++++++++++++ 8 files changed, 96 insertions(+), 11 deletions(-) diff --git a/.agents/skills/comment-and-doc-style/SKILL.md b/.agents/skills/comment-and-doc-style/SKILL.md index 5650699fa..32a75bb06 100644 --- a/.agents/skills/comment-and-doc-style/SKILL.md +++ b/.agents/skills/comment-and-doc-style/SKILL.md @@ -291,7 +291,7 @@ It is also because reading those would report a fixture rather than a claim abou Agent-authored text is ASCII by default: documentation, code, comments, commit messages, and PR descriptions. A non-ASCII character is read against the tiers below, because whether one is typography or meaning depends on where it sits. A character in no tier is a finding rather than a -silent pass, a letter of a recorded name excepted per the bullet below. +silent pass. A letter of a recorded name and quoted data are excepted, per the bullets below. - **Tier 1, never legitimate.** Typography carrying no meaning its ASCII form loses. Remove on sight: @@ -324,12 +324,17 @@ silent pass, a letter of a recorded name excepted per the bullet below. document records as data is written with its own letters and the marks they carry. The reason is that folding such a name to ASCII records a different name. Anywhere else a letter the agent writes that no tier covers takes its ASCII form. +- **A Markdown code span is quoted data, as a fenced block is.** A string quoted verbatim from + another source, such as a third party's output, keeps its bytes inside an inline code span. No + tier judges it there. Outside Markdown a backtick is structural, so a code line is read whole. - **An unrecognized non-ASCII character is reported, not allowed.** Classify it into a tier above - before using it. A letter of a recorded name is the one exception, per the bullet above. + before using it. A letter of a recorded name and quoted data are the exceptions, per the bullets + above. - **No semicolon in agent-authored prose.** Recast a mid-sentence semicolon as a comma or as two sentences. A semicolon separating items in a list that already contains commas, or a statement terminator in code, is unaffected. A single semicolon separates such a list only between two labeled items, as in `Inputs: a, b; outputs: c`, and a list item's bold opening label is not one. + A semicolon inside one token, such as `TL;DR`, joins no clause and is unaffected too. - **No spaced hyphen joining or interrupting a sentence** (` - `, or the paired aside ` - x - `). Recast as a comma, two sentences, or parentheses. A hyphen inside a compound word, a leading list marker, a range, and the `- **Label** - explanation` bullet separator are unaffected. diff --git a/.claude-plugin/fleet-skills/.source-digests/comment-and-doc-style b/.claude-plugin/fleet-skills/.source-digests/comment-and-doc-style index 2e1a721d3..ccc46430c 100644 --- a/.claude-plugin/fleet-skills/.source-digests/comment-and-doc-style +++ b/.claude-plugin/fleet-skills/.source-digests/comment-and-doc-style @@ -1 +1 @@ -53af967c53a13c26 +b3e100a2d4962906 diff --git a/.claude-plugin/fleet-skills/skills/comment-and-doc-style/SKILL.md b/.claude-plugin/fleet-skills/skills/comment-and-doc-style/SKILL.md index 5650699fa..32a75bb06 100644 --- a/.claude-plugin/fleet-skills/skills/comment-and-doc-style/SKILL.md +++ b/.claude-plugin/fleet-skills/skills/comment-and-doc-style/SKILL.md @@ -291,7 +291,7 @@ It is also because reading those would report a fixture rather than a claim abou Agent-authored text is ASCII by default: documentation, code, comments, commit messages, and PR descriptions. A non-ASCII character is read against the tiers below, because whether one is typography or meaning depends on where it sits. A character in no tier is a finding rather than a -silent pass, a letter of a recorded name excepted per the bullet below. +silent pass. A letter of a recorded name and quoted data are excepted, per the bullets below. - **Tier 1, never legitimate.** Typography carrying no meaning its ASCII form loses. Remove on sight: @@ -324,12 +324,17 @@ silent pass, a letter of a recorded name excepted per the bullet below. document records as data is written with its own letters and the marks they carry. The reason is that folding such a name to ASCII records a different name. Anywhere else a letter the agent writes that no tier covers takes its ASCII form. +- **A Markdown code span is quoted data, as a fenced block is.** A string quoted verbatim from + another source, such as a third party's output, keeps its bytes inside an inline code span. No + tier judges it there. Outside Markdown a backtick is structural, so a code line is read whole. - **An unrecognized non-ASCII character is reported, not allowed.** Classify it into a tier above - before using it. A letter of a recorded name is the one exception, per the bullet above. + before using it. A letter of a recorded name and quoted data are the exceptions, per the bullets + above. - **No semicolon in agent-authored prose.** Recast a mid-sentence semicolon as a comma or as two sentences. A semicolon separating items in a list that already contains commas, or a statement terminator in code, is unaffected. A single semicolon separates such a list only between two labeled items, as in `Inputs: a, b; outputs: c`, and a list item's bold opening label is not one. + A semicolon inside one token, such as `TL;DR`, joins no clause and is unaffected too. - **No spaced hyphen joining or interrupting a sentence** (` - `, or the paired aside ` - x - `). Recast as a comma, two sentences, or parentheses. A hyphen inside a compound word, a leading list marker, a range, and the `- **Label** - explanation` bullet separator are unaffected. diff --git a/.github/actions/prose-gate/prose-gate.json b/.github/actions/prose-gate/prose-gate.json index 7efd39230..d7f56e1a5 100644 --- a/.github/actions/prose-gate/prose-gate.json +++ b/.github/actions/prose-gate/prose-gate.json @@ -3,7 +3,7 @@ "rules": { "charset": { "default": true, "summary": "a non-ASCII character its tier does not permit here" }, "charset-unknown": { "default": true, "summary": "non-ASCII in no tier, bar a Latin letter and its U+0300-U+036F diacritics" }, - "semicolon": { "default": true, "summary": "a semicolon in prose, outside a series or labeled pair carrying a comma" }, + "semicolon": { "default": true, "summary": "a semicolon in prose, outside a series or labeled pair carrying a comma and outside one token" }, "dash": { "default": true, "summary": "a spaced hyphen joining or interrupting a sentence" }, "comment-wrap": { "default": true, "summary": "a comment sentence wrapped across lines, or two on one line" }, "comment-case": { "default": true, "summary": "a comment sentence opening in lowercase" }, diff --git a/.github/actions/prose-gate/prose_lint.py b/.github/actions/prose-gate/prose_lint.py index e4dcd37b9..30159602e 100755 --- a/.github/actions/prose-gate/prose_lint.py +++ b/.github/actions/prose-gate/prose_lint.py @@ -1145,6 +1145,7 @@ class Context(NamedTuple): LABEL_WORD = r"[\w`]+(?:[./-][\w`]+)*" LABELED_ITEM = re.compile(rf"^\s*[*_]*{LABEL_WORD}(?:\s+{LABEL_WORD}){{0,2}}[*_]*:[*_]*(?:\s|$)") LIST_MARKER = re.compile(rf"^\s*{LIST_MARKER_TOKEN}\s") +JOINED_SEMICOLON = re.compile(r"(?<=\w);(?=\w)") CELL_BREAK = re.compile(r"(?\s*)*\|") # A word-joining character before the repeat keeps "either/or or" from reading as a doubled word. @@ -1261,17 +1262,33 @@ def charset_findings(lineno: int, line: str) -> list[Finding]: def rule_charset(unit: Unit, ctx: Context) -> list[Finding]: - return [f for line in unit.lines for f in charset_findings(line.number, line.text)] + """Each line's non-ASCII judged by tier, a Markdown code span read as quoted data like a fence. + + Outside Markdown a backtick is structural, such as a shell command substitution, so a code + line is read whole. + """ + return [ + f + for line in unit.lines + for f in charset_findings( + line.number, + by_cell(line.text, strip_inline_code) if unit.kind == "prose" else line.text, + ) + ] def rule_semicolon(unit: Unit, ctx: Context) -> list[Finding]: """A Markdown semicolon, unless its sentence is a list carrying a comma that needs one. + A semicolon with a word character on both sides sits inside one token, as in `TL;DR`, and + joins no clause, so it is no finding. + A table row opening with a pipe is read a cell at a time, split where `row_cells` splits it. `prose_lines` blanks each cell on its own and leaves every pipe ending one where it was. """ out: list[Finding] = [] - for n, _txt, line in prose_lines(unit): + for n, _txt, prose in prose_lines(unit): + line = JOINED_SEMICOLON.sub("_", prose) pieces = ( s for cell in row_cells(line) for s in SENTENCE_BREAK.split(LABEL_COLON.sub("", cell)) ) diff --git a/.github/skills/comment-and-doc-style/SKILL.md b/.github/skills/comment-and-doc-style/SKILL.md index 5650699fa..32a75bb06 100644 --- a/.github/skills/comment-and-doc-style/SKILL.md +++ b/.github/skills/comment-and-doc-style/SKILL.md @@ -291,7 +291,7 @@ It is also because reading those would report a fixture rather than a claim abou Agent-authored text is ASCII by default: documentation, code, comments, commit messages, and PR descriptions. A non-ASCII character is read against the tiers below, because whether one is typography or meaning depends on where it sits. A character in no tier is a finding rather than a -silent pass, a letter of a recorded name excepted per the bullet below. +silent pass. A letter of a recorded name and quoted data are excepted, per the bullets below. - **Tier 1, never legitimate.** Typography carrying no meaning its ASCII form loses. Remove on sight: @@ -324,12 +324,17 @@ silent pass, a letter of a recorded name excepted per the bullet below. document records as data is written with its own letters and the marks they carry. The reason is that folding such a name to ASCII records a different name. Anywhere else a letter the agent writes that no tier covers takes its ASCII form. +- **A Markdown code span is quoted data, as a fenced block is.** A string quoted verbatim from + another source, such as a third party's output, keeps its bytes inside an inline code span. No + tier judges it there. Outside Markdown a backtick is structural, so a code line is read whole. - **An unrecognized non-ASCII character is reported, not allowed.** Classify it into a tier above - before using it. A letter of a recorded name is the one exception, per the bullet above. + before using it. A letter of a recorded name and quoted data are the exceptions, per the bullets + above. - **No semicolon in agent-authored prose.** Recast a mid-sentence semicolon as a comma or as two sentences. A semicolon separating items in a list that already contains commas, or a statement terminator in code, is unaffected. A single semicolon separates such a list only between two labeled items, as in `Inputs: a, b; outputs: c`, and a list item's bold opening label is not one. + A semicolon inside one token, such as `TL;DR`, joins no clause and is unaffected too. - **No spaced hyphen joining or interrupting a sentence** (` - `, or the paired aside ` - x - `). Recast as a comma, two sentences, or parentheses. A hyphen inside a compound word, a leading list marker, a range, and the `- **Label** - explanation` bullet separator are unaffected. diff --git a/scripts/README.md b/scripts/README.md index d86e926ff..cb25cdaa2 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -50,6 +50,8 @@ A repository may carry `.prose-gate.json` at its root to add to the carried exem The tiers decide by context rather than by a flat ban. Tier 1 carries no meaning its ASCII form loses and always flags. Tier 2 is an operator, kept next to a figure or another operator and replaced between words. A threshold table therefore reads as the range it is. Tier 3 is a unit or scientific symbol whose ASCII form would be a lie and never flags. Tier 4 is a fixed set of emoji callout markers (warning, information, check mark, cross mark, memo, light bulb). Each is admitted alone or followed by VARIATION SELECTOR-16. A U+FE0F anywhere else still flags. Developer-typed characters such as other emoji are preserved by the rule but not admitted by the gate. An un-tiered one, other than a Latin letter or a U+0300-U+036F diacritic it carries, is still reported as `charset-unknown` until it is classified. +In Markdown an inline code span is quoted data, as a fenced block already is, so neither charset rule reads it. A string quoted verbatim from another source then keeps its bytes in its sentence, neither moved to a fence nor normalized. Outside Markdown a backtick is structural, such as a shell command substitution, so a code line is read whole. + A character in no tier is a `charset-unknown` finding rather than a silent pass. That is because a gate that allows whatever it does not recognize stops gating as the character set grows. A Latin letter, with any diacritic from the U+0300-U+036F combining block that it carries, is the exception and never flags. That is because it may spell a recorded name, which the charset rule says keeps its actual spelling. That is also because nothing tells a name from a word by its characters. A letter of another script, a compatibility form such as a ligature, any other mark, and a diacritic standing alone still flag. The gate therefore covers the Latin part of that rule and nothing wider. Classifying one is a fleet-law edit, so the whole-tree step that reports the backlog is warn-only. The pull request gate blocks on one the change itself introduces. Which letters count as Latin follows the Unicode data of the Python running the gate, so a letter newer than that data is still reported. Run it scoped to changed lines, matching the standing rule that existing prose is corrected as each file is next edited rather than swept: @@ -88,7 +90,7 @@ The `spelling` rule covers the US English convention where cspell does not reach A double-quoted span in Markdown is treated as a quotation and not scanned for prose rules. A rule that states its own counter-example therefore does not report the document that documents it. Outside Markdown a double quote is structural, so the prose inside it still counts. A table row opening with a pipe has its code spans and quotations blanked one cell at a time. markdown-it-py ends a cell at an unescaped pipe inside a code span as well. A quotation blanked across cells would also hide every cell between its two marks. -The `semicolon` and `dash` rules ban a construction rather than a detectable subset of it. Each therefore flags by default, and the exceptions are the ones the rule names. The exceptions for the dash are a compound word, a leading list marker, a range, and the `- **Label** - explanation` separator that opens a governed bullet. The exception for a semicolon is one inside a list that already carries commas. Where such a list is joined by a single semicolon, each of its two items carries a label. +The `semicolon` and `dash` rules ban a construction rather than a detectable subset of it. Each therefore flags by default, and the exceptions are the ones the rule names. The exceptions for the dash are a compound word, a leading list marker, a range, and the `- **Label** - explanation` separator that opens a governed bullet. The exceptions for a semicolon are one inside a list that already carries commas and one inside a single token. Where such a list is joined by a single semicolon, each of its two items carries a label. A semicolon with a word character on both sides, as in `TL;DR`, is inside one token and joins no clause. **The semicolon rule reads the list where it lives.** The comma qualifies the list as a whole rather than one separator's position. An enumeration whose commas fall in a later item therefore keeps every semicolon it carries. Reading it positionally split one series in two. That reading flagged the openers of the same list it then exempted the tail of. That would have restructured the enumerated guarantees the exemption exists to protect. A Markdown table row opening with a pipe is judged one cell at a time. This is because a row is a record of fields, and a comma in one column cannot excuse a semicolon in another. A cell ends at a pipe no backslash escapes, which is how markdown-it-py reads an escaped pipe, so the escaped pipe stays inside its cell. A bullet's `**Label**:` is dropped before the line is read, because it opens the bullet rather than announcing a list. The `**Label**:` is the same construct the label dash is exempted for. The colon is written inside the emphasis as often as outside it, so `**Label:**` is dropped on the same grounds. Matching only one spelling left the other announcing a list it never announced. diff --git a/tests/test_prose_lint.py b/tests/test_prose_lint.py index 73a700bcd..81d2f8e31 100755 --- a/tests/test_prose_lint.py +++ b/tests/test_prose_lint.py @@ -593,10 +593,61 @@ def test_the_tiers_do_not_overlap(self) -> None: self.assertEqual(set(), t2 & t3) self.assertEqual(set(), t4 & (t1 | t2 | t3)) + def test_a_markdown_code_span_is_read_as_quoted_data_like_a_fence(self) -> None: + """A string quoted verbatim keeps its bytes inside a code span, and the same text outside flags. + + The tier-2 case has no figure beside it, so only the span admits it. + """ + rules = {"charset", "charset-unknown"} + for quoted, kinds in ( + ("\u00abr0\u00bb", ["charset-unknown", "charset-unknown"]), + ("Issued by Example \u00b7 Jan", ["charset"]), + ("left \u2014 right", ["charset"]), + ): + with self.subTest(quoted=quoted): + self.assertEqual([], self.kinds(f"The page printed `{quoted}`.\n", rules)) + self.assertEqual([], self.kinds(f"```text\n{quoted}\n```\n", rules)) + self.assertEqual(kinds, self.kinds(f"The page printed {quoted}.\n", rules)) + self.assertEqual(kinds, self.kinds(f"`ok` then {quoted} then `ok`.\n", rules)) + + def test_a_code_span_in_a_table_cell_is_read_as_quoted_data(self) -> None: + """A cell's span is blanked within the cell, so the next cell is still read.""" + rules = {"charset", "charset-unknown"} + head = "| a | b |\n| - | - |\n" + self.assertEqual([], self.kinds(f"{head}| `\u00ab` | plain |\n", rules)) + self.assertEqual(["charset-unknown"], self.kinds(f"{head}| `x` | \u00ab |\n", rules)) + + def test_a_backtick_outside_markdown_quotes_nothing(self) -> None: + """Outside Markdown a backtick is structural, so a code line is read whole.""" + rules = {"charset", "charset-unknown"} + self.assertEqual( + ["charset-unknown"], self.kinds("#!/bin/sh\n# ids like `\u00ab`\n", rules, "a.sh") + ) + class TestSemicolonRule(BaitCase): """The `semicolon` rule on Markdown prose units.""" + def test_a_semicolon_inside_one_token_joins_no_clause(self) -> None: + """`TL;DR` holds its semicolon between word characters, so neither fix applies to it.""" + for text in ( + "> **TL;DR**: Short summary here.\n", + "A plain sentence with TL;DR inside it.\n", + "TL;DR, it runs on push, always.\n", + ): + with self.subTest(text=text.strip()): + self.assertEqual([], self.kinds(text, {"semicolon"})) + + def test_a_semicolon_with_a_space_beside_it_is_still_a_splice(self) -> None: + """Only a word character on both sides makes one token, so a spaced splice still flags.""" + for text in ( + "TL;DR it runs; it stops.\n", + "It runs ;it stops.\n", + "It runs;\n", + ): + with self.subTest(text=text.strip()): + self.assertEqual(["semicolon"], self.kinds(text, {"semicolon"})) + def test_a_splice_is_flagged(self) -> None: self.assertEqual(["semicolon"], self.kinds(f"{SPLICE_BAIT}.\n", {"semicolon"})) From ca35858a258c0d601e07be22b1975b03b81b37d9 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Thu, 12 Nov 2026 21:41:13 -0800 Subject: [PATCH 2/8] Pair Code Spans as Markdown Does Before the Charset Rules Read a Line Pairing backticks one line at a time took a wrapped span's closer for an opener and hid the prose up to the next span. The charset rules now read a spanless unit, built from markdown-it-py's inline tokens with the span-aware MARKDOWN_SPAN pattern, so front matter and an HTML block are read whole as well. Co-Authored-By: Claude Opus 5.5 --- .github/actions/prose-gate/prose_lint.py | 51 ++++++++++++++++-------- scripts/README.md | 2 +- tests/test_prose_lint.py | 28 +++++++++++++ 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/.github/actions/prose-gate/prose_lint.py b/.github/actions/prose-gate/prose_lint.py index 30159602e..91d76fedf 100755 --- a/.github/actions/prose-gate/prose_lint.py +++ b/.github/actions/prose-gate/prose_lint.py @@ -617,8 +617,8 @@ class Line(NamedTuple): class Unit(NamedTuple): """A run of text one kind of rule reads. - `source` is every line, and `prose` and `code` the unfenced ones. `paragraph` is a Markdown - sentence block. `comment`, `doc`, and `markup` are runs of adjacent comment lines, `doc` a + `source` is every line, and `prose` and `code` the unfenced ones. `spanless` is the unfenced + Markdown lines with each code span's content blanked. `paragraph` is a Markdown sentence block. `comment`, `doc`, and `markup` are runs of adjacent comment lines, `doc` a documentation comment and `markup` a Markdown HTML one. `docstring` opens at `column`. """ @@ -1010,6 +1010,7 @@ def extract_markdown(lines: list[str]) -> Extracted: if line.strip() and not line.strip().startswith("#") ] markup: list[Line] = [] + spanless: dict[int, str] = {} parents: list[str] = [] for tok in MARKDOWN.parse("\n".join([""] * matter + lines[matter:])): if tok.nesting: @@ -1029,6 +1030,13 @@ def extract_markdown(lines: list[str]) -> Extracted: paragraphs.append(Unit("paragraph", (Line(n, span),))) elif tok.type == "inline": markup += inline_comments(tok, lines) + numbers = range(first, last + 1) + texts = [spanless.get(n, lines[n - 1]) for n in numbers] + if parents[-1:] in (["th_open"], ["td_open"]): + texts = [by_cell(text, blank_code_spans) for text in texts] + else: + texts = blank_code_spans("\n".join(texts)).split("\n") + spanless.update(zip(numbers, texts, strict=True)) if parents[-1:] in BLOCK_PARENTS and "blockquote_open" not in parents: spans = enumerate(tok.content.split("\n")) paragraphs.append( @@ -1038,6 +1046,7 @@ def extract_markdown(lines: list[str]) -> Extracted: units = [ Unit("source", tuple(Line(n, t) for n, t in enumerate(lines, 1))), *line_units("prose", lines, skip), + *line_units("spanless", [spanless.get(n, t) for n, t in enumerate(lines, 1)], skip), *paragraphs, *blocks("markup", sorted(markup, key=lambda m: m.number)), ] @@ -1050,8 +1059,7 @@ def inline_comments(tok: Token, lines: list[str]) -> list[Line]: first, last = (tok.map or [0, 1])[0], (tok.map or [0, 1])[1] number, col = first + 1, 0 # A code span can hold a comment's text, so it is blanked, lengths kept, before the search. - blank = lambda m: re.sub(r"[^\n]", " ", m.group()) if m[1] else m.group() - seen = re.sub(MARKDOWN_SPAN, blank, "\n".join(lines[first:last])).split("\n") + seen = blank_code_spans("\n".join(lines[first:last])).split("\n") for child in tok.children or (): if child.type == "html_inline" and child.content.startswith("