@@ -3,34 +3,112 @@ import { banOperatorsRule } from '../../src/rules/ban-operators';
3
3
import { fromFixture } from '../etc' ;
4
4
import { ruleTester } from '../rule-tester' ;
5
5
6
- ruleTester ( { types : false } ) . run ( 'ban-operators' , banOperatorsRule , {
6
+ ruleTester ( { types : true } ) . run ( 'ban-operators' , banOperatorsRule , {
7
7
valid : [
8
8
{
9
- code : `import { concat, merge as m, mergeMap as mm } from "rxjs/operators";` ,
9
+ code : stripIndent `
10
+ // root import
11
+ import { of, concat, merge as m, mergeMap as mm } from "rxjs";
12
+
13
+ of('a').pipe(concat(of('b')));
14
+ of(1).pipe(m(of(2)));
15
+ of('a').pipe(mm(x => of(x + '1')));
16
+ ` ,
17
+ options : [ { } ] ,
18
+ } ,
19
+ {
20
+ code : stripIndent `
21
+ // namespace import
22
+ import * as Rx from "rxjs";
23
+
24
+ Rx.of('a').pipe(Rx.concat(Rx.of('b')));
25
+ Rx.of(1).pipe(Rx.merge(Rx.of(2)));
26
+ Rx.of('a').pipe(Rx.mergeMap(x => Rx.of(x + '1')));
27
+ ` ,
28
+ options : [ { } ] ,
10
29
} ,
11
30
{
12
- code : `import { concat, merge as m, mergeMap as mm } from "rxjs";` ,
31
+ code : stripIndent `
32
+ // operators path import (deprecated)
33
+ import { of, concat, merge as m, mergeMap as mm } from "rxjs/operators";
34
+
35
+ of('a').pipe(concat(of('b')));
36
+ of(1).pipe(m(of(2)));
37
+ of('a').pipe(mm(x => of(x + '1')));
38
+ ` ,
39
+ options : [ { } ] ,
13
40
} ,
41
+ stripIndent `
42
+ // no options
43
+ import { of, concat } from "rxjs";
44
+
45
+ of('a').pipe(concat(of('b')));
46
+ ` ,
14
47
{
15
- // This won't effect errors, because only imports from "rxjs/operators"
16
- // are checked. To support banning operators from "rxjs", it'll need to
17
- // check types.
18
- code : `import { concat, merge as m, mergeMap as mm } from "rxjs";` ,
19
- options : [
20
- {
21
- concat : true ,
22
- merge : 'because I say so' ,
23
- mergeMap : false ,
24
- } ,
25
- ] ,
48
+ code : stripIndent `
49
+ // non-RxJS operator
50
+ import { of } from "rxjs";
51
+
52
+ function concat() {}
53
+
54
+ of('a').pipe(concat());
55
+ ` ,
56
+ options : [ { concat : true } ] ,
26
57
} ,
27
58
] ,
28
59
invalid : [
29
60
fromFixture (
30
61
stripIndent `
31
- import { concat, merge as m, mergeMap as mm } from "rxjs/operators";
32
- ~~~~~~ [forbidden { "name": "concat", "explanation": "" }]
33
- ~~~~~ [forbidden { "name": "merge", "explanation": ": because I say so" }]
62
+ // root import
63
+ import { of, concat, merge as m, mergeMap as mm } from "rxjs";
64
+
65
+ of('a').pipe(concat(of('b')));
66
+ ~~~~~~ [forbidden { "name": "concat", "explanation": "" }]
67
+ of(1).pipe(m(of(2)));
68
+ ~ [forbidden { "name": "merge", "explanation": ": because I say so" }]
69
+ of('a').pipe(mm(x => of(x + '1')));
70
+ ` ,
71
+ {
72
+ options : [
73
+ {
74
+ concat : true ,
75
+ merge : 'because I say so' ,
76
+ mergeMap : false ,
77
+ } ,
78
+ ] ,
79
+ } ,
80
+ ) ,
81
+ fromFixture (
82
+ stripIndent `
83
+ // namespace import
84
+ import * as Rx from "rxjs";
85
+
86
+ Rx.of('a').pipe(Rx.concat(Rx.of('b')));
87
+ ~~~~~~ [forbidden { "name": "concat", "explanation": "" }]
88
+ Rx.of(1).pipe(Rx.merge(Rx.of(2)));
89
+ ~~~~~ [forbidden { "name": "merge", "explanation": "" }]
90
+ Rx.of('a').pipe(Rx.mergeMap(x => Rx.of(x + '1')));
91
+ ` ,
92
+ {
93
+ options : [
94
+ {
95
+ concat : true ,
96
+ merge : true ,
97
+ mergeMap : false ,
98
+ } ,
99
+ ] ,
100
+ } ,
101
+ ) ,
102
+ fromFixture (
103
+ stripIndent `
104
+ // operators path import (deprecated)
105
+ import { of, concat, merge as m, mergeMap as mm } from "rxjs/operators";
106
+
107
+ of('a').pipe(concat(of('b')));
108
+ ~~~~~~ [forbidden { "name": "concat", "explanation": "" }]
109
+ of(1).pipe(m(of(2)));
110
+ ~ [forbidden { "name": "merge", "explanation": ": because I say so" }]
111
+ of('a').pipe(mm(x => of(x + '1')));
34
112
` ,
35
113
{
36
114
options : [
0 commit comments