1
- import * as test from ' node:test' ;
2
- import { RuleTester } from ' @typescript-eslint/rule-tester' ;
1
+ import * as test from " node:test" ;
2
+ import { RuleTester } from " @typescript-eslint/rule-tester" ;
3
3
4
4
import perfPlugin from "../plugins/perf-plugin.js" ;
5
5
@@ -32,99 +32,130 @@ ruleTester.run(
32
32
} ,
33
33
] ,
34
34
}
35
- ) ;
35
+ ) ;
36
36
37
- ruleTester . run ( 'no-repeated-member-access' , perfPlugin . rules [ "no-repeated-member-access" ] , {
38
- valid : [
39
- // Basic valid case
40
- `
37
+ ruleTester . run (
38
+ "no-repeated-member-access" ,
39
+ perfPlugin . rules [ "no-repeated-member-access" ] ,
40
+ {
41
+ valid : [
42
+ // Basic valid case
43
+ `
41
44
const data = ctx.data[0];
42
45
const v1 = data.v1;
43
46
` ,
44
-
45
- // Different scopes
46
- `
47
+
48
+ // Different scopes
49
+ `
47
50
function test() {
48
51
const a = obj.foo.bar;
49
52
}
50
53
function test2() {
51
54
const b = obj.foo.bar;
52
55
}
53
56
` ,
54
-
55
- // Dynamic property access (should be ignored)
56
- `
57
+ // Dynamic property access (should be ignored)
58
+ `
57
59
const v1 = ctx[method()].value;
58
60
const v2 = ctx[method()].value;
59
- `
60
- ] ,
61
-
62
- invalid : [
63
- // Basic invalid case
64
- {
65
- code : `
61
+ ` ,
62
+ `
63
+ switch (reason) {
64
+ case Test.STARTUP: {
65
+ return "STARTUP"
66
+ }
67
+ case Test.DEBOUNCE: {
68
+ return "DEBOUNCE"
69
+ }
70
+ case Test.INSTANT: {
71
+ return "INSTANT"
72
+ }
73
+ case Test.SHUTDOWN: {
74
+ return "SHUTDOWN"
75
+ }
76
+ default: {
77
+ return "UNKNOWN"
78
+ }
79
+ }
80
+ ` ,
81
+ ] ,
82
+
83
+ invalid : [
84
+ // Basic invalid case
85
+ {
86
+ code : `
66
87
const v1 = ctx.data.v1;
67
88
const v2 = ctx.data.v2;
68
89
` ,
69
- errors : [ { messageId : "repeatedAccess" } ] ,
70
- // output: `
71
- // const temp1 = ctx.data;
72
- // const v1 = temp1.v1;
73
- // const v2 = temp1.v2;
74
- // `
75
- } ,
76
- {
77
- code : `
90
+ errors : [ { messageId : "repeatedAccess" } ] ,
91
+ // output: `
92
+ // const temp1 = ctx.data;
93
+ // const v1 = temp1.v1;
94
+ // const v2 = temp1.v2;
95
+ // `
96
+ } ,
97
+ {
98
+ code : `
78
99
class User {
79
100
constructor() {
80
101
this.profile = service.user.profile
81
102
this.log = service.user.logger
82
103
}
83
104
}
84
105
` ,
85
- errors : [ { messageId : "repeatedAccess" } ] ,
86
- // output: `
87
- // class User {
88
- // constructor() {
89
- // const temp1 = service.user;
90
- // this.profile = temp1.profile
91
- // this.log = temp1.logger
92
- // }
93
- // }
94
- // `
95
- } ,
96
- // Nested scope case
97
- {
98
- code : `
106
+ errors : [ { messageId : "repeatedAccess" } ] ,
107
+ // output: `
108
+ // class User {
109
+ // constructor() {
110
+ // const temp1 = service.user;
111
+ // this.profile = temp1.profile
112
+ // this.log = temp1.logger
113
+ // }
114
+ // }
115
+ // `
116
+ } ,
117
+ // Nested scope case
118
+ {
119
+ code : `
99
120
function demo() {
100
121
console.log(obj.a.b.c);
101
122
return obj.a.b.d;
102
123
}
103
124
` ,
104
- errors : [ { messageId : "repeatedAccess" } ] ,
105
- // output: `
106
- // function demo() {
107
- // const temp1 = obj.a.b;
108
- // console.log(temp1.c);
109
- // return temp1.d;
110
- // }
111
- // `
112
- } ,
125
+ errors : [ { messageId : "repeatedAccess" } ] ,
126
+ // output: `
127
+ // function demo() {
128
+ // const temp1 = obj.a.b;
129
+ // console.log(temp1.c);
130
+ // return temp1.d;
131
+ // }
132
+ // `
133
+ } ,
113
134
114
- // Array index case
115
- {
116
- code : `
135
+ // Array index case
136
+ {
137
+ code : `
117
138
const x = data[0].value;
118
139
data[0].count++;
119
140
send(data[0].id);
120
141
` ,
121
- errors : [ { messageId : "repeatedAccess" } ] ,
122
- // output: `
123
- // const temp1 = data[0];
124
- // const x = temp1.value;
125
- // temp1.count++;
126
- // send(temp1.id);
127
- // `
128
- }
129
- ]
130
- } )
142
+ errors : [ { messageId : "repeatedAccess" } ] ,
143
+ // output: `
144
+ // const temp1 = data[0];
145
+ // const x = temp1.value;
146
+ // temp1.count++;
147
+ // send(temp1.id);
148
+ // `
149
+ } ,
150
+ {
151
+ code : `
152
+ this.vehicleSys!.automobile = new TransportCore(new TransportBlueprint());
153
+ this.vehicleSys!.automobile!.underframe = new ChassisAssembly(new ChassisSchema());
154
+ this.vehicleSys!.automobile!.underframe!.propulsionCover = new EngineEnclosure(new EnclosureSpec());
155
+ this.vehicleSys!.automobile!.underframe!.logisticsBay = new CargoModule(new ModuleTemplate());
156
+ ` ,
157
+ errors : [ { messageId : "repeatedAccess" } ] ,
158
+ } ,
159
+ ] ,
160
+ }
161
+ ) ;
0 commit comments