Skip to content

Commit

Permalink
fix(eslint-plugin): [member-ordering] account for repeated names (#6864)
Browse files Browse the repository at this point in the history
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
  • Loading branch information
JoshuaKGoldberg and bradzacher committed Jul 18, 2023
1 parent e5d668c commit d207b59
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/eslint-plugin/src/rules/member-ordering.ts
Expand Up @@ -800,6 +800,10 @@ export default util.createRule<Options, MessageIds>({
previousName: string,
order: AlphabeticalOrder,
): boolean {
if (name === previousName) {
return false;
}

switch (order) {
case 'alphabetically':
return name < previousName;
Expand Down
47 changes: 47 additions & 0 deletions packages/eslint-plugin/tests/rules/member-ordering.test.ts
Expand Up @@ -2008,6 +2008,53 @@ interface Foo {
},
],
},
// https://github.com/typescript-eslint/typescript-eslint/issues/6812
{
code: `
class Foo {
#bar: string;
get bar(): string {
return this.#bar;
}
set bar(value: string) {
this.#bar = value;
}
}
`,
options: [
{
default: {
memberTypes: [['get', 'set']],
order: 'alphabetically',
},
},
],
},
{
code: `
class Foo {
#bar: string;
get bar(): string {
return this.#bar;
}
set bar(value: string) {
this.#bar = value;
}
}
`,
options: [
{
default: {
memberTypes: [['get', 'set']],
order: 'natural',
},
},
],
},
],
invalid: [
{
Expand Down

0 comments on commit d207b59

Please sign in to comment.