Skip to content

Commit

Permalink
Fix: recognise multiline comments as multiline arrays (fixes #9211) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
philquinn authored and not-an-aardvark committed Oct 6, 2017
1 parent c581b77 commit 8da525f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rules/array-bracket-newline.js
Expand Up @@ -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
)
);

Expand Down
3 changes: 3 additions & 0 deletions tests/lib/rules/array-bracket-newline.js
Expand Up @@ -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"] },
Expand Down Expand Up @@ -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 }] },
Expand Down

0 comments on commit 8da525f

Please sign in to comment.