Skip to content

Commit 63815f9

Browse files
AmauryLietgajus
authored andcommitted
feat: do not raise generic spacing on line break (#430)
* 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
1 parent 2627ef0 commit 63815f9

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Run them with `npm test`.
3131

3232
Run with `npm run lint`.
3333

34+
## Submitting a PR
35+
36+
Just before submitting a PR, run `npm run create-readme` to generate the new README.md
37+
3438
## Adding a Rule
3539

3640
### Source & Tests

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,12 @@ type X = Promise<(string)>
13281328

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

1331+
type X = Promise<
1332+
(foo),
1333+
bar,
1334+
(((baz))),
1335+
>
1336+
13311337
// Options: ["always"]
13321338
type X = Promise< string >
13331339

src/rules/genericSpacing.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,25 @@ const create = (context) => {
3131

3232
if (never) {
3333
if (spacesBefore) {
34-
context.report({
35-
data: {name: node.id.name},
36-
fix: spacingFixers.stripSpacesAfter(opener, spacesBefore),
37-
message: 'There must be no space at start of "{{name}}" generic type annotation',
38-
node: types,
39-
});
34+
if (sourceCode.text[opener.end] !== '\n') {
35+
context.report({
36+
data: {name: node.id.name},
37+
fix: spacingFixers.stripSpacesAfter(opener, spacesBefore),
38+
message: 'There must be no space at start of "{{name}}" generic type annotation',
39+
node: types,
40+
});
41+
}
4042
}
4143

4244
if (spacesAfter) {
43-
context.report({
44-
data: {name: node.id.name},
45-
fix: spacingFixers.stripSpacesAfter(lastInnerToken, spacesAfter),
46-
message: 'There must be no space at end of "{{name}}" generic type annotation',
47-
node: types,
48-
});
45+
if (sourceCode.text[closer.start - 1] !== '\n') {
46+
context.report({
47+
data: {name: node.id.name},
48+
fix: spacingFixers.stripSpacesAfter(lastInnerToken, spacesAfter),
49+
message: 'There must be no space at end of "{{name}}" generic type annotation',
50+
node: types,
51+
});
52+
}
4953
}
5054
} else {
5155
if (spacesBefore > 1) {

tests/rules/assertions/genericSpacing.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ export default {
129129
{code: 'type X = Promise<string>'},
130130
{code: 'type X = Promise<(string)>'},
131131
{code: 'type X = Promise<(foo), bar, (((baz)))>'},
132+
{code:
133+
`type X = Promise<
134+
(foo),
135+
bar,
136+
(((baz))),
137+
>`},
132138

133139
// Always
134140

0 commit comments

Comments
 (0)