From f2b088dad4876a58e264a8c962ad8025623b4d7a Mon Sep 17 00:00:00 2001 From: Anix Date: Wed, 8 Apr 2020 15:48:59 +0000 Subject: [PATCH 1/2] Chore: nested array tests for array-element-newline --- tests/lib/rules/array-element-newline.js | 88 +++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/tests/lib/rules/array-element-newline.js b/tests/lib/rules/array-element-newline.js index b17af83763d..eeaa579c4c1 100644 --- a/tests/lib/rules/array-element-newline.js +++ b/tests/lib/rules/array-element-newline.js @@ -43,6 +43,8 @@ ruleTester.run("array-element-newline", rule, { "var foo = [1\n, 2\n, 3];", "var foo = [1,\n2,\n,\n3];", "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\nosomething();\n}\n];", + "var foo = [1,\n[2,\n3],\n4]", + "var foo = [[],\n[\n[]]]", { code: "var foo = [];", options: ["always"] }, { code: "var foo = [1];", options: ["always"] }, @@ -54,6 +56,7 @@ ruleTester.run("array-element-newline", rule, { { code: "var foo = [1,\n2 // any comment\n];", options: ["always"] }, { code: "var foo = [1,\n2,\n3];", options: ["always"] }, { code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];", options: ["always"] }, + { code: "var foo = [\n[1,\n2],\n3,\n[\n4]]", options: ["always"]}, // "never" { code: "var foo = [];", options: ["never"] }, @@ -65,6 +68,8 @@ ruleTester.run("array-element-newline", rule, { { code: "var foo = [1, 2, 3];", options: ["never"] }, { code: "var foo = [1, (\n2\n), 3];", options: ["never"] }, { code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];", options: ["never"] }, + { code: "var foo = [\n[1,2],3,[4]\n]", options: ["never"]}, + { code: "var foo = [[1,2\n],3,[4\n]\n]", options: ["never"]}, // "consistent" { code: "var foo = [];", options: ["consistent"] }, @@ -82,6 +87,9 @@ ruleTester.run("array-element-newline", rule, { { code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];", options: ["consistent"] }, { code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}];", options: ["consistent"] }, { code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}, function bar() {\ndosomething();\n}];", options: ["consistent"] }, + { code: "var foo = [1,\n[\n2,3,\n]\n];", options: ["consistent"] }, + { code: "var foo = [\n1,\n[2\n,3\n,]\n];", options: ["consistent"] }, + { code: "var foo = [\n1,[2,\n3]];", options: ["consistent"] }, // { multiline: true } { code: "var foo = [];", options: [{ multiline: true }] }, @@ -89,6 +97,7 @@ ruleTester.run("array-element-newline", rule, { { code: "var foo = [1, 2];", options: [{ multiline: true }] }, { code: "var foo = [1, 2, 3];", options: [{ multiline: true }] }, { code: "var f = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];", options: [{ multiline: true }] }, + { code: "var foo = [\n1,\n2,\n3,\n[\n]\n];", options: [{ multiline: true }] }, // { minItems: null } { code: "var foo = [];", options: [{ minItems: null }] }, @@ -96,6 +105,7 @@ ruleTester.run("array-element-newline", rule, { { code: "var foo = [1, 2];", options: [{ minItems: null }] }, { code: "var foo = [1, 2, 3];", options: [{ minItems: null }] }, { code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];", options: [{ minItems: null }] }, + { code: "var foo = [1, 2, 3, [[],1,[[]]]];", options: [{ minItems: null }] }, // { minItems: 0 } { code: "var foo = [];", options: [{ minItems: 0 }] }, @@ -103,6 +113,7 @@ ruleTester.run("array-element-newline", rule, { { code: "var foo = [1,\n2];", options: [{ minItems: 0 }] }, { code: "var foo = [1,\n2,\n3];", options: [{ minItems: 0 }] }, { code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];", options: [{ minItems: 0 }] }, + { code: "var foo = [\n1, \n2, \n3,\n[\n[],\n[]],\n[]];", options: [{ minItems: 0 }] }, // { minItems: 3 } { code: "var foo = [];", options: [{ minItems: 3 }] }, @@ -110,6 +121,7 @@ ruleTester.run("array-element-newline", rule, { { code: "var foo = [1, 2];", options: [{ minItems: 3 }] }, { code: "var foo = [1,\n2,\n3];", options: [{ minItems: 3 }] }, { code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];", options: [{ minItems: 3 }] }, + { code: "var foo = [[1,2],[[\n1,\n2,\n3]]];", options: [{ minItems: 3 }] }, // { multiline: true, minItems: 3 } { code: "var foo = [];", options: [{ multiline: true, minItems: 3 }] }, @@ -130,6 +142,10 @@ ruleTester.run("array-element-newline", rule, { { code: "var [// any comment \na,\nb] = foo;", parserOptions: { ecmaVersion: 6 } }, { code: "var [a,\nb // any comment\n] = foo;", parserOptions: { ecmaVersion: 6 } }, { code: "var [a,\nb,\nb] = foo;", parserOptions: { ecmaVersion: 6 } }, + { code: "var [\na,\n[\nb,\nc]] = foo;", parserOptions: { ecmaVersion: 6 } }, + + // "never" + { code: "var [a,[b,c]] = foo;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, // { minItems: 3 } { code: "var [] = foo;", options: [{ minItems: 3 }], parserOptions: { ecmaVersion: 6 } }, @@ -144,7 +160,19 @@ ruleTester.run("array-element-newline", rule, { { code: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], parserOptions: { ecmaVersion: 6 } }], invalid: [ - + { + code: "var foo = [\n1,[2,\n3]]", + output: "var foo = [\n1,\n[2,\n3]]", + errors : [ + { + line: 2, + column: 3, + messageId: 'missingLineBreak', + endLine: 2, + endColumn: 3, + } + ] + }, /* * ArrayExpression * "always" @@ -363,6 +391,17 @@ ruleTester.run("array-element-newline", rule, { } ] }, + { code: "var foo = [\n[1,\n2],\n3,[\n4]]", + output : "var foo = [\n[1,\n2],\n3,\n[\n4]]", + options: ["always"], + errors: [ + { + line: 4, + column: 3, + messageId: 'missingLineBreak', + } + ] + }, // "never" { @@ -471,6 +510,19 @@ ruleTester.run("array-element-newline", rule, { ] }, + { + code: "var foo = [[1,\n2\n],3,[4\n]\n]", + output: "var foo = [[1, 2\n],3,[4\n]\n]", + options: ["never"], + errors: [ + { + line: 1, + column: 15, + messageId: 'unexpectedLineBreak', + } + ] + }, + // "consistent" { code: "var foo = [1,\n2, 3];", @@ -552,6 +604,23 @@ ruleTester.run("array-element-newline", rule, { } ] }, + { + code: "var foo = [\n1,[2,3,\n[]],\n[]\n];", + output: "var foo = [\n1,\n[2,\n3,\n[]],\n[]\n];", + options: ["consistent"], + errors: [ + { + line: 2, + column: 3, + messageId: 'missingLineBreak', + }, + { + line: 2, + column: 6, + messageId: 'missingLineBreak', + } + ] + }, // { multiline: true } { @@ -590,6 +659,23 @@ ruleTester.run("array-element-newline", rule, { } ] }, + { + code: "var foo = [\n1,2,3,\n[\n]\n];", + output: "var foo = [\n1,\n2,\n3,\n[\n]\n];", + options: [{ multiline: true }], + errors : [ + { + line: 2, + column: 3, + messageId: 'missingLineBreak', + }, + { + line: 2, + column: 5, + messageId: 'missingLineBreak', + } + ] + }, // { minItems: null } { From 3045ffecb09f74ba72ec137f9c5e08dfff5c7dde Mon Sep 17 00:00:00 2001 From: Anix Date: Wed, 8 Apr 2020 15:56:04 +0000 Subject: [PATCH 2/2] Chore: linting fixes --- tests/lib/rules/array-element-newline.js | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/tests/lib/rules/array-element-newline.js b/tests/lib/rules/array-element-newline.js index eeaa579c4c1..195b5be45f5 100644 --- a/tests/lib/rules/array-element-newline.js +++ b/tests/lib/rules/array-element-newline.js @@ -56,7 +56,7 @@ ruleTester.run("array-element-newline", rule, { { code: "var foo = [1,\n2 // any comment\n];", options: ["always"] }, { code: "var foo = [1,\n2,\n3];", options: ["always"] }, { code: "var foo = [\nfunction foo() {\ndosomething();\n},\nfunction bar() {\ndosomething();\n}\n];", options: ["always"] }, - { code: "var foo = [\n[1,\n2],\n3,\n[\n4]]", options: ["always"]}, + { code: "var foo = [\n[1,\n2],\n3,\n[\n4]]", options: ["always"] }, // "never" { code: "var foo = [];", options: ["never"] }, @@ -68,8 +68,8 @@ ruleTester.run("array-element-newline", rule, { { code: "var foo = [1, 2, 3];", options: ["never"] }, { code: "var foo = [1, (\n2\n), 3];", options: ["never"] }, { code: "var foo = [\nfunction foo() {\ndosomething();\n}, function bar() {\ndosomething();\n}\n];", options: ["never"] }, - { code: "var foo = [\n[1,2],3,[4]\n]", options: ["never"]}, - { code: "var foo = [[1,2\n],3,[4\n]\n]", options: ["never"]}, + { code: "var foo = [\n[1,2],3,[4]\n]", options: ["never"] }, + { code: "var foo = [[1,2\n],3,[4\n]\n]", options: ["never"] }, // "consistent" { code: "var foo = [];", options: ["consistent"] }, @@ -163,16 +163,17 @@ ruleTester.run("array-element-newline", rule, { { code: "var foo = [\n1,[2,\n3]]", output: "var foo = [\n1,\n[2,\n3]]", - errors : [ + errors: [ { line: 2, column: 3, - messageId: 'missingLineBreak', + messageId: "missingLineBreak", endLine: 2, - endColumn: 3, + endColumn: 3 } ] }, + /* * ArrayExpression * "always" @@ -391,14 +392,15 @@ ruleTester.run("array-element-newline", rule, { } ] }, - { code: "var foo = [\n[1,\n2],\n3,[\n4]]", - output : "var foo = [\n[1,\n2],\n3,\n[\n4]]", + { + code: "var foo = [\n[1,\n2],\n3,[\n4]]", + output: "var foo = [\n[1,\n2],\n3,\n[\n4]]", options: ["always"], errors: [ { line: 4, column: 3, - messageId: 'missingLineBreak', + messageId: "missingLineBreak" } ] }, @@ -518,7 +520,7 @@ ruleTester.run("array-element-newline", rule, { { line: 1, column: 15, - messageId: 'unexpectedLineBreak', + messageId: "unexpectedLineBreak" } ] }, @@ -612,12 +614,12 @@ ruleTester.run("array-element-newline", rule, { { line: 2, column: 3, - messageId: 'missingLineBreak', + messageId: "missingLineBreak" }, { line: 2, column: 6, - messageId: 'missingLineBreak', + messageId: "missingLineBreak" } ] }, @@ -663,16 +665,16 @@ ruleTester.run("array-element-newline", rule, { code: "var foo = [\n1,2,3,\n[\n]\n];", output: "var foo = [\n1,\n2,\n3,\n[\n]\n];", options: [{ multiline: true }], - errors : [ + errors: [ { line: 2, column: 3, - messageId: 'missingLineBreak', + messageId: "missingLineBreak" }, { line: 2, column: 5, - messageId: 'missingLineBreak', + messageId: "missingLineBreak" } ] },