@@ -10,46 +10,6 @@ RuleTester.itOnly = test.it.only;
10
10
11
11
const ruleTester = new RuleTester ( ) ;
12
12
13
- // ruleTester.run(
14
- // "no-repeated-member-access",
15
- // perfPlugin.rules["no-repeated-member-access"],
16
- // {
17
- // valid: [
18
- // `
19
- // switch (reason) {
20
- // case Test.STARTUP: {
21
- // return "STARTUP"
22
- // }
23
- // case Test.DEBOUNCE: {
24
- // return "DEBOUNCE"
25
- // }
26
- // case Test.INSTANT: {
27
- // return "INSTANT"
28
- // }
29
- // case Test.SHUTDOWN: {
30
- // return "SHUTDOWN"
31
- // }
32
- // default: {
33
- // return "UNKNOWN"
34
- // }
35
- // }
36
- // `,
37
- // ],
38
-
39
- // invalid: [
40
- // {
41
- // code: `
42
- // this.vehicleSys!.automobile = new TransportCore(new TransportBlueprint());
43
- // this.vehicleSys!.automobile!.underframe = new ChassisAssembly(new ChassisSchema());
44
- // this.vehicleSys!.automobile!.underframe!.propulsionCover = new EngineEnclosure(new EnclosureSpec());
45
- // this.vehicleSys!.automobile!.underframe!.logisticsBay = new CargoModule(new ModuleTemplate());
46
- // `,
47
- // errors: [{ messageId: "repeatedAccess" }],
48
- // },
49
- // ],
50
- // }
51
- // );
52
-
53
13
// Throws error if the tests in ruleTester.run() do not pass
54
14
ruleTester . run (
55
15
"array-init-style" , // rule name
@@ -124,15 +84,15 @@ ruleTester.run(
124
84
// Basic invalid case
125
85
{
126
86
code : `
127
- const v1 = ctx.data.v1;
128
- const v2 = ctx.data.v2;
129
- ` ,
87
+ const v1 = ctx.data.v1;
88
+ const v2 = ctx.data.v2;
89
+ ` ,
130
90
errors : [ { messageId : "repeatedAccess" } ] ,
131
- // output: `
132
- // const temp1 = ctx.data;
133
- // const v1 = temp1 .v1;
134
- // const v2 = temp1 .v2;
135
- // `
91
+ output : `
92
+ const _ctx_data = ctx.data;
93
+ const v1 = _ctx_data .v1;
94
+ const v2 = _ctx_data .v2;
95
+ ` ,
136
96
} ,
137
97
{
138
98
code : `
@@ -141,18 +101,17 @@ ruleTester.run(
141
101
this.profile = service.user.profile
142
102
this.log = service.user.logger
143
103
}
144
- }
145
- ` ,
104
+ }` ,
146
105
errors : [ { messageId : "repeatedAccess" } ] ,
147
- // output: `
148
- // class User {
149
- // constructor() {
150
- // const temp1 = service.user;
151
- // this.profile = temp1.profile
152
- // this.log = temp1.logger
153
- // }
154
- // }
155
- // `
106
+ output :
107
+ "\n" +
108
+ " class User {\n" +
109
+ " constructor() {\n" +
110
+ " const _service_user = service.user;\n" +
111
+ " this.profile = _service_user.profile\n" +
112
+ " this.log = _service_user.logger\n" +
113
+ " }\n" +
114
+ " }" ,
156
115
} ,
157
116
// Nested scope case
158
117
{
@@ -163,13 +122,14 @@ ruleTester.run(
163
122
}
164
123
` ,
165
124
errors : [ { messageId : "repeatedAccess" } ] ,
166
- // output: `
167
- // function demo() {
168
- // const temp1 = obj.a.b;
169
- // console.log(temp1.c);
170
- // return temp1.d;
171
- // }
172
- // `
125
+ output :
126
+ "\n" +
127
+ " function demo() {\n" +
128
+ " const _obj_a_b = obj.a.b;\n" +
129
+ "console.log(_obj_a_b.c);\n" +
130
+ " return _obj_a_b.d;\n" +
131
+ " }\n" +
132
+ " " ,
173
133
} ,
174
134
175
135
// Array index case
@@ -179,13 +139,17 @@ ruleTester.run(
179
139
data[0].count++;
180
140
send(data[0].id);
181
141
` ,
182
- errors : [ { messageId : "repeatedAccess" } ] ,
183
- // output: `
184
- // const temp1 = data[0];
185
- // const x = temp1.value;
186
- // temp1.count++;
187
- // send(temp1.id);
188
- // `
142
+ errors : [
143
+ { messageId : "repeatedAccess" } ,
144
+ { messageId : "repeatedAccess" } ,
145
+ ] ,
146
+ output :
147
+ "\n" +
148
+ " const _data_0_ = data[0];\n" +
149
+ "const x = _data_0_.value;\n" +
150
+ " _data_0_.count++;\n" +
151
+ " send(_data_0_.id);\n" +
152
+ " " ,
189
153
} ,
190
154
{
191
155
code : `
@@ -198,6 +162,29 @@ ruleTester.run(
198
162
{ messageId : "repeatedAccess" } ,
199
163
{ messageId : "repeatedAccess" } ,
200
164
{ messageId : "repeatedAccess" } ,
165
+ { messageId : "repeatedAccess" } ,
166
+ { messageId : "repeatedAccess" } ,
167
+ { messageId : "repeatedAccess" } ,
168
+ ] ,
169
+ output : [
170
+ "\n" +
171
+ " const _this_vehicleSys = this.vehicleSys;\n" +
172
+ "this.vehicleSys!.automobile = new TransportCore(new TransportBlueprint());\n" +
173
+ " const _this_vehicleSys_automobile = this.vehicleSys.automobile;\n" +
174
+ "this.vehicleSys!.automobile!.underframe = new ChassisAssembly(new ChassisSchema());\n" +
175
+ " const _this_vehicleSys_automobile_underframe = this.vehicleSys.automobile.underframe;\n" +
176
+ "this.vehicleSys!.automobile!.underframe!.propulsionCover = new EngineEnclosure(new EnclosureSpec());\n" +
177
+ " this.vehicleSys!.automobile!.underframe!.logisticsBay = new CargoModule(new ModuleTemplate());\n" +
178
+ " " ,
179
+ "\n" +
180
+ " const _this_vehicleSys = this.vehicleSys;\n" +
181
+ "this.vehicleSys!.automobile = new TransportCore(new TransportBlueprint());\n" +
182
+ " const _this_vehicleSys_automobile = _this_vehicleSys.automobile;\n" +
183
+ "this.vehicleSys!.automobile!.underframe = new ChassisAssembly(new ChassisSchema());\n" +
184
+ " const _this_vehicleSys_automobile_underframe = _this_vehicleSys_automobile.underframe;\n" +
185
+ "this.vehicleSys!.automobile!.underframe!.propulsionCover = new EngineEnclosure(new EnclosureSpec());\n" +
186
+ " this.vehicleSys!.automobile!.underframe!.logisticsBay = new CargoModule(new ModuleTemplate());\n" +
187
+ " " ,
201
188
] ,
202
189
} ,
203
190
] ,
0 commit comments