Skip to content

Commit d207b59

Browse files
fix(eslint-plugin): [member-ordering] account for repeated names (typescript-eslint#6864)
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
1 parent e5d668c commit d207b59

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
@@ -800,6 +800,10 @@ export default util.createRule<Options, MessageIds>({
800800
previousName: string,
801801
order: AlphabeticalOrder,
802802
): boolean {
803+
if (name === previousName) {
804+
return false;
805+
}
806+
803807
switch (order) {
804808
case 'alphabetically':
805809
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
@@ -2008,6 +2008,53 @@ interface Foo {
20082008
},
20092009
],
20102010
},
2011+
// https://github.com/typescript-eslint/typescript-eslint/issues/6812
2012+
{
2013+
code: `
2014+
class Foo {
2015+
#bar: string;
2016+
2017+
get bar(): string {
2018+
return this.#bar;
2019+
}
2020+
2021+
set bar(value: string) {
2022+
this.#bar = value;
2023+
}
2024+
}
2025+
`,
2026+
options: [
2027+
{
2028+
default: {
2029+
memberTypes: [['get', 'set']],
2030+
order: 'alphabetically',
2031+
},
2032+
},
2033+
],
2034+
},
2035+
{
2036+
code: `
2037+
class Foo {
2038+
#bar: string;
2039+
2040+
get bar(): string {
2041+
return this.#bar;
2042+
}
2043+
2044+
set bar(value: string) {
2045+
this.#bar = value;
2046+
}
2047+
}
2048+
`,
2049+
options: [
2050+
{
2051+
default: {
2052+
memberTypes: [['get', 'set']],
2053+
order: 'natural',
2054+
},
2055+
},
2056+
],
2057+
},
20112058
],
20122059
invalid: [
20132060
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy