Skip to content

Commit

Permalink
fix(eslint-plugin): [member-ordering] ignore method overloading (type…
Browse files Browse the repository at this point in the history
…script-eslint#10536)

* fix(eslint-plugin): [member-ordering] ignore method overloading

* refactor
  • Loading branch information
yeonjuan authored Dec 30, 2024
1 parent 7eba36e commit 9746832
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
7 changes: 7 additions & 0 deletions packages/eslint-plugin/src/rules/member-ordering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,13 @@ function getRank(
): number {
const type = getNodeType(node);

if (
node.type === AST_NODE_TYPES.MethodDefinition &&
node.value.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression
) {
return -1;
}

if (type == null) {
// shouldn't happen but just in case, put it on the end
return orderConfig.length - 1;
Expand Down
77 changes: 73 additions & 4 deletions packages/eslint-plugin/tests/rules/member-ordering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,52 @@ interface Foo {
},
],
},
{
code: `
class Foo {
public baz(): void;
@Decorator() public baz() {}
@Decorator() bar() {}
}
`,
options: [
{
default: ['public-decorated-method', 'public-instance-method'],
},
],
},
{
code: `
class Foo {
public bar(): void;
@Decorator() bar() {}
public baz(): void;
@Decorator() public baz() {}
}
`,
options: [
{
default: ['public-instance-method', 'public-decorated-method'],
},
],
},
{
code: `
class Foo {
@Decorator() bar() {}
public baz(): void;
@Decorator() public baz() {}
}
`,
options: [
{
default: ['public-instance-method', 'public-decorated-method'],
},
],
},
],
invalid: [
{
Expand Down Expand Up @@ -4439,7 +4485,7 @@ abstract class Foo {
class Foo {
C: number;
[A: string]: number;
public static D(): {};
public static D() {}
static [B: string]: number;
}
`,
Expand Down Expand Up @@ -4471,7 +4517,7 @@ class Foo {
abstract class Foo {
abstract B: string;
abstract A(): void;
public C(): {};
public C() {}
}
`,
errors: [
Expand Down Expand Up @@ -4623,7 +4669,7 @@ class Foo {
code: `
class Foo {
A: string;
private C(): void;
private C() {}
constructor() {}
@Dec() private B: string;
set D() {}
Expand Down Expand Up @@ -4975,7 +5021,7 @@ class Foo {
code: `
class Foo {
A: string;
private C(): void;
private C() {}
constructor() {}
private readonly B: string;
set D() {}
Expand Down Expand Up @@ -5267,6 +5313,29 @@ interface Foo {
},
],
},
{
code: `
class Foo {
static foo() {}
foo(): void;
foo() {}
}
`,
errors: [
{
column: 3,
data: {
name: 'foo',
rank: 'public static method',
},
line: 5,
messageId: 'incorrectGroupOrder',
},
],
options: [
{ default: ['public-instance-method', 'public-static-method'] },
],
},
],
};

Expand Down

0 comments on commit 9746832

Please sign in to comment.