File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed
packages/eslint-plugin-typescript Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ module.exports = {
45
45
} ,
46
46
47
47
create ( context ) {
48
+ const punctuators = [ ":" , "=>" ] ;
48
49
const sourceCode = context . getSourceCode ( ) ;
49
50
const options = context . options [ 0 ] || { } ;
50
51
@@ -78,12 +79,16 @@ module.exports = {
78
79
const nextToken = typeAnnotation ;
79
80
const punctuatorToken = sourceCode . getTokenBefore ( nextToken ) ;
80
81
const previousToken = sourceCode . getTokenBefore ( punctuatorToken ) ;
82
+ const type = punctuatorToken . value ;
83
+
84
+ if ( punctuators . indexOf ( type ) === - 1 ) {
85
+ return ;
86
+ }
81
87
82
88
const previousDelta =
83
89
punctuatorToken . range [ 0 ] - previousToken . range [ 1 ] ;
84
90
const nextDelta = nextToken . range [ 0 ] - punctuatorToken . range [ 1 ] ;
85
91
86
- const type = punctuatorToken . value ;
87
92
const before =
88
93
type === ":" ? colonOptions . before : arrowOptions . before ;
89
94
const after =
@@ -159,9 +164,7 @@ module.exports = {
159
164
}
160
165
} ,
161
166
TypeAnnotation ( node ) {
162
- if ( node . parent . type !== "TSAsExpression" ) {
163
- checkTypeAnnotationSpacing ( node . typeAnnotation ) ;
164
- }
167
+ checkTypeAnnotationSpacing ( node . typeAnnotation ) ;
165
168
} ,
166
169
FunctionDeclaration : checkFunctionReturnTypeSpacing ,
167
170
FunctionExpression : checkFunctionReturnTypeSpacing ,
Original file line number Diff line number Diff line change @@ -19,6 +19,14 @@ const ruleTester = new RuleTester();
19
19
20
20
ruleTester . run ( "type-annotation-spacing" , rule , {
21
21
valid : [
22
+ {
23
+ code : `
24
+ interface resolve {
25
+ resolver: (() => PromiseLike<T>) | PromiseLike<T>;
26
+ }
27
+ ` ,
28
+ parser : "typescript-eslint-parser"
29
+ } ,
22
30
{
23
31
code : "const foo = {} as Foo;" ,
24
32
parser : "typescript-eslint-parser"
@@ -1175,6 +1183,18 @@ class Foo {
1175
1183
` ,
1176
1184
options : [ { before : true } ] ,
1177
1185
parser : "typescript-eslint-parser"
1186
+ } ,
1187
+ {
1188
+ code : "let resolver: (() => PromiseLike<T>) | PromiseLike<T>;" ,
1189
+ parser : "typescript-eslint-parser"
1190
+ } ,
1191
+ {
1192
+ code : `
1193
+ interface resolve {
1194
+ resolver: (() => PromiseLike<T>) | PromiseLike<T>;
1195
+ }
1196
+ ` ,
1197
+ parser : "typescript-eslint-parser"
1178
1198
}
1179
1199
] ,
1180
1200
invalid : [
You can’t perform that action at this time.
0 commit comments