Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/do not raise generic spacing on line break #430

Merged
merged 5 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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