From 51fbbd78f98f223d17071650f5117d07f60dadc2 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Sun, 20 Oct 2019 21:10:42 +0200 Subject: [PATCH] Fix: array-bracket-newline consistent error with comments (fixes #12416) (#12441) --- lib/rules/array-bracket-newline.js | 2 +- tests/lib/rules/array-bracket-newline.js | 39 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/rules/array-bracket-newline.js b/lib/rules/array-bracket-newline.js index 21463177762..b4b4dd430f6 100644 --- a/lib/rules/array-bracket-newline.js +++ b/lib/rules/array-bracket-newline.js @@ -216,7 +216,7 @@ module.exports = { ) || ( options.consistent && - firstIncComment.loc.start.line !== openBracket.loc.end.line + openBracket.loc.end.line !== first.loc.start.line ) ); diff --git a/tests/lib/rules/array-bracket-newline.js b/tests/lib/rules/array-bracket-newline.js index b1603fcd5a8..d20c365dbc4 100644 --- a/tests/lib/rules/array-bracket-newline.js +++ b/tests/lib/rules/array-bracket-newline.js @@ -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 }] }, @@ -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 } }, @@ -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 } { @@ -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 } {