@@ -13,15 +13,19 @@ export class Rule extends Lint.Rules.AbstractRule {
13
13
class TypeOperatorSpacingWalker extends Lint . RuleWalker {
14
14
public visitNode ( node : ts . Node ) {
15
15
if ( node . kind === ts . SyntaxKind . UnionType || node . kind === ts . SyntaxKind . IntersectionType ) {
16
- const types = ( < ts . UnionOrIntersectionTypeNode > node ) . types ;
17
- let expectedStart = types [ 0 ] . end + 2 ; // space, | or &
18
- for ( let i = 1 ; i < types . length ; i ++ ) {
19
- const currentType = types [ i ] ;
20
- if ( expectedStart !== currentType . pos || currentType . getLeadingTriviaWidth ( ) !== 1 ) {
21
- const failure = this . createFailure ( currentType . pos , currentType . getWidth ( ) , Rule . FAILURE_STRING ) ;
22
- this . addFailure ( failure ) ;
16
+ const { line : start } = ts . getLineAndCharacterOfPosition ( this . getSourceFile ( ) , node . getStart ( ) ) ;
17
+ const { line : end } = ts . getLineAndCharacterOfPosition ( this . getSourceFile ( ) , node . getEnd ( ) ) ;
18
+ if ( start === end ) {
19
+ const types = ( < ts . UnionOrIntersectionTypeNode > node ) . types ;
20
+ let expectedStart = types [ 0 ] . end + 2 ; // space, | or &
21
+ for ( let i = 1 ; i < types . length ; i ++ ) {
22
+ const currentType = types [ i ] ;
23
+ if ( expectedStart !== currentType . pos || currentType . getLeadingTriviaWidth ( ) !== 1 ) {
24
+ const failure = this . createFailure ( currentType . pos , currentType . getWidth ( ) , Rule . FAILURE_STRING ) ;
25
+ this . addFailure ( failure ) ;
26
+ }
27
+ expectedStart = currentType . end + 2 ;
23
28
}
24
- expectedStart = currentType . end + 2 ;
25
29
}
26
30
}
27
31
super . visitNode ( node ) ;
0 commit comments