Skip to content

Commit aac6d0a

Browse files
fix(lint): correct the toSpliced remediation and catch template-literal property names
Co-Authored-By: Claude Code <[email protected]>
1 parent b5b095e commit aac6d0a

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎oxlint-plugin-t3code/rules/no-hermes-unsupported-array-methods.test.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,24 @@ describe("t3code/no-hermes-unsupported-array-methods", () => {
3434
);
3535

3636
rule.invalid(
37-
"reports toSpliced via computed access",
37+
"reports toSpliced via computed access with a copy-then-splice remediation",
3838
`const next = items["toSpliced"](0, 1);`,
3939
(output) => {
4040
assert.match(output, /Array#toSpliced/);
41+
assert.match(output, /const copy = \[\.\.\.array\]; copy\.splice\(\.\.\.\); use copy/);
4142
},
4243
);
44+
45+
rule.invalid(
46+
"reports a static template-literal property name",
47+
"const reversed = items[`toReversed`]();",
48+
(output) => {
49+
assert.match(output, /Array#toReversed/);
50+
},
51+
);
52+
53+
rule.valid(
54+
"ignores a template-literal property with substitutions",
55+
"const value = items[`to${suffix}`]();",
56+
);
4357
});

‎oxlint-plugin-t3code/rules/no-hermes-unsupported-array-methods.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { defineRule } from "@oxlint/plugins";
66
const UNSUPPORTED_METHODS = new Map([
77
["toSorted", "[...array].sort(...)"],
88
["toReversed", "[...array].reverse()"],
9-
["toSpliced", "[...array].splice(...)"],
9+
// splice returns the removed elements, so the copy itself is the result.
10+
["toSpliced", "const copy = [...array]; copy.splice(...); use copy"],
1011
]);
1112

1213
export default defineRule({
@@ -27,7 +28,9 @@ export default defineRule({
2728
? property.name
2829
: property.type === "Literal" && typeof property.value === "string"
2930
? property.value
30-
: null;
31+
: property.type === "TemplateLiteral" && property.expressions.length === 0
32+
? (property.quasis[0]?.value.cooked ?? null)
33+
: null;
3134
if (name === null) return;
3235
const replacement = UNSUPPORTED_METHODS.get(name);
3336
if (replacement === undefined) return;

0 commit comments

Comments
 (0)