Skip to content

Commit b783b1e

Browse files
fix(eslint-plugin) [member-ordering] account for repeated names
1 parent e94f24c commit b783b1e

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

packages/eslint-plugin/src/rules/member-ordering.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,10 @@ export default util.createRule<Options, MessageIds>({
811811
previousName: string,
812812
order: AlphabeticalOrder,
813813
): boolean {
814+
if (name === previousName) {
815+
return false;
816+
}
817+
814818
switch (order) {
815819
case 'alphabetically':
816820
return name < previousName;

packages/eslint-plugin/tests/rules/member-ordering.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,53 @@ interface Foo {
20072007
},
20082008
],
20092009
},
2010+
// https://github.com/typescript-eslint/typescript-eslint/issues/6812
2011+
{
2012+
code: `
2013+
class Foo {
2014+
#bar: string;
2015+
2016+
get bar(): string {
2017+
return this.#bar;
2018+
}
2019+
2020+
set bar(value: string) {
2021+
this.#bar = value;
2022+
}
2023+
}
2024+
`,
2025+
options: [
2026+
{
2027+
default: {
2028+
memberTypes: [['get', 'set']],
2029+
order: 'alphabetically',
2030+
},
2031+
},
2032+
],
2033+
},
2034+
{
2035+
code: `
2036+
class Foo {
2037+
#bar: string;
2038+
2039+
get bar(): string {
2040+
return this.#bar;
2041+
}
2042+
2043+
set bar(value: string) {
2044+
this.#bar = value;
2045+
}
2046+
}
2047+
`,
2048+
options: [
2049+
{
2050+
default: {
2051+
memberTypes: [['get', 'set']],
2052+
order: 'natural',
2053+
},
2054+
},
2055+
],
2056+
},
20102057
],
20112058
invalid: [
20122059
{

0 commit comments

Comments
 (0)