diff --git a/packages/eslint-plugin/src/rules/member-ordering.ts b/packages/eslint-plugin/src/rules/member-ordering.ts index de5b971f5339..a6b1b74c20e8 100644 --- a/packages/eslint-plugin/src/rules/member-ordering.ts +++ b/packages/eslint-plugin/src/rules/member-ordering.ts @@ -55,6 +55,7 @@ const objectConfig = (memberTypes: string[]): JSONSchema.JSONSchema4 => ({ export const defaultOrder = [ // Index signature 'signature', + 'call-signature', // Fields 'public-static-field', @@ -122,9 +123,13 @@ export const defaultOrder = [ 'method', ]; -const allMemberTypes = ['signature', 'field', 'method', 'constructor'].reduce< - string[] ->((all, type) => { +const allMemberTypes = [ + 'signature', + 'field', + 'method', + 'call-signature', + 'constructor', +].reduce((all, type) => { all.push(type); ['public', 'protected', 'private'].forEach(accessibility => { @@ -170,13 +175,14 @@ const functionExpressions = [ * @param node the node to be evaluated. */ function getNodeType(node: Member): string | null { - // TODO: add missing TSCallSignatureDeclaration switch (node.type) { case AST_NODE_TYPES.TSAbstractMethodDefinition: case AST_NODE_TYPES.MethodDefinition: return node.kind; case AST_NODE_TYPES.TSMethodSignature: return 'method'; + case AST_NODE_TYPES.TSCallSignatureDeclaration: + return 'call-signature'; case AST_NODE_TYPES.TSConstructSignatureDeclaration: return 'constructor'; case AST_NODE_TYPES.TSAbstractClassProperty: @@ -216,6 +222,8 @@ function getMemberName( : util.getNameFromMember(node, sourceCode); case AST_NODE_TYPES.TSConstructSignatureDeclaration: return 'new'; + case AST_NODE_TYPES.TSCallSignatureDeclaration: + return 'call'; case AST_NODE_TYPES.TSIndexSignature: return util.getNameFromIndexSignature(node); default: diff --git a/packages/eslint-plugin/tests/rules/member-ordering.test.ts b/packages/eslint-plugin/tests/rules/member-ordering.test.ts index 5134d591ffa8..c17aa57b90e7 100644 --- a/packages/eslint-plugin/tests/rules/member-ordering.test.ts +++ b/packages/eslint-plugin/tests/rules/member-ordering.test.ts @@ -75,7 +75,16 @@ interface Foo { `, options: [{ default: ['signature', 'field', 'constructor', 'method'] }], }, - + { + code: ` +interface X { + (): void; + a: unknown; + b(): void; +} + `, + options: [{ default: ['call-signature', 'field', 'method'] }], + }, { code: ` // no accessibility === public @@ -1448,6 +1457,27 @@ interface Foo { }, { code: ` +interface X { + a: unknown; + (): void; + b(): void; +} + `, + options: [{ default: ['call-signature', 'field', 'method'] }], + errors: [ + { + messageId: 'incorrectGroupOrder', + data: { + name: 'call', + rank: 'field', + }, + line: 4, + column: 3, + }, + ], + }, + { + code: ` // no accessibility === public interface Foo { A: string; @@ -3811,8 +3841,8 @@ const sortedWithoutGroupingDefaultOption: TSESLint.RunTests< { code: ` interface Foo { - a(): Foo; (): Foo; + a(): Foo; b(): Foo; } `, @@ -3850,8 +3880,8 @@ type Foo = { a : b; [a: string] : number; b() : void; - new () : Bar; () : Baz; + new () : Bar; } `, options: [{ default: { memberTypes: 'never', order: 'alphabetically' } }], @@ -3990,6 +4020,13 @@ interface Foo { beforeMember: 'b', }, }, + { + messageId: 'incorrectOrder', + data: { + member: 'call', + beforeMember: 'new', + }, + }, ], }, @@ -4041,6 +4078,13 @@ type Foo = { beforeMember: 'b', }, }, + { + messageId: 'incorrectOrder', + data: { + member: 'call', + beforeMember: 'new', + }, + }, ], }, @@ -4190,10 +4234,10 @@ const sortedWithoutGroupingClassesOption: TSESLint.RunTests< code: ` interface Foo { [a: string] : number; + () : Baz; c : b; new () : Bar; b() : void; - () : Baz; } `, options: [{ classes: { memberTypes: 'never', order: 'alphabetically' } }], @@ -4226,10 +4270,10 @@ interface Foo { code: ` type Foo = { [a: string] : number; + () : Baz; c : b; new () : Bar; b() : void; - () : Baz; } `, options: [{ classes: { memberTypes: 'never', order: 'alphabetically' } }], @@ -4400,10 +4444,10 @@ const sortedWithoutGroupingClassExpressionsOption: TSESLint.RunTests< code: ` interface Foo { [a: string] : number; + () : Baz; c : b; new () : Bar; b() : void; - () : Baz; } `, options: [ @@ -4442,10 +4486,10 @@ interface Foo { code: ` type Foo = { [a: string] : number; + () : Baz; c : b; new () : Bar; b() : void; - () : Baz; } `, options: [ @@ -4639,8 +4683,8 @@ interface Foo { [a: string] : number; a : b; b() : void; - new () : Bar; () : Baz; + new () : Bar; } `, options: [ @@ -4679,10 +4723,10 @@ interface Foo { code: ` type Foo = { [a: string] : number; + () : Baz; c : b; new () : Bar; b() : void; - () : Baz; } `, options: [ @@ -4827,6 +4871,13 @@ interface Foo { beforeMember: 'b', }, }, + { + messageId: 'incorrectOrder', + data: { + member: 'call', + beforeMember: 'new', + }, + }, ], }, @@ -4872,10 +4923,10 @@ const sortedWithoutGroupingTypeLiteralsOption: TSESLint.RunTests< code: ` interface Foo { [a: string] : number; + () : Baz; c : b; new () : Bar; b() : void; - () : Baz; } `, options: [ @@ -4916,8 +4967,8 @@ type Foo = { [a: string] : number; a : b; b() : void; - new () : Bar; () : Baz; + new () : Bar; } `, options: [ @@ -5062,6 +5113,13 @@ type Foo = { beforeMember: 'b', }, }, + { + messageId: 'incorrectOrder', + data: { + member: 'call', + beforeMember: 'new', + }, + }, ], }, @@ -5108,6 +5166,8 @@ const sortedWithGroupingDefaultOption: TSESLint.RunTests< interface Foo { [a: string] : number; + () : Baz; + a : x; b : x; c : x; @@ -5117,8 +5177,6 @@ interface Foo { a() : void; b() : void; c() : void; - - () : Baz; } `, options: [ @@ -5160,6 +5218,8 @@ interface Foo { type Foo = { [a: string] : number; + () : Baz; + a : x; b : x; c : x; @@ -5169,8 +5229,6 @@ type Foo = { a() : void; b() : void; c() : void; - - () : Baz; } `, options: [ @@ -5344,6 +5402,13 @@ interface Foo { { default: { memberTypes: defaultOrder, order: 'alphabetically' } }, ], errors: [ + { + messageId: 'incorrectGroupOrder', + data: { + name: 'call', + rank: 'field', + }, + }, { messageId: 'incorrectGroupOrder', data: { @@ -5377,6 +5442,13 @@ type Foo = { { default: { memberTypes: defaultOrder, order: 'alphabetically' } }, ], errors: [ + { + messageId: 'incorrectGroupOrder', + data: { + name: 'call', + rank: 'field', + }, + }, { messageId: 'incorrectGroupOrder', data: { @@ -5503,6 +5575,8 @@ const sortedWithGroupingClassesOption: TSESLint.RunTests< interface Foo { [a: string] : number; + () : Baz; + c : x; b : x; a : x; @@ -5512,8 +5586,6 @@ interface Foo { c() : void; b() : void; a() : void; - - () : Baz; } `, options: [{ classes: { order: 'alphabetically' } }], @@ -5525,6 +5597,8 @@ interface Foo { type Foo = { [a: string] : number; + () : Baz; + c : x; b : x; a : x; @@ -5534,8 +5608,6 @@ type Foo = { c() : void; b() : void; a() : void; - - () : Baz; } `, options: [{ classes: { order: 'alphabetically' } }], @@ -5645,6 +5717,8 @@ const sortedWithGroupingClassExpressionsOption: TSESLint.RunTests< interface Foo { [a: string] : number; + () : Baz; + c : x; b : x; a : x; @@ -5654,8 +5728,6 @@ interface Foo { c() : void; b() : void; a() : void; - - () : Baz; } `, options: [{ classExpressions: { order: 'alphabetically' } }], @@ -5667,6 +5739,8 @@ interface Foo { type Foo = { [a: string] : number; + () : Baz; + c : x; b : x; a : x; @@ -5676,8 +5750,6 @@ type Foo = { c() : void; b() : void; a() : void; - - () : Baz; } `, options: [{ classExpressions: { order: 'alphabetically' } }], @@ -5849,6 +5921,8 @@ interface Foo { type Foo = { [a: string] : number; + () : Baz; + c : x; b : x; a : x; @@ -5858,8 +5932,6 @@ type Foo = { c() : void; b() : void; a() : void; - - () : Baz; } `, options: [{ interfaces: { order: 'alphabetically' } }], @@ -5925,6 +5997,13 @@ interface Foo { { default: { memberTypes: defaultOrder, order: 'alphabetically' } }, ], errors: [ + { + messageId: 'incorrectGroupOrder', + data: { + name: 'call', + rank: 'field', + }, + }, { messageId: 'incorrectGroupOrder', data: { @@ -5948,6 +6027,8 @@ const sortedWithGroupingTypeLiteralsOption: TSESLint.RunTests< interface Foo { [a: string] : number; + () : Baz; + c : x; b : x; a : x; @@ -5957,8 +6038,6 @@ interface Foo { c() : void; b() : void; a() : void; - - () : Baz; } `, options: [{ typeLiterals: { order: 'alphabetically' } }], @@ -6081,6 +6160,13 @@ type Foo = { { default: { memberTypes: defaultOrder, order: 'alphabetically' } }, ], errors: [ + { + messageId: 'incorrectGroupOrder', + data: { + name: 'call', + rank: 'field', + }, + }, { messageId: 'incorrectGroupOrder', data: { 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