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

Chore: nested array tests for array-element-newline #13161

Merged
merged 2 commits into from Apr 23, 2020
Merged
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
88 changes: 88 additions & 0 deletions tests/lib/rules/array-element-newline.js
Expand Up @@ -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"] },
Expand All @@ -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"] },
Expand All @@ -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"] },
Expand All @@ -82,34 +87,41 @@ 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 }] },
{ code: "var foo = [1];", options: [{ multiline: true }] },
{ 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 }] },
{ code: "var foo = [1];", options: [{ minItems: null }] },
{ 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 }] },
{ code: "var foo = [1];", options: [{ minItems: 0 }] },
{ 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 }] },
{ code: "var foo = [1];", options: [{ minItems: 3 }] },
{ 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 }] },
Expand All @@ -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 } },
Expand All @@ -144,6 +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
Expand Down Expand Up @@ -363,6 +392,18 @@ 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"
{
Expand Down Expand Up @@ -471,6 +512,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];",
Expand Down Expand Up @@ -552,6 +606,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 }
{
Expand Down Expand Up @@ -590,6 +661,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 }
{
Expand Down