Skip to content

Commit

Permalink
Fix: invalid autofix in function-call-argument-newline (fixes #12454)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjuan committed Nov 7, 2019
1 parent 5868550 commit d679dd8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rules/function-call-argument-newline.js
Expand Up @@ -70,14 +70,16 @@ module.exports = {
{ includeComments: true }
);

const hasLineCommentBefore = tokenBefore.type === "Line";

context.report({
node,
loc: {
start: tokenBefore.loc.end,
end: currentArgToken.loc.start
},
messageId: checker.messageId,
fix: checker.createFix(currentArgToken, tokenBefore)
fix: hasLineCommentBefore ? null : checker.createFix(currentArgToken, tokenBefore)
});
}
}
Expand Down
44 changes: 44 additions & 0 deletions tests/lib/rules/function-call-argument-newline.js
Expand Up @@ -505,6 +505,50 @@ ruleTester.run("function-call-argument-newline", rule, {
endColumn: 1
}
]
},
{
code: "fn(a,// comment\n{b, c})",
output: null,
options: ["never"],
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "unexpectedLineBreak",
line: 1,
column: 16,
endLine: 2,
endColumn: 1
}
]
},
{
code: "fn(a, // comment\nb)",
output: null,
options: ["never"],
errors: [
{
messageId: "unexpectedLineBreak",
line: 1,
column: 17,
endLine: 2,
endColumn: 1
}
]
},
{
code: "fn(`\n`, b, // comment\nc)",
output: null,
options: ["consistent"],
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "unexpectedLineBreak",
line: 2,
column: 17,
endLine: 3,
endColumn: 1
}
]
}
]
});

0 comments on commit d679dd8

Please sign in to comment.