Skip to content

Commit

Permalink
Update: fix false negative of arrow-spacing (fixes #7079) (#7080)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored and nzakas committed Sep 9, 2016
1 parent cec65e3 commit 08fa538
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
16 changes: 9 additions & 7 deletions lib/rules/arrow-spacing.js
Expand Up @@ -51,16 +51,18 @@ module.exports = {
* @returns {Object} Tokens of arrow and before/after arrow.
*/
function getTokens(node) {
let t = sourceCode.getFirstToken(node);
let before;
let arrow = sourceCode.getTokenBefore(node.body);

while (t.type !== "Punctuator" || t.value !== "=>") {
before = t;
t = sourceCode.getTokenAfter(t);
// skip '(' tokens.
while (arrow.value !== "=>") {
arrow = sourceCode.getTokenBefore(arrow);
}
const after = sourceCode.getTokenAfter(t);

return { before, arrow: t, after };
return {
before: sourceCode.getTokenBefore(arrow),
arrow,
after: sourceCode.getTokenAfter(arrow)
};
}

/**
Expand Down
26 changes: 25 additions & 1 deletion tests/lib/rules/arrow-spacing.js
Expand Up @@ -328,7 +328,31 @@ const invalid = [
errors: [
{ column: 1, line: 2, type: "Punctuator" }
]
}
},

// https://github.com/eslint/eslint/issues/7079
{
code: "(a = ()=>0)=>1",
output: "(a = () => 0) => 1",
parserOptions: { ecmaVersion: 6 },
errors: [
{ column: 7, line: 1, message: "Missing space before =>." },
{ column: 10, line: 1, message: "Missing space after =>." },
{ column: 11, line: 1, message: "Missing space before =>." },
{ column: 14, line: 1, message: "Missing space after =>." },
],
},
{
code: "(a = ()=>0)=>(1)",
output: "(a = () => 0) => (1)",
parserOptions: { ecmaVersion: 6 },
errors: [
{ column: 7, line: 1, message: "Missing space before =>." },
{ column: 10, line: 1, message: "Missing space after =>." },
{ column: 11, line: 1, message: "Missing space before =>." },
{ column: 14, line: 1, message: "Missing space after =>." },
],
},
];

ruleTester.run("arrow-spacing", rule, {
Expand Down

0 comments on commit 08fa538

Please sign in to comment.