From 0afb518d1f139376245613dddd8eaef32b52d619 Mon Sep 17 00:00:00 2001 From: YeonJuan Date: Sun, 10 Nov 2019 15:49:14 +0900 Subject: [PATCH] Fix: invalid autofix in function-call-argument-newline (fixes #12454) (#12539) * Fix: invalid autofix in function-call-argument-newline (fixes #12454) * Add test case for multi line comments * Fix typo --- lib/rules/function-call-argument-newline.js | 4 +- .../rules/function-call-argument-newline.js | 59 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) 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 + } + ] } ] });