File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -113,7 +113,8 @@ var scriptSources = [
113113 "tslint/nextLineRule.ts" ,
114114 "tslint/noNullRule.ts" ,
115115 "tslint/preferConstRule.ts" ,
116- "tslint/typeOperatorSpacingRule.ts"
116+ "tslint/typeOperatorSpacingRule.ts" ,
117+ "tslint/noInOperatorRule.ts"
117118] . map ( function ( f ) {
118119 return path . join ( scriptsDirectory , f ) ;
119120} ) ;
@@ -875,7 +876,8 @@ var tslintRules = ([
875876 "noNullRule" ,
876877 "preferConstRule" ,
877878 "booleanTriviaRule" ,
878- "typeOperatorSpacingRule"
879+ "typeOperatorSpacingRule" ,
880+ "noInOperatorRule"
879881] ) ;
880882var tslintRulesFiles = tslintRules . map ( function ( p ) {
881883 return path . join ( tslintRuleDir , p + ".ts" ) ;
Original file line number Diff line number Diff line change 1+ import * as Lint from "tslint/lib/lint" ;
2+ import * as ts from "typescript" ;
3+
4+
5+ export class Rule extends Lint . Rules . AbstractRule {
6+ public static FAILURE_STRING = "Don't use the 'in' keyword - use 'hasProperty' to check for key presence instead" ;
7+
8+ public apply ( sourceFile : ts . SourceFile ) : Lint . RuleFailure [ ] {
9+ return this . applyWithWalker ( new InWalker ( sourceFile , this . getOptions ( ) ) ) ;
10+ }
11+ }
12+
13+ class InWalker extends Lint . RuleWalker {
14+ visitNode ( node : ts . Node ) {
15+ super . visitNode ( node ) ;
16+ if ( node . kind === ts . SyntaxKind . InKeyword && node . parent && node . parent . kind === ts . SyntaxKind . BinaryExpression ) {
17+ this . addFailure ( this . createFailure ( node . getStart ( ) , node . getWidth ( ) , Rule . FAILURE_STRING ) ) ;
18+ }
19+ }
20+ }
Original file line number Diff line number Diff line change 4040 "no-null" : true ,
4141 "boolean-trivia" : true ,
4242 "type-operator-spacing" : true ,
43- "prefer-const" : true
43+ "prefer-const" : true ,
44+ "no-in-operator" : true
4445 }
4546}
You can’t perform that action at this time.
0 commit comments