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

Fix: Allow separate mode option for multiline and align (fixes #6691) #6991

Merged
merged 1 commit into from Aug 30, 2016
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion lib/rules/key-spacing.js
Expand Up @@ -136,7 +136,7 @@ function initOptions(toOptions, fromOptions) {
if (toOptions.multiLine.align) {
toOptions.align = {
on: toOptions.multiLine.align.on,
mode: toOptions.multiLine.mode,
mode: toOptions.multiLine.align.mode || toOptions.multiLine.mode,
beforeColon: toOptions.multiLine.align.beforeColon,
afterColon: toOptions.multiLine.align.afterColon
};
Expand Down Expand Up @@ -289,6 +289,9 @@ module.exports = {
multiLine: {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"]
},
beforeColon: {
type: "boolean"
},
Expand Down
106 changes: 106 additions & 0 deletions tests/lib/rules/key-spacing.js
Expand Up @@ -711,6 +711,56 @@ ruleTester.run("key-spacing", rule, {
}
}],
parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }
}, {
code: [
"var obj = {",
" key1: 1,",
"",
" key2: 2,",
" key3: 3,",
"",
" key4: 4",
"}"
].join("\n"),
options: [{
multiLine: {
beforeColon: false,
afterColon: true,
mode: "strict",
align: {
beforeColon: false,
afterColon: true,
on: "colon",
mode: "minimum"
}
}
}],
parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }
}, {
code: [
"var obj = {",
" key1: 1,",
"",
" key2: 2,",
" key3: 3,",
"",
" key4: 4",
"}"
].join("\n"),
options: [{
multiLine: {
beforeColon: false,
afterColon: true,
mode: "strict"
},
align: {
beforeColon: false,
afterColon: true,
on: "colon",
mode: "minimum"
}
}],
parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }
}],

invalid: [{
Expand Down Expand Up @@ -1622,5 +1672,61 @@ ruleTester.run("key-spacing", rule, {
{ message: "Extra space before value for key \'func2\'.", line: 8, column: 16, type: "FunctionExpression" },
{ message: "Extra space after key \'singleLine\'.", line: 11, column: 5, type: "Identifier" }
]
}, {
code: [
"var obj = {",
" key1: 1,",
"",
" key2: 2,",
" key3: 3,",
"",
" key4: 4",
"}"
].join("\n"),
options: [{
multiLine: {
beforeColon: false,
afterColon: true,
mode: "strict",
align: {
beforeColon: false,
afterColon: true,
on: "colon",
}
}
}],
parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } },
errors: [
{ message: "Extra space before value for key \'key2\'.", line: 4, column: 14, type: "Literal" },
{ message: "Extra space before value for key \'key3\'.", line: 5, column: 14, type: "Literal" }
]
}, {
code: [
"var obj = {",
" key1: 1,",
"",
" key2: 2,",
" key3: 3,",
"",
" key4: 4",
"}"
].join("\n"),
options: [{
multiLine: {
beforeColon: false,
afterColon: true,
mode: "strict"
},
align: {
beforeColon: false,
afterColon: true,
on: "colon",
}
}],
parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } },
errors: [
{ message: "Extra space before value for key \'key2\'.", line: 4, column: 14, type: "Literal" },
{ message: "Extra space before value for key \'key3\'.", line: 5, column: 14, type: "Literal" }
]
}]
});