@@ -30,6 +30,7 @@ const OPTION_SEPARATOR = "check-separator";
3030const OPTION_REST_SPREAD = "check-rest-spread" ;
3131const OPTION_TYPE = "check-type" ;
3232const OPTION_TYPECAST = "check-typecast" ;
33+ const OPTION_TYPE_OPERATOR = "check-type-operator" ;
3334const OPTION_PREBLOCK = "check-preblock" ;
3435
3536export class Rule extends Lint . Rules . AbstractRule {
@@ -48,16 +49,19 @@ export class Rule extends Lint.Rules.AbstractRule {
4849 * \`"check-rest-spread"\` checks that there is no whitespace after rest/spread operator (\`...\`).
4950 * \`"check-type"\` checks for whitespace before a variable type specification.
5051 * \`"check-typecast"\` checks for whitespace between a typecast and its target.
52+ * \`"check-type-operator"\` checks for whitespace between type operators \`|\` and \`&\`.
5153 * \`"check-preblock"\` checks for whitespace before the opening brace of a block` ,
5254 options : {
5355 type : "array" ,
5456 items : {
5557 type : "string" ,
56- enum : [ "check-branch" , "check-decl" , "check-operator" , "check-module" ,
57- "check-separator" , "check-rest-spread" , "check-type" , "check-typecast" , "check-preblock" ] ,
58+ enum : [
59+ "check-branch" , "check-decl" , "check-operator" , "check-module" , "check-separator" ,
60+ "check-rest-spread" , "check-type" , "check-typecast" , "check-type-operator" , "check-preblock" ,
61+ ] ,
5862 } ,
5963 minLength : 0 ,
60- maxLength : 9 ,
64+ maxLength : 10 ,
6165 } ,
6266 optionExamples : [ [ true , "check-branch" , "check-operator" , "check-typecast" ] ] ,
6367 type : "style" ,
@@ -72,7 +76,10 @@ export class Rule extends Lint.Rules.AbstractRule {
7276 }
7377}
7478
75- type Options = Record < "branch" | "decl" | "operator" | "module" | "separator" | "restSpread" | "type" | "typecast" | "preblock" , boolean > ;
79+ type Options = Record <
80+ "branch" | "decl" | "operator" | "module" | "separator" | "restSpread" | "type" | "typecast" | "typeOperator" | "preblock" ,
81+ boolean > ;
82+
7683function parseOptions ( ruleArguments : string [ ] ) : Options {
7784 return {
7885 branch : has ( OPTION_BRANCH ) ,
@@ -83,6 +90,7 @@ function parseOptions(ruleArguments: string[]): Options {
8390 restSpread : has ( OPTION_REST_SPREAD ) ,
8491 type : has ( OPTION_TYPE ) ,
8592 typecast : has ( OPTION_TYPECAST ) ,
93+ typeOperator : has ( OPTION_TYPE_OPERATOR ) ,
8694 preblock : has ( OPTION_PREBLOCK ) ,
8795 } ;
8896
@@ -194,7 +202,7 @@ function walk(ctx: Lint.WalkContext<Options>) {
194202 case ts . SyntaxKind . VariableDeclaration :
195203 const { name, type, initializer } = node as ts . VariableDeclaration ;
196204 if ( options . decl && initializer !== undefined ) {
197- checkForTrailingWhitespace ( ( type !== undefined ? type : name ) . getEnd ( ) ) ;
205+ checkForTrailingWhitespace ( ( type !== undefined ? type : name ) . getEnd ( ) ) ;
198206 }
199207 break ;
200208
@@ -212,6 +220,21 @@ function walk(ctx: Lint.WalkContext<Options>) {
212220 const position = ( node as ts . SpreadAssignment ) . expression . getFullStart ( ) ;
213221 checkForExcessiveWhitespace ( position ) ;
214222 }
223+ break ;
224+
225+ case ts . SyntaxKind . UnionType :
226+ case ts . SyntaxKind . IntersectionType :
227+ if ( options . typeOperator ) {
228+ const { types } = node as ts . UnionOrIntersectionTypeNode ;
229+ types . forEach ( ( typeNode , index ) => {
230+ if ( index > 0 ) {
231+ checkForTrailingWhitespace ( typeNode . getFullStart ( ) ) ;
232+ }
233+ if ( index < types . length - 1 ) {
234+ checkForTrailingWhitespace ( typeNode . getEnd ( ) ) ;
235+ }
236+ } ) ;
237+ }
215238 }
216239
217240 ts . forEachChild ( node , cb ) ;
@@ -262,7 +285,7 @@ function walk(ctx: Lint.WalkContext<Options>) {
262285 ( parent as ts . CallExpression ) . expression . kind === ts . SyntaxKind . ImportKeyword ) {
263286 return ; // Don't check ImportCall
264287 }
265- // falls through
288+ // falls through
266289 case ts . SyntaxKind . ExportKeyword :
267290 case ts . SyntaxKind . FromKeyword :
268291 if ( options . typecast ) {
0 commit comments