Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: recognise multiline comments as multiline arrays (fixes #9211) #9369

Merged
merged 1 commit into from Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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