Skip to content

Commit 0cbd4cd

Browse files
fix(eslint-plugin): [class-literal-property-style] don't report nodes with override keyword (#10135)
[class-literal-property-style] don't report nodes with `override` keyword
1 parent 127066a commit 0cbd4cd

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/eslint-plugin/src/rules/class-literal-property-style.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export default createRule<Options, MessageIds>({
146146
MethodDefinition(node): void {
147147
if (
148148
node.kind !== 'get' ||
149+
node.override ||
149150
!node.value.body ||
150151
node.value.body.body.length === 0
151152
) {
@@ -223,7 +224,7 @@ export default createRule<Options, MessageIds>({
223224
}
224225
},
225226
PropertyDefinition(node): void {
226-
if (!node.readonly || node.declare) {
227+
if (!node.readonly || node.declare || node.override) {
227228
return;
228229
}
229230
const { properties } =

packages/eslint-plugin/tests/rules/class-literal-property-style.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,35 @@ class Mx {
257257
`,
258258
options: ['getters'],
259259
},
260+
{
261+
// https://github.com/typescript-eslint/typescript-eslint/issues/3602
262+
// getter with override modifier should be ignored
263+
code: `
264+
declare abstract class BaseClass {
265+
get cursor(): string;
266+
}
267+
268+
class ChildClass extends BaseClass {
269+
override get cursor() {
270+
return 'overridden value';
271+
}
272+
}
273+
`,
274+
},
275+
{
276+
// https://github.com/typescript-eslint/typescript-eslint/issues/3602
277+
// property with override modifier should be ignored
278+
code: `
279+
declare abstract class BaseClass {
280+
protected readonly foo: string;
281+
}
282+
283+
class ChildClass extends BaseClass {
284+
protected override readonly foo = 'bar';
285+
}
286+
`,
287+
options: ['getters'],
288+
},
260289
],
261290
invalid: [
262291
{

0 commit comments

Comments
 (0)