diff --git a/lib/rules/key-spacing.js b/lib/rules/key-spacing.js index 994c35627f7..f407825a8ba 100644 --- a/lib/rules/key-spacing.js +++ b/lib/rules/key-spacing.js @@ -643,6 +643,10 @@ module.exports = { // Obey beforeColon and afterColon in each property as configured return { Property(node) { + if (node.parent.type !== "ObjectExpression") { + return; + } + verifySpacing(node, isSingleLine(node.parent) ? singleLineOptions : multiLineOptions); } }; diff --git a/tests/lib/rules/key-spacing.js b/tests/lib/rules/key-spacing.js index a9ed533741c..aeb7b9bd651 100644 --- a/tests/lib/rules/key-spacing.js +++ b/tests/lib/rules/key-spacing.js @@ -757,6 +757,22 @@ ruleTester.run("key-spacing", rule, { } }], parserOptions: { ecmaVersion: 6 } + }, + + // This rule does not check object pattern properties + { + code: "({ a : foo } = bar)", + options: [{ beforeColon: false }], + parserOptions: { ecmaVersion: 6 } + }, { + code: [ + "({", + " foo: a,", + " bar: b", + "} = baz)" + ].join("\n"), + options: [{ align: "value" }], + parserOptions: { ecmaVersion: 6 } }], invalid: [{