Skip to content

Commit

Permalink
feat: do not raise generic spacing on line break (#430)
Browse files Browse the repository at this point in the history
* feat: Allow multiline formatting for generic-spacing ("never" config)

* chore: Make sure all contributors have the same dependencies version

* docs: Auto-generate readme

* docs: Explain to future contributors that they should re-generating the readme

* Delete yarn.lock
  • Loading branch information
AmauryLiet authored and gajus committed Sep 3, 2019
1 parent 2627ef0 commit 63815f9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Run them with `npm test`.

Run with `npm run lint`.

## Submitting a PR

Just before submitting a PR, run `npm run create-readme` to generate the new README.md

## Adding a Rule

### Source & Tests
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,12 @@ type X = Promise<(string)>

type X = Promise<(foo), bar, (((baz)))>

type X = Promise<
(foo),
bar,
(((baz))),
>

// Options: ["always"]
type X = Promise< string >

Expand Down
28 changes: 16 additions & 12 deletions src/rules/genericSpacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@ const create = (context) => {

if (never) {
if (spacesBefore) {
context.report({
data: {name: node.id.name},
fix: spacingFixers.stripSpacesAfter(opener, spacesBefore),
message: 'There must be no space at start of "{{name}}" generic type annotation',
node: types,
});
if (sourceCode.text[opener.end] !== '\n') {
context.report({
data: {name: node.id.name},
fix: spacingFixers.stripSpacesAfter(opener, spacesBefore),
message: 'There must be no space at start of "{{name}}" generic type annotation',
node: types,
});
}
}

if (spacesAfter) {
context.report({
data: {name: node.id.name},
fix: spacingFixers.stripSpacesAfter(lastInnerToken, spacesAfter),
message: 'There must be no space at end of "{{name}}" generic type annotation',
node: types,
});
if (sourceCode.text[closer.start - 1] !== '\n') {
context.report({
data: {name: node.id.name},
fix: spacingFixers.stripSpacesAfter(lastInnerToken, spacesAfter),
message: 'There must be no space at end of "{{name}}" generic type annotation',
node: types,
});
}
}
} else {
if (spacesBefore > 1) {
Expand Down
6 changes: 6 additions & 0 deletions tests/rules/assertions/genericSpacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ export default {
{code: 'type X = Promise<string>'},
{code: 'type X = Promise<(string)>'},
{code: 'type X = Promise<(foo), bar, (((baz)))>'},
{code:
`type X = Promise<
(foo),
bar,
(((baz))),
>`},

// Always

Expand Down

0 comments on commit 63815f9

Please sign in to comment.