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
…#12539)

* Fix: invalid autofix in function-call-argument-newline (fixes #12454)

* Add test case for multi line comments

* Fix typo
  • Loading branch information
yeonjuan authored and kaicataldo committed Nov 10, 2019
1 parent 90305e0 commit 0afb518
Show file tree
Hide file tree
Showing 2 changed files with 62 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
59 changes: 59 additions & 0 deletions tests/lib/rules/function-call-argument-newline.js
Expand Up @@ -390,6 +390,21 @@ ruleTester.run("function-call-argument-newline", rule, {
}
]
},
{
code: "fn(a,/* comment */\nb)",
output: "fn(a,/* comment */ b)",
options: ["never"],
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "unexpectedLineBreak",
line: 1,
column: 19,
endLine: 2,
endColumn: 1
}
]
},

/* "consistent" */
{
Expand Down Expand Up @@ -505,6 +520,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 0afb518

Please sign in to comment.