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

Fix: only remove arrow before body in object-shorthand (fixes #11305) #11307

Merged
merged 1 commit into from Feb 1, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+9 −1
Diff settings

Always

Just for now

Copy path View file
@@ -255,7 +255,7 @@ module.exports = {
keyPrefix + keyText + sourceCode.text.slice(tokenBeforeParams.range[1], node.value.range[1])
);
}
const arrowToken = sourceCode.getTokens(node.value).find(token => token.value === "=>");
const arrowToken = sourceCode.getTokenBefore(node.value.body, { filter: token => token.value === "=>" });
const tokenBeforeArrow = sourceCode.getTokenBefore(arrowToken);
const hasParensAroundParameters = tokenBeforeArrow.type === "Punctuator" && tokenBeforeArrow.value === ")";
const oldParamText = sourceCode.text.slice(sourceCode.getFirstToken(node.value, node.value.async ? 1 : 0).range[0], tokenBeforeArrow.range[1]);
@@ -931,6 +931,14 @@ ruleTester.run("object-shorthand", rule, {
parserOptions: { ecmaVersion: 8 },
errors: [METHOD_ERROR]
},
{

// https://github.com/eslint/eslint/issues/11305
code: "({ key: (arg = () => {}) => {} })",
output: "({ key(arg = () => {}) {} })",
options: ["always", { avoidExplicitReturnArrows: true }],
errors: [METHOD_ERROR]
},
{
code: `
function foo() {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.