Skip to content

Commit e21df95

Browse files
committed
add no-repeated-member-access case
1 parent e320f4d commit e21df95

File tree

1 file changed

+96
-65
lines changed

1 file changed

+96
-65
lines changed

tests/perf-plugin.test.ts

Lines changed: 96 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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";
33

44
import perfPlugin from "../plugins/perf-plugin.js";
55

@@ -32,99 +32,130 @@ ruleTester.run(
3232
},
3333
],
3434
}
35-
);
35+
);
3636

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+
`
4144
const data = ctx.data[0];
4245
const v1 = data.v1;
4346
`,
44-
45-
// Different scopes
46-
`
47+
48+
// Different scopes
49+
`
4750
function test() {
4851
const a = obj.foo.bar;
4952
}
5053
function test2() {
5154
const b = obj.foo.bar;
5255
}
5356
`,
54-
55-
// Dynamic property access (should be ignored)
56-
`
57+
// Dynamic property access (should be ignored)
58+
`
5759
const v1 = ctx[method()].value;
5860
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: `
6687
const v1 = ctx.data.v1;
6788
const v2 = ctx.data.v2;
6889
`,
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: `
7899
class User {
79100
constructor() {
80101
this.profile = service.user.profile
81102
this.log = service.user.logger
82103
}
83104
}
84105
`,
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: `
99120
function demo() {
100121
console.log(obj.a.b.c);
101122
return obj.a.b.d;
102123
}
103124
`,
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+
},
113134

114-
// Array index case
115-
{
116-
code: `
135+
// Array index case
136+
{
137+
code: `
117138
const x = data[0].value;
118139
data[0].count++;
119140
send(data[0].id);
120141
`,
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

Comments
 (0)