From d679dd89cfc672252eee3396c506dd45ed28f1d5 Mon Sep 17 00:00:00 2001 From: yeonjuan Date: Thu, 7 Nov 2019 21:15:02 +0900 Subject: [PATCH] Fix: invalid autofix in function-call-argument-newline (fixes #12454) --- lib/rules/function-call-argument-newline.js | 4 +- .../rules/function-call-argument-newline.js | 44 +++++++++++++++++++ 2 files changed, 47 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..04c74e416e6 100644 --- a/tests/lib/rules/function-call-argument-newline.js +++ b/tests/lib/rules/function-call-argument-newline.js @@ -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 + } + ] } ] });