File tree 3 files changed +26
-3
lines changed
3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -113,7 +113,8 @@ var scriptSources = [
113
113
"tslint/nextLineRule.ts" ,
114
114
"tslint/noNullRule.ts" ,
115
115
"tslint/preferConstRule.ts" ,
116
- "tslint/typeOperatorSpacingRule.ts"
116
+ "tslint/typeOperatorSpacingRule.ts" ,
117
+ "tslint/noInOperatorRule.ts"
117
118
] . map ( function ( f ) {
118
119
return path . join ( scriptsDirectory , f ) ;
119
120
} ) ;
@@ -875,7 +876,8 @@ var tslintRules = ([
875
876
"noNullRule" ,
876
877
"preferConstRule" ,
877
878
"booleanTriviaRule" ,
878
- "typeOperatorSpacingRule"
879
+ "typeOperatorSpacingRule" ,
880
+ "noInOperatorRule"
879
881
] ) ;
880
882
var tslintRulesFiles = tslintRules . map ( function ( p ) {
881
883
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 40
40
"no-null" : true ,
41
41
"boolean-trivia" : true ,
42
42
"type-operator-spacing" : true ,
43
- "prefer-const" : true
43
+ "prefer-const" : true ,
44
+ "no-in-operator" : true
44
45
}
45
46
}
You can’t perform that action at this time.
0 commit comments