From b5a52a3aae85fce3bc45b39a2107a00d2655f5f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Veyret?= Date: Tue, 3 Dec 2019 19:55:57 +0100 Subject: [PATCH] feat(eslint-plugin): [member-ordering] add index signature (#1190) Co-authored-by: Brad Zacher --- .../docs/rules/member-ordering.md | 70 ++++- .../src/rules/member-ordering.ts | 12 +- packages/eslint-plugin/src/util/misc.ts | 13 + .../tests/rules/member-ordering.test.ts | 292 +++++++++++++----- 4 files changed, 298 insertions(+), 89 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/member-ordering.md b/packages/eslint-plugin/docs/rules/member-ordering.md index 517673f09d6..d803e9def7e 100644 --- a/packages/eslint-plugin/docs/rules/member-ordering.md +++ b/packages/eslint-plugin/docs/rules/member-ordering.md @@ -17,8 +17,8 @@ It allows to group members by their type (e.g. `public-static-field`, `protected classes?: Array | never classExpressions?: Array | never - interfaces?: ['field' | 'method' | 'constructor'] | never - typeLiterals?: ['field' | 'method' | 'constructor'] | never + interfaces?: ['signature' | 'field' | 'method' | 'constructor'] | never + typeLiterals?: ['signature' | 'field' | 'method' | 'constructor'] | never } ``` @@ -30,6 +30,9 @@ There are multiple ways to specify the member types. The most explicit and granu ```json5 [ + // Index signature + 'signature', + // Fields 'public-static-field', 'protected-static-field', @@ -67,6 +70,9 @@ It is also possible to group member types by their accessibility (`static`, `ins ```json5 [ + // Index signature + // No accessibility for index signature. See above. + // Fields 'public-field', // = ['public-static-field', 'public-instance-field']) 'protected-field', // = ['protected-static-field', 'protected-instance-field']) @@ -88,6 +94,9 @@ Another option is to group the member types by their scope (`public`, `protected ```json5 [ + // Index signature + // No scope for index signature. See above. + // Fields 'static-field', // = ['public-static-field', 'protected-static-field', 'private-static-field']) 'instance-field', // = ['public-instance-field', 'protected-instance-field', 'private-instance-field']) @@ -109,6 +118,9 @@ The third grouping option is to ignore both scope and accessibility. ```json5 [ + // Index signature + // No grouping for index signature. See above. + // Fields 'field', // = ['public-static-field', 'protected-static-field', 'private-static-field', 'public-instance-field', 'protected-instance-field', 'private-instance-field', // 'public-abstract-field', 'protected-abstract-field', private-abstract-field']) @@ -129,6 +141,8 @@ The default configuration looks as follows: ```json { "default": [ + "signature", + "public-static-field", "protected-static-field", "private-static-field", @@ -186,7 +200,7 @@ Note: The default configuration contains member group types which contain other Note: The `default` options are overwritten in these examples. -#### Configuration: `{ "default": ["method", "constructor", "field"] }` +#### Configuration: `{ "default": ["signature", "method", "constructor", "field"] }` ##### Incorrect examples @@ -197,6 +211,8 @@ interface Foo { new (); // -> constructor A(): void; // -> method + + [Z: string]: any; // -> signature } ``` @@ -209,6 +225,8 @@ type Foo = { // no constructor A(): void; // -> method + + // no signature }; ``` @@ -224,10 +242,12 @@ class Foo { public static A(): void {} // -> method public B(): void {} // -> method + + [Z: string]: any; // -> signature } ``` -Note: Accessibility or scope are ignored with this ignored. +Note: Accessibility or scope are ignored with this configuration. ```ts const Foo = class { @@ -239,6 +259,8 @@ const Foo = class { public static A(): void {} // -> method public B(): void {} // -> method + [Z: string]: any; // -> signature + protected static E: string; // -> field }; ``` @@ -249,6 +271,8 @@ Note: Not all members have to be grouped to find rule violations. ```ts interface Foo { + [Z: string]: any; // -> signature + A(): void; // -> method new (); // -> constructor @@ -259,6 +283,8 @@ interface Foo { ```ts type Foo = { + // no signature + A(): void; // -> method // no constructor @@ -269,6 +295,8 @@ type Foo = { ```ts class Foo { + [Z: string]: any; // -> signature + public static A(): void {} // -> method public B(): void {} // -> method @@ -282,6 +310,8 @@ class Foo { ```ts const Foo = class { + [Z: string]: any; // -> signature + public static A(): void {} // -> method public B(): void {} // -> method @@ -311,6 +341,8 @@ class Foo { public static A(): void {} // (irrelevant) + [Z: string]: any; // (irrelevant) + public B(): void {} // -> public instance method } ``` @@ -321,6 +353,8 @@ Note: Public instance methods should come first before public static fields. Eve const Foo = class { private C: string; // (irrelevant) + [Z: string]: any; // (irrelevant) + public static E: string; // -> public static field public D: string; // (irrelevant) @@ -350,6 +384,8 @@ class Foo { constructor() {} // (irrelevant) public static A(): void {} // (irrelevant) + + [Z: string]: any; // (irrelevant) } ``` @@ -359,6 +395,8 @@ const Foo = class { private C: string; // (irrelevant) + [Z: string]: any; // (irrelevant) + public D: string; // (irrelevant) constructor() {} // (irrelevant) @@ -384,6 +422,8 @@ class Foo { private static D: string; // -> static field public static A: string; // -> public static field + + [Z: string]: any; // (irrelevant) } ``` @@ -402,6 +442,8 @@ const foo = class { protected static C: string; // -> static field private static D: string; // -> static field + [Z: string]: any; // (irrelevant) + public static A: string; // -> public static field }; ``` @@ -424,6 +466,8 @@ class Foo { ```ts const foo = class { + [Z: string]: any; // -> signature + public static A: string; // -> public static field constructor() {} // -> constructor @@ -596,11 +640,11 @@ const foo = class { Note: If this is not set, the `default` will automatically be applied to classes expressions as well. If a `interfaces` configuration is provided, only this configuration will be used for `interfaces` (i.e. nothing will be merged with `default`). -Note: The configuration for `interfaces` only allows a limited set of member types: `field`, `constructor` and `method`. +Note: The configuration for `interfaces` only allows a limited set of member types: `signature`, `field`, `constructor` and `method`. Note: The configuration for `interfaces` does not apply to type literals (use `typeLiterals` for them). -#### Configuration: `{ "interfaces": ["method", "constructor", "field"] }` +#### Configuration: `{ "interfaces": ["signature", "method", "constructor", "field"] }` ##### Incorrect example @@ -611,6 +655,8 @@ interface Foo { new (); // -> constructor A(): void; // -> method + + [Z: string]: any; // -> signature } ``` @@ -618,6 +664,8 @@ interface Foo { ```ts interface Foo { + [Z: string]: any; // -> signature + A(): void; // -> method new (); // -> constructor @@ -630,11 +678,11 @@ interface Foo { Note: If this is not set, the `default` will automatically be applied to classes expressions as well. If a `typeLiterals` configuration is provided, only this configuration will be used for `typeLiterals` (i.e. nothing will be merged with `default`). -Note: The configuration for `typeLiterals` only allows a limited set of member types: `field`, `constructor` and `method`. +Note: The configuration for `typeLiterals` only allows a limited set of member types: `signature`, `field`, `constructor` and `method`. -Note: The configuration for `typeLiterals` does not apply to type literals (use `interfaces` for them). +Note: The configuration for `typeLiterals` does not apply to interfaces (use `interfaces` for them). -#### Configuration: `{ "typeLiterals": ["method", "constructor", "field"] }` +#### Configuration: `{ "typeLiterals": ["signature", "method", "constructor", "field"] }` ##### Incorrect example @@ -645,6 +693,8 @@ type Foo = { A(): void; // -> method new (); // -> constructor + + [Z: string]: any; // -> signature }; ``` @@ -652,6 +702,8 @@ type Foo = { ```ts type Foo = { + [Z: string]: any; // -> signature + A(): void; // -> method new (); // -> constructor diff --git a/packages/eslint-plugin/src/rules/member-ordering.ts b/packages/eslint-plugin/src/rules/member-ordering.ts index c8911292836..56e3fae240c 100644 --- a/packages/eslint-plugin/src/rules/member-ordering.ts +++ b/packages/eslint-plugin/src/rules/member-ordering.ts @@ -39,6 +39,7 @@ const allMemberTypes = ['field', 'method', 'constructor'].reduce( }, [], ); +allMemberTypes.unshift('signature'); export default util.createRule({ name: 'member-ordering', @@ -104,7 +105,7 @@ export default util.createRule({ { type: 'array', items: { - enum: ['field', 'method', 'constructor'], + enum: ['signature', 'field', 'method', 'constructor'], }, }, ], @@ -117,7 +118,7 @@ export default util.createRule({ { type: 'array', items: { - enum: ['field', 'method', 'constructor'], + enum: ['signature', 'field', 'method', 'constructor'], }, }, ], @@ -130,6 +131,8 @@ export default util.createRule({ defaultOptions: [ { default: [ + 'signature', + 'public-static-field', 'protected-static-field', 'private-static-field', @@ -194,7 +197,6 @@ export default util.createRule({ node: TSESTree.ClassElement | TSESTree.TypeElement, ): string | null { // TODO: add missing TSCallSignatureDeclaration - // TODO: add missing TSIndexSignature switch (node.type) { case AST_NODE_TYPES.TSAbstractMethodDefinition: case AST_NODE_TYPES.MethodDefinition: @@ -210,6 +212,8 @@ export default util.createRule({ : 'field'; case AST_NODE_TYPES.TSPropertySignature: return 'field'; + case AST_NODE_TYPES.TSIndexSignature: + return 'signature'; default: return null; } @@ -235,6 +239,8 @@ export default util.createRule({ : util.getNameFromClassMember(node, sourceCode); case AST_NODE_TYPES.TSConstructSignatureDeclaration: return 'new'; + case AST_NODE_TYPES.TSIndexSignature: + return util.getNameFromIndexSignature(node); default: return null; } diff --git a/packages/eslint-plugin/src/util/misc.ts b/packages/eslint-plugin/src/util/misc.ts index f7c8c0194ba..bf65b97b898 100644 --- a/packages/eslint-plugin/src/util/misc.ts +++ b/packages/eslint-plugin/src/util/misc.ts @@ -48,6 +48,19 @@ type InferMessageIdsTypeFromRule = T extends TSESLint.RuleModule< ? TMessageIds : unknown; +/** + * Gets a string representation of the name of the index signature. + */ +export function getNameFromIndexSignature( + node: TSESTree.TSIndexSignature, +): string { + const propName: TSESTree.PropertyName | undefined = node.parameters.find( + (parameter: TSESTree.Parameter): parameter is TSESTree.Identifier => + parameter.type === AST_NODE_TYPES.Identifier, + ); + return propName ? getNameFromPropertyName(propName) : '(index signature)'; +} + /** * Gets a string name representation of the given PropertyName node */ diff --git a/packages/eslint-plugin/tests/rules/member-ordering.test.ts b/packages/eslint-plugin/tests/rules/member-ordering.test.ts index 936fe3a8900..5307793c3d7 100644 --- a/packages/eslint-plugin/tests/rules/member-ordering.test.ts +++ b/packages/eslint-plugin/tests/rules/member-ordering.test.ts @@ -10,6 +10,7 @@ ruleTester.run('member-ordering', rule, { ` // no accessibility === public interface Foo { + [Z: string]: any; A: string; B: string; C: string; @@ -38,6 +39,7 @@ interface Foo { new(); G(); H(); + [Z: string]: any; B: string; C: string; I(); @@ -50,6 +52,7 @@ interface Foo { code: ` // no accessibility === public interface Foo { + [Z: string]: any; A: string; B: string; C: string; @@ -65,7 +68,7 @@ interface Foo { L(); } `, - options: [{ default: ['field', 'constructor', 'method'] }], + options: [{ default: ['signature', 'field', 'constructor', 'method'] }], }, { @@ -76,6 +79,7 @@ interface Foo { J(); K(); D: string; + [Z: string]: any; E: string; F: string; new(); @@ -93,6 +97,7 @@ interface Foo { code: ` // no accessibility === public interface Foo { + [Z: string]: any; G(); H(); I(); @@ -108,7 +113,9 @@ interface Foo { F: string; } `, - options: [{ interfaces: ['method', 'constructor', 'field'] }], + options: [ + { interfaces: ['signature', 'method', 'constructor', 'field'] }, + ], }, { code: ` @@ -127,12 +134,13 @@ interface Foo { D: string; E: string; F: string; + [Z: string]: any; } `, options: [ { - default: ['field', 'constructor', 'method'], - interfaces: ['method', 'constructor', 'field'], + default: ['signature', 'field', 'constructor', 'method'], + interfaces: ['method', 'constructor', 'field', 'signature'], }, ], }, @@ -144,6 +152,7 @@ interface Foo { H(); I(); new(); + [Z: string]: any; D: string; E: string; F: string; @@ -176,6 +185,7 @@ interface Foo { J(); K(); L(); + [Z: string]: any; D: string; E: string; F: string; @@ -194,6 +204,7 @@ interface Foo { ` // no accessibility === public type Foo = { + [Z: string]: any; A: string; B: string; C: string; @@ -219,6 +230,7 @@ type Foo = { D: string; E: string; F: string; + [Z: string]: any; G(); H(); I(); @@ -233,6 +245,7 @@ type Foo = { code: ` // no accessibility === public type Foo = { + [Z: string]: any; A: string; B: string; C: string; @@ -247,12 +260,13 @@ type Foo = { L(); } `, - options: [{ default: ['field', 'constructor', 'method'] }], + options: [{ default: ['signature', 'field', 'constructor', 'method'] }], }, { code: ` // no accessibility === public type Foo = { + [Z: string]: any; new(); A: string; B: string; @@ -276,6 +290,7 @@ type Foo = { type Foo = { G(); H(); + [Z: string]: any; K(); L(); A: string; @@ -306,9 +321,10 @@ type Foo = { D: string; E: string; F: string; + [Z: string]: any; } `, - options: [{ typeLiterals: ['method', 'field'] }], + options: [{ typeLiterals: ['method', 'field', 'signature'] }], }, { code: ` @@ -326,9 +342,12 @@ type Foo = { D: string; E: string; F: string; + [Z: string]: any; } `, - options: [{ typeLiterals: ['method', 'constructor', 'field'] }], + options: [ + { typeLiterals: ['method', 'constructor', 'field', 'signature'] }, + ], }, { code: ` @@ -346,12 +365,13 @@ type Foo = { D: string; E: string; F: string; + [Z: string]: any; } `, options: [ { - default: ['field', 'constructor', 'method'], - typeLiterals: ['method', 'constructor', 'field'], + default: ['signature', 'field', 'constructor', 'method'], + typeLiterals: ['method', 'constructor', 'field', 'signature'], }, ], }, @@ -359,6 +379,7 @@ type Foo = { code: ` // no accessibility === public type Foo = { + [Z: string]: any; D: string; E: string; F: string; @@ -380,12 +401,13 @@ type Foo = { 'public-constructor', 'protected-static-field', ], - typeLiterals: ['field', 'method'], + typeLiterals: ['signature', 'field', 'method'], }, ], }, ` class Foo { + [Z: string]: any; public static A: string; protected static B: string = ""; private static C: string = ""; @@ -404,6 +426,7 @@ class Foo { { code: ` class Foo { + [Z: string]: any; public static A: string; protected static B: string = ""; private static C: string = ""; @@ -424,6 +447,7 @@ class Foo { { code: ` class Foo { + [Z: string]: any; public static A: string; protected static B: string = ""; private static C: string = ""; @@ -439,11 +463,12 @@ class Foo { private L() {} } `, - options: [{ default: ['field', 'constructor', 'method'] }], + options: [{ default: ['signature', 'field', 'constructor', 'method'] }], }, { code: ` class Foo { + [Z: string]: any; constructor() {} public static A: string; protected static B: string = ""; @@ -470,6 +495,7 @@ class Foo { private static I() {} public J() {} public D: string = ""; + [Z: string]: any; protected static H() {} public static A: string; protected static B: string = ""; @@ -490,6 +516,7 @@ class Foo { public J() {} protected K() {} private L() {} + [Z: string]: any; public static A: string; protected static B: string = ""; private static C: string = ""; @@ -517,9 +544,10 @@ class Foo { public D: string = ""; protected E: string = ""; private F: string = ""; + [Z: string]: any; } `, - options: [{ classes: ['method', 'constructor', 'field'] }], + options: [{ classes: ['method', 'constructor', 'field', 'signature'] }], }, { code: ` @@ -552,12 +580,13 @@ class Foo { public D: string = ""; protected E: string = ""; private F: string = ""; + [Z: string]: any; } `, options: [ { - default: ['field', 'constructor', 'method'], - classes: ['method', 'constructor', 'field'], + default: ['signature', 'field', 'constructor', 'method'], + classes: ['method', 'constructor', 'field', 'signature'], }, ], }, @@ -570,6 +599,7 @@ class Foo { private static I() {} protected K() {} private L() {} + [Z: string]: any; constructor() {} public D: string = ""; public static A: string; @@ -583,6 +613,7 @@ class Foo { { classes: [ 'public-method', + 'signature', 'constructor', 'public-field', 'private-field', @@ -600,6 +631,7 @@ class Foo { public J() {} private L() {} protected K() {} + [Z: string]: any; constructor() {} public D: string = ""; public static A: string; @@ -616,6 +648,7 @@ class Foo { 'static-method', 'public-instance-method', 'instance-method', + 'signature', 'constructor', 'public-field', 'protected-field', @@ -640,6 +673,7 @@ class Foo { private static C: string = ""; protected E: string = ""; private F: string = ""; + [Z: string]: any; } `, options: [ @@ -650,6 +684,7 @@ class Foo { 'constructor', 'method', 'field', + 'signature', ], }, ], @@ -664,6 +699,7 @@ class Foo { protected K() {} private L() {} constructor() {} + [Z: string]: any; public static A: string; private F: string = ""; protected static B: string = ""; @@ -681,6 +717,7 @@ class Foo { 'protected-instance-method', 'private-instance-method', 'constructor', + 'signature', 'field', ], }, @@ -702,7 +739,7 @@ class Foo { public static A: string; public D: string = ""; constructor() {} - + [Z: string]: any; } `, options: [ @@ -727,7 +764,7 @@ class Foo { public static A: string; public D: string = ""; constructor() {} - + [Z: string]: any; } `, options: [ @@ -752,7 +789,7 @@ class Foo { public static A: string; public D: string = ""; constructor() {} - + [Z: string]: any; } `, options: [ @@ -764,6 +801,7 @@ class Foo { { code: ` class Foo { + [Z: string]: any; public D: string = ""; private L() {} private static I() {} @@ -804,6 +842,7 @@ class Foo { protected static H() {} public static G() {} public J() {} + [Z: string]: any; protected static B: string = ""; protected K() {} private static C: string = ""; @@ -829,6 +868,7 @@ class Foo { }, ` const foo = class Foo { + [Z: string]: any; public static A: string; protected static B: string = ""; private static C: string = ""; @@ -853,6 +893,7 @@ const foo = class Foo { private static I() {} public J() {} private F: string = ""; + [Z: string]: any; public static G() {} private static C: string = ""; public D: string = ""; @@ -867,6 +908,7 @@ const foo = class Foo { { code: ` const foo = class Foo { + [Z: string]: any; public static A: string; protected static B: string = ""; private static C: string = ""; @@ -882,7 +924,7 @@ const foo = class Foo { private L() {} } `, - options: [{ default: ['field', 'constructor', 'method'] }], + options: [{ default: ['signature', 'field', 'constructor', 'method'] }], }, { code: ` @@ -894,6 +936,7 @@ const foo = class Foo { public D: string = ""; protected E: string = ""; private F: string = ""; + [Z: string]: any; public static G() {} protected static H() {} private static I() {} @@ -913,6 +956,7 @@ const foo = class Foo { private static I() {} public J() {} private static C: string = ""; + [Z: string]: any; public D: string = ""; protected K() {} public static G() {} @@ -940,6 +984,7 @@ const foo = class Foo { protected E: string = ""; private F: string = ""; constructor() {} + [Z: string]: any; } `, options: [{ classExpressions: ['method', 'field'] }], @@ -953,6 +998,7 @@ const foo = class Foo { public J() {} protected K() {} private L() {} + [Z: string]: any; constructor() {} public static A: string; protected static B: string = ""; @@ -962,7 +1008,9 @@ const foo = class Foo { private F: string = ""; } `, - options: [{ classExpressions: ['method', 'constructor', 'field'] }], + options: [ + { classExpressions: ['method', 'signature', 'constructor', 'field'] }, + ], }, { code: ` @@ -973,6 +1021,7 @@ const foo = class Foo { public J() {} protected K() {} private L() {} + [Z: string]: any; constructor() {} public static A: string; protected static B: string = ""; @@ -985,13 +1034,14 @@ const foo = class Foo { options: [ { default: ['field', 'constructor', 'method'], - classExpressions: ['method', 'constructor', 'field'], + classExpressions: ['method', 'signature', 'constructor', 'field'], }, ], }, { code: ` const foo = class Foo { + [Z: string]: any; private L() {} private static I() {} protected static H() {} @@ -1025,6 +1075,7 @@ const foo = class Foo { protected static H() {} public static G() {} public J() {} + [Z: string]: any; protected static B: string = ""; protected K() {} private static C: string = ""; @@ -1050,6 +1101,7 @@ const foo = class Foo { protected static H() {} public static G() {} public J() {} + [Z: string]: any; protected static B: string = ""; protected K() {} private static C: string = ""; @@ -1079,6 +1131,7 @@ const foo = class Foo { protected static H() {} public static G() {} public J() {} + [Z: string]: any; private constructor() {} protected static B: string = ""; protected K() {} @@ -1120,6 +1173,7 @@ const foo = class Foo { public J() {} protected static B: string = ""; protected K() {} + [Z: string]: any; private static C: string = ""; private F: string = ""; protected E: string = ""; @@ -1148,6 +1202,7 @@ const foo = class Foo { }, ` class Foo { + [Z: string]: any; A: string; constructor () {} J() {} @@ -1161,9 +1216,10 @@ class Foo { K = () => {} constructor () {} A: string; + [Z: string]: any; } `, - options: [{ default: ['method', 'constructor', 'field'] }], + options: [{ default: ['method', 'constructor', 'field', 'signature'] }], }, { code: ` @@ -1171,14 +1227,16 @@ class Foo { J() {} K = () => {} constructor () {} + [Z: string]: any; A: string; L: () => {} } `, - options: [{ default: ['method', 'constructor', 'field'] }], + options: [{ default: ['method', 'constructor', 'signature', 'field'] }], }, ` interface Foo { + [Z: string]: any; A: string; K: () => {}; J(); @@ -1187,15 +1245,17 @@ interface Foo { { code: ` interface Foo { + [Z: string]: any; J(); K: () => {} A: string; } `, - options: [{ default: ['method', 'constructor', 'field'] }], + options: [{ default: ['signature', 'method', 'constructor', 'field'] }], }, ` type Foo = { + [Z: string]: any; A: string; K: () => {} J(); @@ -1205,11 +1265,12 @@ type Foo = { code: ` type Foo = { J(); + [Z: string]: any; K: () => {} A: string; } `, - options: [{ default: ['method', 'constructor', 'field'] }], + options: [{ default: ['method', 'constructor', 'signature', 'field'] }], }, { code: ` @@ -1222,14 +1283,15 @@ abstract class Foo { { code: ` interface Foo { - public B: string; [A:string]: number; + public B: string; } `, }, { code: ` abstract class Foo { + [Z: string]: any; private static C: string; B: string; private D: string; @@ -1248,7 +1310,7 @@ abstract class Foo { abstract verify(): void; } `, - options: [{ classes: ['field', 'constructor', 'method'] }], + options: [{ classes: ['signature', 'field', 'constructor', 'method'] }], }, ], invalid: [ @@ -1256,6 +1318,7 @@ abstract class Foo { code: ` // no accessibility === public interface Foo { + [Z: string]: any; A: string; B: string; C: string; @@ -1278,7 +1341,7 @@ interface Foo { name: 'new', rank: 'method', }, - line: 16, + line: 17, column: 5, }, ], @@ -1300,9 +1363,10 @@ interface Foo { K(); L(); new(); + [Z: string]: any; } `, - options: [{ default: ['method', 'constructor', 'field'] }], + options: [{ default: ['signature', 'method', 'constructor', 'field'] }], errors: [ { messageId: 'incorrectOrder', @@ -1367,6 +1431,15 @@ interface Foo { line: 16, column: 5, }, + { + messageId: 'incorrectOrder', + data: { + name: 'Z', + rank: 'field', + }, + line: 17, + column: 5, + }, ], }, { @@ -1386,9 +1459,12 @@ interface Foo { K(); L(); new(); + [Z: string]: any; } `, - options: [{ interfaces: ['method', 'constructor', 'field'] }], + options: [ + { interfaces: ['method', 'signature', 'constructor', 'field'] }, + ], errors: [ { messageId: 'incorrectOrder', @@ -1453,6 +1529,15 @@ interface Foo { line: 16, column: 5, }, + { + messageId: 'incorrectOrder', + data: { + name: 'Z', + rank: 'field', + }, + line: 17, + column: 5, + }, ], }, { @@ -1472,12 +1557,13 @@ interface Foo { K(); L(); new(); + [Z: string]: any; } `, options: [ { - default: ['field', 'method', 'constructor'], - interfaces: ['method', 'constructor', 'field'], + default: ['field', 'method', 'constructor', 'signature'], + interfaces: ['method', 'signature', 'constructor', 'field'], }, ], errors: [ @@ -1544,12 +1630,22 @@ interface Foo { line: 16, column: 5, }, + { + messageId: 'incorrectOrder', + data: { + name: 'Z', + rank: 'field', + }, + line: 17, + column: 5, + }, ], }, { code: ` // no accessibility === public interface Foo { + [Z: string]: any; new(); A: string; G(); @@ -1567,7 +1663,7 @@ interface Foo { `, options: [ { - interfaces: ['constructor', 'field', 'method'], + interfaces: ['signature', 'constructor', 'field', 'method'], }, ], errors: [ @@ -1577,7 +1673,7 @@ interface Foo { name: 'B', rank: 'method', }, - line: 7, + line: 8, column: 5, }, { @@ -1586,7 +1682,7 @@ interface Foo { name: 'C', rank: 'method', }, - line: 9, + line: 10, column: 5, }, { @@ -1595,7 +1691,7 @@ interface Foo { name: 'D', rank: 'method', }, - line: 11, + line: 12, column: 5, }, { @@ -1604,7 +1700,7 @@ interface Foo { name: 'E', rank: 'method', }, - line: 13, + line: 14, column: 5, }, { @@ -1613,7 +1709,7 @@ interface Foo { name: 'F', rank: 'method', }, - line: 15, + line: 16, column: 5, }, ], @@ -1622,6 +1718,7 @@ interface Foo { code: ` // no accessibility === public type Foo = { + [Z: string]: any; A: string; B: string; C: string; @@ -1644,7 +1741,7 @@ type Foo = { name: 'new', rank: 'method', }, - line: 16, + line: 17, column: 5, }, ], @@ -1665,10 +1762,11 @@ type Foo = { J(); K(); L(); + [Z: string]: any; new(); } `, - options: [{ default: ['method', 'constructor', 'field'] }], + options: [{ default: ['method', 'constructor', 'signature', 'field'] }], errors: [ { messageId: 'incorrectOrder', @@ -1727,18 +1825,28 @@ type Foo = { { messageId: 'incorrectOrder', data: { - name: 'new', + name: 'Z', rank: 'field', }, line: 16, column: 5, }, + { + messageId: 'incorrectOrder', + data: { + name: 'new', + rank: 'field', + }, + line: 17, + column: 5, + }, ], }, { code: ` // no accessibility === public type Foo = { + [Z: string]: any; A: string; B: string; C: string; @@ -1754,69 +1862,71 @@ type Foo = { new(); } `, - options: [{ typeLiterals: ['method', 'constructor', 'field'] }], + options: [ + { typeLiterals: ['method', 'constructor', 'signature', 'field'] }, + ], errors: [ { messageId: 'incorrectOrder', data: { name: 'G', - rank: 'field', + rank: 'signature', }, - line: 10, + line: 11, column: 5, }, { messageId: 'incorrectOrder', data: { name: 'H', - rank: 'field', + rank: 'signature', }, - line: 11, + line: 12, column: 5, }, { messageId: 'incorrectOrder', data: { name: 'I', - rank: 'field', + rank: 'signature', }, - line: 12, + line: 13, column: 5, }, { messageId: 'incorrectOrder', data: { name: 'J', - rank: 'field', + rank: 'signature', }, - line: 13, + line: 14, column: 5, }, { messageId: 'incorrectOrder', data: { name: 'K', - rank: 'field', + rank: 'signature', }, - line: 14, + line: 15, column: 5, }, { messageId: 'incorrectOrder', data: { name: 'L', - rank: 'field', + rank: 'signature', }, - line: 15, + line: 16, column: 5, }, { messageId: 'incorrectOrder', data: { name: 'new', - rank: 'field', + rank: 'signature', }, - line: 16, + line: 17, column: 5, }, ], @@ -1838,12 +1948,13 @@ type Foo = { K(); L(); new(); + [Z: string]: any; } `, options: [ { - default: ['field', 'method', 'constructor'], - typeLiterals: ['method', 'constructor', 'field'], + default: ['field', 'method', 'constructor', 'signature'], + typeLiterals: ['signature', 'method', 'constructor', 'field'], }, ], errors: [ @@ -1910,6 +2021,15 @@ type Foo = { line: 16, column: 5, }, + { + messageId: 'incorrectOrder', + data: { + name: 'Z', + rank: 'field', + }, + line: 17, + column: 5, + }, ], }, { @@ -1917,6 +2037,7 @@ type Foo = { // no accessibility === public type Foo = { new(); + [Z: string]: any; A: string; G(); B: string; @@ -1933,7 +2054,7 @@ type Foo = { `, options: [ { - typeLiterals: ['constructor', 'field', 'method'], + typeLiterals: ['constructor', 'signature', 'field', 'method'], }, ], errors: [ @@ -1943,7 +2064,7 @@ type Foo = { name: 'B', rank: 'method', }, - line: 7, + line: 8, column: 5, }, { @@ -1952,7 +2073,7 @@ type Foo = { name: 'C', rank: 'method', }, - line: 9, + line: 10, column: 5, }, { @@ -1961,7 +2082,7 @@ type Foo = { name: 'D', rank: 'method', }, - line: 11, + line: 12, column: 5, }, { @@ -1970,7 +2091,7 @@ type Foo = { name: 'E', rank: 'method', }, - line: 13, + line: 14, column: 5, }, { @@ -1979,7 +2100,7 @@ type Foo = { name: 'F', rank: 'method', }, - line: 15, + line: 16, column: 5, }, ], @@ -1987,6 +2108,7 @@ type Foo = { { code: ` class Foo { + [Z: string]: any; public static A: string = ""; protected static B: string = ""; private static C: string = ""; @@ -2009,7 +2131,7 @@ class Foo { name: 'G', rank: 'public instance method', }, - line: 13, + line: 14, column: 5, }, { @@ -2018,7 +2140,7 @@ class Foo { name: 'H', rank: 'public instance method', }, - line: 14, + line: 15, column: 5, }, { @@ -2027,7 +2149,7 @@ class Foo { name: 'I', rank: 'public instance method', }, - line: 15, + line: 16, column: 5, }, ], @@ -2048,9 +2170,10 @@ class Foo { public static G() {} protected static H() {} private static I() {} + [Z: string]: any; } `, - options: [{ default: ['field', 'constructor', 'method'] }], + options: [{ default: ['field', 'constructor', 'method', 'signature'] }], errors: [ { messageId: 'incorrectOrder', @@ -2647,6 +2770,7 @@ const foo = class Foo { { code: ` const foo = class { + [Z: string]: any; constructor() {} public static A: string = ""; protected static B: string = ""; @@ -2662,7 +2786,7 @@ const foo = class { private static I() {} } `, - options: [{ default: ['field', 'constructor', 'method'] }], + options: [{ default: ['signature', 'field', 'constructor', 'method'] }], errors: [ { messageId: 'incorrectOrder', @@ -2670,7 +2794,7 @@ const foo = class { name: 'A', rank: 'constructor', }, - line: 4, + line: 5, column: 5, }, { @@ -2679,7 +2803,7 @@ const foo = class { name: 'B', rank: 'constructor', }, - line: 5, + line: 6, column: 5, }, { @@ -2688,7 +2812,7 @@ const foo = class { name: 'C', rank: 'constructor', }, - line: 6, + line: 7, column: 5, }, { @@ -2697,7 +2821,7 @@ const foo = class { name: 'D', rank: 'constructor', }, - line: 7, + line: 8, column: 5, }, { @@ -2706,7 +2830,7 @@ const foo = class { name: 'E', rank: 'constructor', }, - line: 8, + line: 9, column: 5, }, { @@ -2715,7 +2839,7 @@ const foo = class { name: 'F', rank: 'constructor', }, - line: 9, + line: 10, column: 5, }, ], @@ -2729,6 +2853,7 @@ const foo = class { public D: string = ""; protected E: string = ""; private F: string = ""; + [Z: string]: any; public static G() {} public static A: string; protected static H() {} @@ -2746,7 +2871,7 @@ const foo = class { name: 'A', rank: 'method', }, - line: 10, + line: 11, column: 5, }, ], @@ -2794,6 +2919,7 @@ const foo = class { private L() {} public static A: string; constructor() {} + [Z: string]: any; private static C: string = ""; public D: string = ""; protected E: string = ""; @@ -3219,6 +3345,7 @@ class Foo { K = () => {} A: string; constructor () {} + [Z: string]: any; J() {} } `, @@ -3241,6 +3368,15 @@ class Foo { line: 5, column: 5, }, + { + messageId: 'incorrectOrder', + data: { + name: 'Z', + rank: 'public instance method', + }, + line: 6, + column: 5, + }, ], }, { @@ -3250,9 +3386,10 @@ class Foo { constructor () {} K = () => {} A: string; + [Z: string]: any; } `, - options: [{ default: ['method', 'constructor', 'field'] }], + options: [{ default: ['method', 'constructor', 'field', 'signature'] }], errors: [ { messageId: 'incorrectOrder', @@ -3427,6 +3564,7 @@ class Foo { 'method', 'public-static-method', 'private-static-method', + 'signature', ], }, ], @@ -3435,7 +3573,7 @@ class Foo { messageId: 'incorrectOrder', data: { name: 'D', - rank: 'private static method', + rank: 'signature', }, line: 5, column: 5,