Skip to content

Commit b0351f3

Browse files
committed
Add early return when offset range is unavailable in no-invalid-scriptlets rule fuzzy matching
- Added null check for `context.getOffsetRangeForNode(node)` before processing fuzzy match suggestions - Moved range calculation before fuzzy matching logic to avoid unnecessary processing - Changed `fixer.replaceWithText` to use validated range instead of `[node.start!, node.end!]` - Prevents potential errors when node offset range cannot be determined
1 parent 2d21efc commit b0351f3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/rules/no-invalid-scriptlets.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ export default defineRule({
242242
scriptletData = scriptletsCompatibilityTable.getFirst(scriptletName, platform);
243243

244244
if (scriptletData === null) {
245+
const range = context.getOffsetRangeForNode(node);
246+
247+
if (range === null) {
248+
return;
249+
}
250+
245251
const names = getScriptletNames(platform);
246252
const possibleMatches = search(
247253
scriptletName,
@@ -267,7 +273,7 @@ export default defineRule({
267273
},
268274
fix(fixer) {
269275
return fixer.replaceWithText(
270-
[node.start!, node.end!],
276+
range,
271277
QuoteUtils.setStringQuoteType(match, actualQuote),
272278
);
273279
},

0 commit comments

Comments
 (0)