From 8da525f052efa72499e45af3892453ef98a348c5 Mon Sep 17 00:00:00 2001 From: Phil Quinn Date: Fri, 6 Oct 2017 05:23:50 +0100 Subject: [PATCH] Fix: recognise multiline comments as multiline arrays (fixes #9211) (#9369) --- lib/rules/array-bracket-newline.js | 6 ++++++ tests/lib/rules/array-bracket-newline.js | 3 +++ 2 files changed, 9 insertions(+) diff --git a/lib/rules/array-bracket-newline.js b/lib/rules/array-bracket-newline.js index 319ac60f2cd..adfce985fdd 100644 --- a/lib/rules/array-bracket-newline.js +++ b/lib/rules/array-bracket-newline.js @@ -194,6 +194,12 @@ module.exports = { options.multiline && elements.length > 0 && firstIncComment.loc.start.line !== lastIncComment.loc.end.line + ) || + ( + elements.length === 0 && + firstIncComment.type === "Block" && + firstIncComment.loc.start.line !== lastIncComment.loc.end.line && + firstIncComment === lastIncComment ) ); diff --git a/tests/lib/rules/array-bracket-newline.js b/tests/lib/rules/array-bracket-newline.js index d4e76dfc6ab..cf02cbdf6fe 100644 --- a/tests/lib/rules/array-bracket-newline.js +++ b/tests/lib/rules/array-bracket-newline.js @@ -40,6 +40,8 @@ ruleTester.run("array-bracket-newline", rule, { "var foo = [\n1, 2\n// any comment\n];", "var foo = [\n1,\n2\n];", "var foo = [\nfunction foo() {\nreturn dosomething();\n}\n];", + "var foo = [/* \nany comment\n */];", + "var foo = [/* single line multiline comment for no real reason */];", // "always" { code: "var foo = [\n];", options: ["always"] }, @@ -72,6 +74,7 @@ ruleTester.run("array-bracket-newline", rule, { { code: "var foo = [\n1, 2\n// any comment\n];", options: [{ multiline: true }] }, { code: "var foo = [\n1,\n2\n];", options: [{ multiline: true }] }, { code: "var foo = [\nfunction foo() {\nreturn dosomething();\n}\n];", options: [{ multiline: true }] }, + { code: "var foo = [/* \nany comment\n */];", options: [{ multiline: true }] }, // { multiline: false } { code: "var foo = [];", options: [{ multiline: false }] },