mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 18:43:44 +00:00
fix(linter/unicorn/prefer-spread): ignore super method calls (#27868)
Ignore direct `super` method calls in `unicorn/prefer-spread`. These calls delegate to inherited implementations, so spread is not a valid general replacement; the failing `File.slice()` call returns a `Blob`. Adds passing regressions for `super.slice()`, `super.toSpliced()`, and `super.concat()`, including computed and parenthesized calls. `super.items.slice()` remains fixable. Fixes the [ecosystem CI fixer panic](https://github.com/oxc-project/oxc-ecosystem-ci/actions/runs/39043725818/job/117429458847).
This commit is contained in:
1 parent
dc54fe268b
commit
f9cf1652ed
1 file changed
+15
@@ -68,6 +68,10 @@ fn check_unicorn_prefer_spread<'a>(
|
||||
return;
|
||||
};
|
||||
|
||||
if member_expr.object().without_parentheses().is_super() {
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(static_property_name) = member_expr.static_property_name().and_then(JSStr::as_str)
|
||||
else {
|
||||
return;
|
||||
@@ -426,6 +430,13 @@ fn test() {
|
||||
str.split("")"#,
|
||||
r#""string"
|
||||
str.split("")"#,
|
||||
"class A extends B { method() { return super.slice(); } }",
|
||||
"class A extends B { method() { return super.slice(0); } }",
|
||||
r#"class A extends B { method() { return super["slice"](); } }"#,
|
||||
"class A extends B { method() { return super.toSpliced(); } }",
|
||||
"class A extends B { method() { return (super.toSpliced)(); } }",
|
||||
r#"class A extends B { method() { return super["toSpliced"](); } }"#,
|
||||
"class A extends B { method() { return super.concat(); } }",
|
||||
];
|
||||
|
||||
let fail = vec![
|
||||
@@ -668,6 +679,10 @@ str.split("")"#,
|
||||
("(foo, Array.from(set))", "(foo, [...set])"),
|
||||
("[Array.from(set)]", "[[...set]]"),
|
||||
("async () => await Array.from(set)", "async () => await [...set]"),
|
||||
(
|
||||
"class A extends B { method() { return super.items.slice(); } }",
|
||||
"class A extends B { method() { return [...super.items]; } }",
|
||||
),
|
||||
];
|
||||
|
||||
Tester::new(PreferSpread::NAME, PreferSpread::PLUGIN, pass, fail)
|
||||
|
||||
Reference in new issue
Block a user