Skip to content

Commit 052b9e7

Browse files
fix(gate): ignore directive-looking JSX text in tsx sources
CodeRabbit: getLeadingCommentRanges is text-based, so rendered JSX text such as "<div> // Stryker disable all" produced a comment range and failed a touched .tsx file. Skip ranges whose token is JsxText; comments inside JSX expression containers ({// ...}) still resolve to a real comment and remain rejected. Tests: node --test scripts/stryker-diff.test.mjs (46/46).
1 parent 372f5fb commit 052b9e7

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎scripts/stryker-diff.mjs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ export function assertNoDisableDirectives(source, lineNumbers, filePath) {
169169
for (const range of ranges ?? []) {
170170
if (seen.has(range.pos)) continue
171171
seen.add(range.pos)
172+
// getLeadingCommentRanges is text-based: inside JSX, directive-looking rendered text
173+
// (e.g. <div> // Stryker disable all) is JsxText, not a comment, and must not fail.
174+
if (ts.getTokenAtPosition(sourceFile, range.pos).kind === ts.SyntaxKind.JsxText) continue
172175
if (!SUPPRESSION_DIRECTIVE.test(source.slice(range.pos, range.end))) continue
173176
const lineNumber = (source.slice(0, range.pos).match(/\n/g)?.length ?? 0) + 1
174177
if (lineNumbers.has(lineNumber)) {

‎scripts/stryker-diff.test.mjs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,25 @@ describe("Stryker suppression directive prohibition", () => {
654654
)
655655
})
656656

657+
it("ignores directive-looking JSX text in tsx sources", () => {
658+
assert.doesNotThrow(() =>
659+
assertNoDisableDirectives(
660+
"const el = <div> // Stryker disable all\n</div>\n",
661+
new Set([1, 2]),
662+
"source.tsx",
663+
),
664+
)
665+
assert.throws(
666+
() =>
667+
assertNoDisableDirectives(
668+
"const el = <div>{ // Stryker disable next-line all: reason\nx}</div>\n",
669+
new Set([1, 2]),
670+
"source.tsx",
671+
),
672+
/Stryker suppression comments are not allowed/,
673+
)
674+
})
675+
657676
it("accepts sources without suppression comments", () => {
658677
assert.doesNotThrow(() => assertNoDisableDirectives("return value <= limit\n", new Set([1]), "source.ts"))
659678
assert.doesNotThrow(() =>

0 commit comments

Comments
 (0)