Skip to content

Commit

Permalink
Fix: array-bracket-newline consistent error with comments (fixes #12416)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Oct 15, 2019
1 parent b962775 commit 3e71b0f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/array-bracket-newline.js
Expand Up @@ -216,7 +216,7 @@ module.exports = {
) ||
(
options.consistent &&
firstIncComment.loc.start.line !== openBracket.loc.end.line
openBracket.loc.end.line !== first.loc.start.line
)
);

Expand Down
39 changes: 39 additions & 0 deletions tests/lib/rules/array-bracket-newline.js
Expand Up @@ -65,6 +65,10 @@ ruleTester.run("array-bracket-newline", rule, {
{ code: "var a = [\n]", options: ["consistent"] },
{ code: "var a = [1]", options: ["consistent"] },
{ code: "var a = [\n1\n]", options: ["consistent"] },
{ code: "var a = [//\n1\n]", options: ["consistent"] },
{ code: "var a = [/**/\n1\n]", options: ["consistent"] },
{ code: "var a = [/*\n*/1\n]", options: ["consistent"] },
{ code: "var a = [//\n]", options: ["consistent"] },

// { multiline: true }
{ code: "var foo = [];", options: [{ multiline: true }] },
Expand Down Expand Up @@ -156,6 +160,10 @@ ruleTester.run("array-bracket-newline", rule, {
{ code: "var [\n] = foo", options: ["consistent"], parserOptions: { ecmaVersion: 6 } },
{ code: "var [a] = foo", options: ["consistent"], parserOptions: { ecmaVersion: 6 } },
{ code: "var [\na\n] = foo", options: ["consistent"], parserOptions: { ecmaVersion: 6 } },
{ code: "var [//\na\n] = foo", options: ["consistent"], parserOptions: { ecmaVersion: 6 } },
{ code: "var [/**/\na\n] = foo", options: ["consistent"], parserOptions: { ecmaVersion: 6 } },
{ code: "var [/*\n*/a\n] = foo", options: ["consistent"], parserOptions: { ecmaVersion: 6 } },
{ code: "var [//\n] = foo", options: ["consistent"], parserOptions: { ecmaVersion: 6 } },

// { multiline: true }
{ code: "var [] = foo;", options: [{ multiline: true }], parserOptions: { ecmaVersion: 6 } },
Expand Down Expand Up @@ -529,6 +537,21 @@ ruleTester.run("array-bracket-newline", rule, {
}
]
},
{
code: "var foo = [//\n1]",
output: "var foo = [//\n1\n]",
options: ["consistent"],
errors: [
{
messageId: "missingClosingLinebreak",
type: "ArrayExpression",
line: 2,
column: 2,
endLine: 2,
endColumn: 3
}
]
},

// { multiline: true }
{
Expand Down Expand Up @@ -1459,6 +1482,22 @@ ruleTester.run("array-bracket-newline", rule, {
}
]
},
{
code: "var [//\na] = foo",
output: "var [//\na\n] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingClosingLinebreak",
type: "ArrayPattern",
line: 2,
column: 2,
endLine: 2,
endColumn: 3
}
]
},

// { minItems: 2 }
{
Expand Down

0 comments on commit 3e71b0f

Please sign in to comment.