Skip to content

Commit 9746832

Browse files
authored
fix(eslint-plugin): [member-ordering] ignore method overloading (#10536)
* fix(eslint-plugin): [member-ordering] ignore method overloading * refactor
1 parent 7eba36e commit 9746832

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,13 @@ function getRank(
548548
): number {
549549
const type = getNodeType(node);
550550

551+
if (
552+
node.type === AST_NODE_TYPES.MethodDefinition &&
553+
node.value.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression
554+
) {
555+
return -1;
556+
}
557+
551558
if (type == null) {
552559
// shouldn't happen but just in case, put it on the end
553560
return orderConfig.length - 1;

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

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,52 @@ interface Foo {
21482148
},
21492149
],
21502150
},
2151+
{
2152+
code: `
2153+
class Foo {
2154+
public baz(): void;
2155+
@Decorator() public baz() {}
2156+
2157+
@Decorator() bar() {}
2158+
}
2159+
`,
2160+
options: [
2161+
{
2162+
default: ['public-decorated-method', 'public-instance-method'],
2163+
},
2164+
],
2165+
},
2166+
{
2167+
code: `
2168+
class Foo {
2169+
public bar(): void;
2170+
@Decorator() bar() {}
2171+
2172+
public baz(): void;
2173+
@Decorator() public baz() {}
2174+
}
2175+
`,
2176+
options: [
2177+
{
2178+
default: ['public-instance-method', 'public-decorated-method'],
2179+
},
2180+
],
2181+
},
2182+
{
2183+
code: `
2184+
class Foo {
2185+
@Decorator() bar() {}
2186+
2187+
public baz(): void;
2188+
@Decorator() public baz() {}
2189+
}
2190+
`,
2191+
options: [
2192+
{
2193+
default: ['public-instance-method', 'public-decorated-method'],
2194+
},
2195+
],
2196+
},
21512197
],
21522198
invalid: [
21532199
{
@@ -4439,7 +4485,7 @@ abstract class Foo {
44394485
class Foo {
44404486
C: number;
44414487
[A: string]: number;
4442-
public static D(): {};
4488+
public static D() {}
44434489
static [B: string]: number;
44444490
}
44454491
`,
@@ -4471,7 +4517,7 @@ class Foo {
44714517
abstract class Foo {
44724518
abstract B: string;
44734519
abstract A(): void;
4474-
public C(): {};
4520+
public C() {}
44754521
}
44764522
`,
44774523
errors: [
@@ -4623,7 +4669,7 @@ class Foo {
46234669
code: `
46244670
class Foo {
46254671
A: string;
4626-
private C(): void;
4672+
private C() {}
46274673
constructor() {}
46284674
@Dec() private B: string;
46294675
set D() {}
@@ -4975,7 +5021,7 @@ class Foo {
49755021
code: `
49765022
class Foo {
49775023
A: string;
4978-
private C(): void;
5024+
private C() {}
49795025
constructor() {}
49805026
private readonly B: string;
49815027
set D() {}
@@ -5267,6 +5313,29 @@ interface Foo {
52675313
},
52685314
],
52695315
},
5316+
{
5317+
code: `
5318+
class Foo {
5319+
static foo() {}
5320+
foo(): void;
5321+
foo() {}
5322+
}
5323+
`,
5324+
errors: [
5325+
{
5326+
column: 3,
5327+
data: {
5328+
name: 'foo',
5329+
rank: 'public static method',
5330+
},
5331+
line: 5,
5332+
messageId: 'incorrectGroupOrder',
5333+
},
5334+
],
5335+
options: [
5336+
{ default: ['public-instance-method', 'public-static-method'] },
5337+
],
5338+
},
52705339
],
52715340
};
52725341

0 commit comments

Comments
 (0)