33
44
55export class Rule extends Lint . Rules . AbstractRule {
6- public static FAILURE_STRING = "Place spaces around the '|' and '&' type operators" ;
6+ public static FAILURE_STRING = "The '|' and '&' operators must be surrounded by single spaces " ;
77
88 public apply ( sourceFile : ts . SourceFile ) : Lint . RuleFailure [ ] {
99 return this . applyWithWalker ( new TypeOperatorSpacingWalker ( sourceFile , this . getOptions ( ) ) ) ;
@@ -12,15 +12,16 @@ export class Rule extends Lint.Rules.AbstractRule {
1212
1313class TypeOperatorSpacingWalker extends Lint . RuleWalker {
1414 public visitNode ( node : ts . Node ) {
15- if ( node . kind === ts . SyntaxKind . UnionType || node . kind === ts . SyntaxKind . IntersectionType ) {
16- let typeNode = < ts . UnionOrIntersectionTypeNode > node ;
17- let expectedStart = typeNode . types [ 0 ] . end + 2 ; // space, | or &
18- for ( let i = 1 ; i < typeNode . types . length ; i ++ ) {
19- if ( expectedStart !== typeNode . types [ i ] . pos || typeNode . types [ i ] . getLeadingTriviaWidth ( ) !== 1 ) {
20- const failure = this . createFailure ( typeNode . types [ i ] . pos , typeNode . types [ i ] . getWidth ( ) , Rule . FAILURE_STRING ) ;
15+ if ( node . kind === ts . SyntaxKind . UnionType || node . kind === ts . SyntaxKind . IntersectionType ) {
16+ let types = ( < ts . UnionOrIntersectionTypeNode > node ) . types ;
17+ let expectedStart = types [ 0 ] . end + 2 ; // space, | or &
18+ for ( let i = 1 ; i < types . length ; i ++ ) {
19+ let currentType = types [ i ] ;
20+ if ( expectedStart !== currentType . pos || currentType . getLeadingTriviaWidth ( ) !== 1 ) {
21+ const failure = this . createFailure ( currentType . pos , currentType . getWidth ( ) , Rule . FAILURE_STRING ) ;
2122 this . addFailure ( failure ) ;
2223 }
23- expectedStart = typeNode . types [ i ] . end + 2 ;
24+ expectedStart = currentType . end + 2 ;
2425 }
2526 }
2627 super . visitNode ( node ) ;
0 commit comments