Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}
Copy link
Contributor Author

@yeonjuan yeonjuan Dec 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a typo. The following TS error occurs because {} is a return type
Function implementation is missing or not immediately following the declaration.

}
`,
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
Loading