Skip to content

Commit 177fb95

Browse files
author
f0-1528
committed
fix(config-eslint): flag an escaped dot or anchor in a bare abort assertion
The row on this pull request's own rule says a regex with an escaped dot slips past abortSubstringSelector: /^Request was aborted\.$/ is not flagged while the same message written as a string is. Measured against the rule as it stood, through the extension's real config (calculateConfigForFile on core/task/__tests__/example.spec.ts, then linter.verify): toThrow(/^aborted$/) 1 (already flagged) toThrow(/^Request was aborted\.$/) 0 <- the hole toThrowError(/request aborted\.$/i) 0 <- the hole toThrow(/^request aborted\$/) 0 <- same hole, escaped anchor toThrow(/^Request was aborted because the peer …\.$/) 0 (a full message stays allowed) The tail [.$]?$ cannot consume the backslash that an escaped dot or anchor leaves in the pattern text, so the match dies one character short. The tail becomes [\\.$]*$ in both branches of the selector (the string-value branch and the regex-pattern branch), which consumes \\., \$, . or $ before the end and nothing else. Red before, green after, in packages/config-eslint/api-provider-hygiene.test.js: the four new rows fail with 'expected: 1' against the old tail (# tests 89, # fail 2 - the loop runs for two lane paths) and pass against the new one (# tests 89, # pass 89, # fail 0). After the change the probe reports 13 of 13 cases as wanted, including toThrow(/aborted\./) -> 1, rejects.not.toThrow(/^Request was aborted\.$/) -> 0 and the long-message cases -> 0. No spec in the repository is newly caught: eslint over src (with main merged at a326612) still exits 0 with --max-warnings=0, root pnpm run lint is 12/12, and pnpm lint in packages/config-eslint exits 0. No eslint-suppression entry changes (pnpm exec eslint --prune-suppressions on both files leaves src/eslint-suppressions.json byte-identical). Rule source and its test are the only files touched.
1 parent a326612 commit 177fb95

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎packages/config-eslint/api-provider-hygiene.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ export const apiProviderHygieneConfig = {
6666
// Shared by every spec lane, not only src/api: an abort assertion must not pass on a raw SDK error.
6767
export const abortSubstringSelector = {
6868
selector:
69-
"CallExpression[callee.property.name=/^toThrow(Error)?$/]:not([callee.object.property.name='not']):matches([arguments.0.value=/^[$^]?(the )?(request )?(was )?abort(ed)?[.$]?$/i], [arguments.0.regex.pattern=/^[$^]?(the )?(request )?(was )?abort(ed)?[.$]?$/i])",
69+
// The escaped-dot and escaped-anchor forms keep a backslash in the pattern text, so the tail
70+
// has to allow one before the dot or anchor; without it /^Request was aborted\\.$/ slips
71+
// through the rule while the same message written as a string is flagged.
72+
"CallExpression[callee.property.name=/^toThrow(Error)?$/]:not([callee.object.property.name='not']):matches([arguments.0.value=/^[$^]?(the )?(request )?(was )?abort(ed)?[\\\\.$]*$/i], [arguments.0.regex.pattern=/^[$^]?(the )?(request )?(was )?abort(ed)?[\\\\.$]*$/i])",
7073
message:
7174
"A bare 'abort' substring also matches a raw SDK error. Assert the AbortError name and the full provider message.",
7275
}

‎packages/config-eslint/api-provider-hygiene.test.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,14 @@ describe("abort assertions in the extension ESLint config", () => {
297297
for (const [code, expectedCount] of [
298298
['await expect(p).rejects.toThrow("aborted")', 1],
299299
["await expect(p).rejects.toThrowError(/abort/i)", 1],
300+
// An escaped dot in the source text is still a bare abort substring: the pattern
301+
// keeps a backslash, so the matcher must allow it before the trailing dot or anchor.
302+
["await expect(p).rejects.toThrow(/^aborted$/)", 1],
303+
["await expect(p).rejects.toThrow(/^Request was aborted\\.$/)", 1],
304+
["await expect(p).rejects.toThrowError(/request aborted\\.$/i)", 1],
305+
["await expect(p).rejects.toThrow(/^request aborted\\$/)", 1],
300306
['await expect(p).rejects.not.toThrow("aborted")', 0],
307+
["await expect(p).rejects.toThrow(/^Request was aborted because the peer closed the stream\\.$/)", 0],
301308
[
302309
'await expect(p).rejects.toMatchObject({ name: "AbortError", message: "The Requesty request was aborted" })',
303310
0,

0 commit comments

Comments
 (0)