Skip to content

Commit

Permalink
fix: object-type-curly-spacing should not throw errors on multiple sp…
Browse files Browse the repository at this point in the history
…aces 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 <angelica.bocanegra@tabcorp.com.au>
  • Loading branch information
angelica-bocanegra and Angelica Bocanegra committed Feb 24, 2021
1 parent 1a4939a commit e1d5d04
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -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
}
```
Expand Down
22 changes: 2 additions & 20 deletions src/rules/objectTypeCurlySpacing.js
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions tests/rules/assertions/objectTypeCurlySpacing.js
Expand Up @@ -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'],
},
],
};

0 comments on commit e1d5d04

Please sign in to comment.