Fix false positives in balanced-punctuation - #229
Conversation
|
I think this introduces a regression. I manually checked it with a minimal case and the new logic hides a real unmatched opening quote if there is a possessive apostrophe later in the same text. For example, The issue seems to be that once there is any earlier opening curly single quote on the stack, a later word-boundary Might be worth tightening the heuristic here a bit more becuase right now it seems to accept an unrelated opener as a match. |
Ok now I get the issue. The tension lies in the distinction between what count as an apostrophe and what count as a quoting mark, and which characters to reserve for each usage. I made an argument in #104 (comment) that:
So at the time my position was to reserve straight The current I just updated the code to tightened the heuristic. Each opener now records its text index, and a word-boundary If my original strict separation holds (awesome lists should use straight |
This PR fix false positives in
balanced-punctuationfor apostrophes.Description
The
balanced-punctuationrule treats'(U+2019) after a word character as an apostrophe and skips it. This works forcompany'sordon't, but breaks when the same line also contains a curly-quoted span like'steal', in which the closing'afterstealhas a word character before it and space after it, so it gets classified as an apostrophe too, leaving the opening'unmatched.I stumbled upon this issue in my awesome-billing project, where I had to add
<!--lint ignore balanced-punctuation-->to bypass this false-positive:Line 402 has
China's(apostrophe) and'steal'(quoted span) on the same line: 3'characters total, with the closing quote misidentified as an apostrophe.Root cause
The original
match-punctuationplugin fromremark-lint-pluginshad a similar issue (see: #104 and laysent/remark-lint-plugins#44), which was fixed in 2345263. Then af84612 replaced the plugin with the custombalanced-punctuationimplementation and reintroduced the same class of bug.Fix
When
isApostrophe()returns true but the character is at a word boundary (not between two word characters), check whether there's a matching opening'(U+2018) on the stack.Context
I contributed the quote/punctuation validation logic in the
list-itemrule 6 years ago (see: #101 and #127) and ran into thisbalanced-punctuationregression on my downstream awesome lists.