Skip to content

noDuplicateClassMembers

Diagnostic Category: lint/suspicious/noDuplicateClassMembers

Since: v1.0.0

Sources:

Disallow duplicate class members.

If there are declarations of the same name among class members, the last declaration overwrites other declarations silently. It can cause unexpected behaviours.

class Foo {
bar() { }
bar() { }
}
code-block.js:3:3 lint/suspicious/noDuplicateClassMembers ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Duplicate class member name “bar”

1 │ class Foo {
2 │ bar() { }
> 3 │ bar() { }
^^^^^^^^^
4 │ }
5 │

class Foo {
bar() { }
get bar() { }
}
code-block.js:3:3 lint/suspicious/noDuplicateClassMembers ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Duplicate class member name “bar”

1 │ class Foo {
2 │ bar() { }
> 3 │ get bar() { }
^^^^^^^^^^^^^
4 │ }
5 │

class Foo {
bar;
bar() { }
}
code-block.js:3:3 lint/suspicious/noDuplicateClassMembers ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Duplicate class member name “bar”

1 │ class Foo {
2 │ bar;
> 3 │ bar() { }
^^^^^^^^^
4 │ }
5 │

class Foo {
static bar() { }
static bar() { }
}
code-block.js:3:3 lint/suspicious/noDuplicateClassMembers ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Duplicate class member name “bar”

1 │ class Foo {
2 │ static bar() { }
> 3 │ static bar() { }
^^^^^^^^^^^^^^^^
4 │ }
5 │

class Foo {
bar() { }
qux() { }
}
class Foo {
set bar(value) { }
get bar() { }
}
class Foo {
bar;
qux;
}
class Foo {
bar;
qux() { }
}
class Foo {
static bar() { }
bar() { }
}