From e1d5d049ae12a024f6007772a7d57acef254ac3d Mon Sep 17 00:00:00 2001 From: angelica-bocanegra <58057927+angelica-bocanegra@users.noreply.github.com> Date: Wed, 24 Feb 2021 13:31:03 +1100 Subject: [PATCH] fix: object-type-curly-spacing should not throw errors on multiple spaces on option always (#466) * fix: object-type-curly-spacing should not throw error when there are multiple spaces * chore: add tests Co-authored-by: Angelica Bocanegra --- README.md | 8 +++++++ src/rules/objectTypeCurlySpacing.js | 22 ++----------------- .../assertions/objectTypeCurlySpacing.js | 8 +++++++ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ea7fa6b..d0e19c6 100644 --- a/README.md +++ b/README.md @@ -2611,6 +2611,14 @@ type obj = {| "foo": "bar" |} // Options: ["always"] type obj = { "foo": "bar", [key: string]: string } + +// Options: ["always"] +type obj = { baz: { "foo": "qux" }, bar: 4 } + +// Options: ["always"] +type obj = { + baz: { "foo": "qux" }, bar: 4 +} ``` diff --git a/src/rules/objectTypeCurlySpacing.js b/src/rules/objectTypeCurlySpacing.js index 92f03e8..76520f5 100644 --- a/src/rules/objectTypeCurlySpacing.js +++ b/src/rules/objectTypeCurlySpacing.js @@ -57,16 +57,7 @@ const create = (context) => { } } } else { - if (spacesBefore > 1) { - context.report({ - data: { - token: opener.value, - }, - fix: spacingFixers.stripSpacesAfter(opener, spacesBefore - 1), - message: 'Only one space is required after "{{token}}".', - node, - }); - } else if (spacesBefore === 0) { + if (!spacesBefore) { context.report({ data: { token: opener.value, @@ -77,16 +68,7 @@ const create = (context) => { }); } - if (spacesAfter > 1) { - context.report({ - data: { - token: closer.value, - }, - fix: spacingFixers.stripSpacesAfter(lastInnerToken, spacesAfter - 1), - message: 'Only one space is required before "{{token}}".', - node, - }); - } else if (spacesAfter === 0) { + if (!spacesAfter) { context.report({ data: { token: closer.value, diff --git a/tests/rules/assertions/objectTypeCurlySpacing.js b/tests/rules/assertions/objectTypeCurlySpacing.js index 149f5f6..c3fdeab 100644 --- a/tests/rules/assertions/objectTypeCurlySpacing.js +++ b/tests/rules/assertions/objectTypeCurlySpacing.js @@ -173,5 +173,13 @@ export default { code: 'type obj = { "foo": "bar", [key: string]: string }', options: ['always'], }, + { + code: 'type obj = { baz: { "foo": "qux" }, bar: 4 }', + options: ['always'], + }, + { + code: 'type obj = {\n baz: { "foo": "qux" }, bar: 4\n}', + options: ['always'], + }, ], };