Skip to content

Commit

Permalink
Fix: Allow separate mode option for multiline and align (fixes #6691) (
Browse files Browse the repository at this point in the history
  • Loading branch information
annie authored and nzakas committed Aug 30, 2016
1 parent a989a7c commit 256c4a2
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
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" }
]
}]
});

0 comments on commit 256c4a2

Please sign in to comment.