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: Add object-property-newline tests to increase coverage. #9553

Merged
merged 1 commit into from Nov 1, 2017
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
46 changes: 46 additions & 0 deletions tests/lib/rules/object-property-newline.js
Expand Up @@ -24,7 +24,9 @@ ruleTester.run("object-property-newline", rule, {

// default-case
"var obj = {\nk1: 'val1',\nk2: 'val2',\nk3: 'val3',\nk4: 'val4'\n};",
"var obj = {\nk1: 'val1'\n, k2: 'val2'\n, k3: 'val3'\n, k4: 'val4'\n};",
"var obj = { k1: 'val1',\nk2: 'val2',\nk3: 'val3',\nk4: 'val4' };",
"var obj = { k1: 'val1'\n, k2: 'val2'\n, k3: 'val3'\n, k4: 'val4' };",
"var obj = { k1: 'val1' };",
"var obj = {\nk1: 'val1'\n};",
"var obj = {};",
Expand Down Expand Up @@ -173,6 +175,18 @@ ruleTester.run("object-property-newline", rule, {
}
]
},
{
code: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n], k3: 'val3' };",
output: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n],\nk3: 'val3' };",
errors: [
{
message: "Object properties must go on a new line.",
type: "ObjectExpression",
line: 4,
column: 4
}
]
},
{
code: "var obj = { k1: 'val1', [\nk2]: 'val2' };",
output: "var obj = { k1: 'val1',\n[\nk2]: 'val2' };",
Expand Down Expand Up @@ -378,6 +392,25 @@ ruleTester.run("object-property-newline", rule, {
}
]
},
{
code: "var obj = {\nk1:\n'val1', k2: 'val2', k3:\n'val3'\n};",
output: "var obj = {\nk1:\n'val1',\nk2: 'val2',\nk3:\n'val3'\n};",
options: [{ allowMultiplePropertiesPerLine: true }],
errors: [
{
message: "Object properties must go on a new line if they aren't all on the same line.",
type: "ObjectExpression",
line: 3,
column: 9
},
{
message: "Object properties must go on a new line if they aren't all on the same line.",
type: "ObjectExpression",
line: 3,
column: 21
}
]
},
{
code: "var obj = {k1: [\n'foo',\n'bar'\n], k2: 'val1'};",
output: "var obj = {k1: [\n'foo',\n'bar'\n],\nk2: 'val1'};",
Expand Down Expand Up @@ -423,6 +456,19 @@ ruleTester.run("object-property-newline", rule, {
}
]
},
{
code: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n], k3: 'val3' };",
output: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n],\nk3: 'val3' };",
options: [{ allowMultiplePropertiesPerLine: true }],
errors: [
{
message: "Object properties must go on a new line if they aren't all on the same line.",
type: "ObjectExpression",
line: 4,
column: 4
}
]
},
{
code: "var obj = { [\nk1]: 'val1', k2: 'val2' };",
output: "var obj = { [\nk1]: 'val1',\nk2: 'val2' };",
Expand Down