From d679dd89cfc672252eee3396c506dd45ed28f1d5 Mon Sep 17 00:00:00 2001 From: yeonjuan Date: Thu, 7 Nov 2019 21:15:02 +0900 Subject: [PATCH 1/3] 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 + } + ] } ] }); From 2404c7b410cdd08321f712b04da11ad6fb403b57 Mon Sep 17 00:00:00 2001 From: yeonjuan Date: Sat, 9 Nov 2019 19:54:42 +0900 Subject: [PATCH 2/3] Add test case for multi line comments --- tests/lib/rules/function-call-argument-newline.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/lib/rules/function-call-argument-newline.js b/tests/lib/rules/function-call-argument-newline.js index 04c74e416e6..934f587ff24 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,/* commeent */\nb)", + output: "fn(a,/* commeent */ b)", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [ + { + messageId: "unexpectedLineBreak", + line: 1, + column: 20, + endLine: 2, + endColumn: 1 + } + ] + }, /* "consistent" */ { From c33034be8f335d74b72c409e27894ff15d472c01 Mon Sep 17 00:00:00 2001 From: yeonjuan Date: Sun, 10 Nov 2019 15:14:05 +0900 Subject: [PATCH 3/3] Fix typo --- tests/lib/rules/function-call-argument-newline.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/lib/rules/function-call-argument-newline.js b/tests/lib/rules/function-call-argument-newline.js index 934f587ff24..85c908a135d 100644 --- a/tests/lib/rules/function-call-argument-newline.js +++ b/tests/lib/rules/function-call-argument-newline.js @@ -391,15 +391,15 @@ ruleTester.run("function-call-argument-newline", rule, { ] }, { - code: "fn(a,/* commeent */\nb)", - output: "fn(a,/* commeent */ b)", + code: "fn(a,/* comment */\nb)", + output: "fn(a,/* comment */ b)", options: ["never"], parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", line: 1, - column: 20, + column: 19, endLine: 2, endColumn: 1 }