Skip to content

Commit

Permalink
Update: remove prefer-spread autofix (fixes #11330) (#11365)
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Feb 11, 2019
1 parent 5eb3121 commit 3c90dd7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
15 changes: 2 additions & 13 deletions lib/rules/prefer-spread.js
Expand Up @@ -59,7 +59,7 @@ module.exports = {
},

schema: [],
fixable: "code"
fixable: null
},

create(context) {
Expand All @@ -78,18 +78,7 @@ module.exports = {
if (isValidThisArg(expectedThis, thisArg, sourceCode)) {
context.report({
node,
message: "Use the spread operator instead of '.apply()'.",
fix(fixer) {
if (expectedThis && expectedThis.type !== "Identifier") {

// Don't fix cases where the `this` value could be a computed expression.
return null;
}

const propertyDot = sourceCode.getFirstTokenBetween(applied, node.callee.property, token => token.value === ".");

return fixer.replaceTextRange([propertyDot.range[0], node.range[1]], `(...${sourceCode.getText(node.arguments[1])})`);
}
message: "Use the spread operator instead of '.apply()'."
});
}
}
Expand Down
16 changes: 0 additions & 16 deletions tests/lib/rules/prefer-spread.js
Expand Up @@ -44,50 +44,34 @@ ruleTester.run("prefer-spread", rule, {
invalid: [
{
code: "foo.apply(undefined, args);",
output: "foo(...args);",
errors
},
{
code: "foo.apply(void 0, args);",
output: "foo(...args);",
errors
},
{
code: "foo.apply(null, args);",
output: "foo(...args);",
errors
},
{
code: "obj.foo.apply(obj, args);",
output: "obj.foo(...args);",
errors
},
{

// Not fixed: a.b.c might activate getters
code: "a.b.c.foo.apply(a.b.c, args);",
output: null,
errors
},
{

// Not fixed: a.b(x, y).c might activate getters
code: "a.b(x, y).c.foo.apply(a.b(x, y).c, args);",
output: null,
errors
},
{

// Not fixed (not an identifier)
code: "[].concat.apply([ ], args);",
output: null,
errors
},
{

// Not fixed (not an identifier)
code: "[].concat.apply([\n/*empty*/\n], args);",
output: null,
errors
}
]
Expand Down

0 comments on commit 3c90dd7

Please sign in to comment.