Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: remove prefer-spread autofix (fixes #11330) #11365

Merged
merged 1 commit into from Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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