diff --git a/lib/rules/function-call-argument-newline.js b/lib/rules/function-call-argument-newline.js index 31ebc097c46..b6abbe95fa9 100644 --- a/lib/rules/function-call-argument-newline.js +++ b/lib/rules/function-call-argument-newline.js @@ -70,6 +70,8 @@ module.exports = { { includeComments: true } ); + const hasLineCommentBefore = tokenBefore.type === "Line"; + context.report({ node, loc: { @@ -77,7 +79,7 @@ module.exports = { end: currentArgToken.loc.start }, messageId: checker.messageId, - fix: checker.createFix(currentArgToken, tokenBefore) + fix: hasLineCommentBefore ? null : checker.createFix(currentArgToken, tokenBefore) }); } } diff --git a/tests/lib/rules/function-call-argument-newline.js b/tests/lib/rules/function-call-argument-newline.js index 6a5b739afbf..85c908a135d 100644 --- a/tests/lib/rules/function-call-argument-newline.js +++ b/tests/lib/rules/function-call-argument-newline.js @@ -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" */ { @@ -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 + } + ] } ] });