File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ const Lint = require ( 'tslint' ) ;
2
+ const ERROR_MESSAGE = 'Uses of RxJS patch imports are forbidden.' ;
3
+
4
+ /**
5
+ * Rule that prevents uses of RxJS patch imports (e.g. `import 'rxjs/add/operator/map').
6
+ * Supports whitelisting via `"no-patch-imports": [true, "\.spec\.ts$"]`.
7
+ */
8
+ class Rule extends Lint . Rules . AbstractRule {
9
+ apply ( file ) {
10
+ return this . applyWithWalker ( new Walker ( file , this . getOptions ( ) ) ) ;
11
+ }
12
+ }
13
+
14
+ class Walker extends Lint . RuleWalker {
15
+ constructor ( file , options ) {
16
+ super ( ...arguments ) ;
17
+
18
+ // Whitelist with regular expressions to use when determining which files to lint.
19
+ const whitelist = options . ruleArguments ;
20
+
21
+ // Whether the file should be checked at all.
22
+ this . _enabled = ! whitelist . length || whitelist . some ( p => new RegExp ( p ) . test ( file . fileName ) ) ;
23
+ }
24
+
25
+ visitImportDeclaration ( node ) {
26
+ // Walk through the imports and check if they start with `rxjs/add`.
27
+ if ( this . _enabled && node . moduleSpecifier . getText ( ) . startsWith ( 'rxjs/add' , 1 ) ) {
28
+ this . addFailureAtNode ( node , ERROR_MESSAGE ) ;
29
+ }
30
+
31
+ super . visitImportDeclaration ( node ) ;
32
+ }
33
+ }
34
+
35
+ exports . Rule = Rule ;
Original file line number Diff line number Diff line change 29
29
"no-var-keyword" : true ,
30
30
"no-exposed-todo" : true ,
31
31
"no-debugger" : true ,
32
+ "no-rxjs-patch-imports" : [
33
+ true ,
34
+ " src/lib" ,
35
+ " src/cdk"
36
+ ],
32
37
"one-line" : [
33
38
true ,
34
39
" check-catch" ,
You can’t perform that action at this time.
0 commit comments