@typescript-eslint/eslint-plugin
Advanced tools
Comparing version 1.4.3-alpha.4 to 1.4.3-alpha.5
@@ -12,16 +12,17 @@ "use strict"; | ||
const util = __importStar(require("../util")); | ||
const schemaOptions = ['field', 'method', 'constructor'].reduce((options, type) => { | ||
options.push(type); | ||
const allMemberTypes = ['field', 'method', 'constructor'].reduce((all, type) => { | ||
all.push(type); | ||
['public', 'protected', 'private'].forEach(accessibility => { | ||
options.push(`${accessibility}-${type}`); | ||
all.push(`${accessibility}-${type}`); // e.g. `public-field` | ||
if (type !== 'constructor') { | ||
// There is no `static-constructor` or `instance-constructor | ||
['static', 'instance'].forEach(scope => { | ||
if (options.indexOf(`${scope}-${type}`) === -1) { | ||
options.push(`${scope}-${type}`); | ||
if (all.indexOf(`${scope}-${type}`) === -1) { | ||
all.push(`${scope}-${type}`); | ||
} | ||
options.push(`${accessibility}-${scope}-${type}`); | ||
all.push(`${accessibility}-${scope}-${type}`); | ||
}); | ||
} | ||
}); | ||
return options; | ||
return all; | ||
}, []); | ||
@@ -53,3 +54,3 @@ exports.default = util.createRule({ | ||
items: { | ||
enum: schemaOptions, | ||
enum: allMemberTypes, | ||
}, | ||
@@ -67,3 +68,3 @@ }, | ||
items: { | ||
enum: schemaOptions, | ||
enum: allMemberTypes, | ||
}, | ||
@@ -81,3 +82,3 @@ }, | ||
items: { | ||
enum: schemaOptions, | ||
enum: allMemberTypes, | ||
}, | ||
@@ -208,8 +209,10 @@ }, | ||
* - If there is no order for type, then return -1 | ||
* @param names the valid names to be validated. | ||
* @param memberTypes the valid names to be validated. | ||
* @param order the current order to be validated. | ||
* | ||
* @return Index of the matching member type in the order configuration. | ||
*/ | ||
function getRankOrder(names, order) { | ||
function getRankOrder(memberTypes, order) { | ||
let rank = -1; | ||
const stack = names.slice(); | ||
const stack = memberTypes.slice(); // Get a copy of the member types | ||
while (stack.length > 0 && rank === -1) { | ||
@@ -224,3 +227,3 @@ rank = order.indexOf(stack.shift()); | ||
* @param order the current order to be validated. | ||
* @param supportsModifiers a flag indicating whether the type supports modifiers or not. | ||
* @param supportsModifiers a flag indicating whether the type supports modifiers (scope or accessibility) or not. | ||
*/ | ||
@@ -237,12 +240,13 @@ function getRank(node, order, supportsModifiers) { | ||
: 'public'; | ||
const names = []; | ||
const memberTypes = []; | ||
if (supportsModifiers) { | ||
if (type !== 'constructor') { | ||
names.push(`${accessibility}-${scope}-${type}`); | ||
names.push(`${scope}-${type}`); | ||
// Constructors have no scope | ||
memberTypes.push(`${accessibility}-${scope}-${type}`); | ||
memberTypes.push(`${scope}-${type}`); | ||
} | ||
names.push(`${accessibility}-${type}`); | ||
memberTypes.push(`${accessibility}-${type}`); | ||
} | ||
names.push(type); | ||
return getRankOrder(names, order); | ||
memberTypes.push(type); | ||
return getRankOrder(memberTypes, order); | ||
} | ||
@@ -278,10 +282,12 @@ /** | ||
/** | ||
* Validates each member rank. | ||
* @param members the members to be validated. | ||
* @param order the current order to be validated. | ||
* @param supportsModifiers a flag indicating whether the type supports modifiers or not. | ||
* Validates if all members are correctly sorted. | ||
* | ||
* @param members Members to be validated. | ||
* @param order Current order to be validated. | ||
* @param supportsModifiers A flag indicating whether the type supports modifiers (scope or accessibility) or not. | ||
*/ | ||
function validateMembers(members, order, supportsModifiers) { | ||
function validateMembersOrder(members, order, supportsModifiers) { | ||
if (members && order !== 'never') { | ||
const previousRanks = []; | ||
// Find first member which isn't correctly sorted | ||
members.forEach(member => { | ||
@@ -309,12 +315,12 @@ const rank = getRank(member, order, supportsModifiers); | ||
ClassDeclaration(node) { | ||
validateMembers(node.body.body, options.classes || options.default, true); | ||
validateMembersOrder(node.body.body, options.classes || options.default, true); | ||
}, | ||
ClassExpression(node) { | ||
validateMembers(node.body.body, options.classExpressions || options.default, true); | ||
validateMembersOrder(node.body.body, options.classExpressions || options.default, true); | ||
}, | ||
TSInterfaceDeclaration(node) { | ||
validateMembers(node.body.body, options.interfaces || options.default, false); | ||
validateMembersOrder(node.body.body, options.interfaces || options.default, false); | ||
}, | ||
TSTypeLiteral(node) { | ||
validateMembers(node.members, options.typeLiterals || options.default, false); | ||
validateMembersOrder(node.members, options.typeLiterals || options.default, false); | ||
}, | ||
@@ -321,0 +327,0 @@ }; |
@@ -8,587 +8,634 @@ # Require a consistent member declaration order (member-ordering) | ||
This rule aims to standardise the way interfaces, type literals, classes and class expressions are structured. | ||
This rule aims to standardize the way class declarations, class expressions, interfaces and type literals are structured. | ||
It allows to group members by their type (e.g. `public-static-field`, `protected-static-field`, `private-static-field`, `public-instance-field`, ...). By default, their order is the same inside `classes`, `classExpressions`, `interfaces` and `typeLiterals` (note: not all member types apply to `interfaces` and `typeLiterals`). It is possible to define the order for any of those individually or to change the default order for all of them by setting the `default` option. | ||
## Options | ||
This rule, in its default state, does not require any argument, in which case the following order is enforced: | ||
```ts | ||
{ | ||
default?: Array<MemberType> | never | ||
classes?: Array<MemberType> | never | ||
classExpressions?: Array<MemberType> | never | ||
- `public-static-field` | ||
- `protected-static-field` | ||
- `private-static-field` | ||
- `public-instance-field` | ||
- `protected-instance-field` | ||
- `private-instance-field` | ||
- `public-field` (ignores scope) | ||
- `protected-field` (ignores scope) | ||
- `private-field` (ignores scope) | ||
- `static-field` (ignores accessibility) | ||
- `instance-field` (ignores accessibility) | ||
- `field` (ignores scope and/or accessibility) | ||
- `constructor` (ignores scope and/or accessibility) | ||
- `public-static-method` | ||
- `protected-static-method` | ||
- `private-static-method` | ||
- `public-instance-method` | ||
- `protected-instance-method` | ||
- `private-instance-method` | ||
- `public-method` (ignores scope) | ||
- `protected-method` (ignores scope) | ||
- `private-method` (ignores scope) | ||
- `static-method` (ignores accessibility) | ||
- `instance-method` (ignores accessibility) | ||
- `method` (ignores scope and/or accessibility) | ||
interfaces?: ['field' | 'method' | 'constructor'] | never | ||
typeLiterals?: ['field' | 'method' | 'constructor'] | never | ||
} | ||
``` | ||
The rule can also take one or more of the following options: | ||
See below for the possible definitions of `MemberType`. | ||
- `default`, use this to change the default order (used when no specific configuration has been provided). | ||
- `classes`, use this to change the order in classes. | ||
- `classExpressions`, use this to change the order in class expressions. | ||
- `interfaces`, use this to change the order in interfaces. | ||
- `typeLiterals`, use this to change the order in type literals. | ||
### Member types (granular form) | ||
### default | ||
There are multiple ways to specify the member types. The most explicit and granular form is the following: | ||
Disable using `never` or use one of the following values to specify an order: | ||
```json5 | ||
[ | ||
// Fields | ||
'public-static-field', | ||
'protected-static-field', | ||
'private-static-field', | ||
'public-instance-field', | ||
'protected-instance-field', | ||
'private-instance-field', | ||
- Fields: | ||
`public-static-field` | ||
`protected-static-field` | ||
`private-static-field` | ||
`public-instance-field` | ||
`protected-instance-field` | ||
`private-instance-field` | ||
`public-field` (= public-_-field) | ||
`protected-field` (= protected-_-field) | ||
`private-field` (= private-_-field) | ||
`static-field` (= _-static-field) | ||
`instance-field` (= \*-instance-field) | ||
`field` (= all) | ||
// Constructors | ||
'public-constructor', | ||
'protected-constructor', | ||
'private-constructor', | ||
- Constructors: | ||
`public-constructor` | ||
`protected-constructor` | ||
`private-constructor` | ||
`constructor` (= \*-constructor) | ||
// Methods | ||
'public-static-method', | ||
'protected-static-method', | ||
'private-static-method', | ||
'public-instance-method', | ||
'protected-instance-method', | ||
'private-instance-method', | ||
] | ||
``` | ||
- Methods: | ||
`public-static-method` | ||
`protected-static-method` | ||
`private-static-method` | ||
`public-instance-method` | ||
`protected-instance-method` | ||
`private-instance-method` | ||
`public-method` (= public-_-method) | ||
`protected-method` (= protected-_-method) | ||
`private-method` (= private-_-method) | ||
`static-method` (= _-static-method) | ||
`instance-method` (= \*-instance-method) | ||
`method` (= all) | ||
Note: If you only specify some of the possible types, the non-specified ones can have any particular order. This means that they can be placed before, within or after the specified types and the linter won't complain about it. | ||
Examples of **incorrect** code for the `{ "default": [...] }` option: | ||
### Member group types (with accessibility, ignoring scope) | ||
It is also possible to group member types by their accessibility (`static`, `instance`), ignoring their scope. | ||
```json5 | ||
[ | ||
// Fields | ||
'public-field', // = ['public-static-field', 'public-instance-field']) | ||
'protected-field', // = ['protected-static-field', 'protected-instance-field']) | ||
'private-field', // = ['private-static-field', 'private-instance-field']) | ||
// Constructors | ||
// Only the accessibility of constructors is configurable. See below. | ||
// Methods | ||
'public-method', // = ['public-static-method', 'public-instance-method']) | ||
'protected-method', // = ['protected-static-method', 'protected-instance-method']) | ||
'private-method', // = ['private-static-method', 'private-instance-method']) | ||
] | ||
``` | ||
### Member group types (with scope, ignoring accessibility) | ||
Another option is to group the member types by their scope (`public`, `protected`, `private`), ignoring their accessibility. | ||
```json5 | ||
[ | ||
// Fields | ||
'static-field', // = ['public-static-field', 'protected-static-field', 'private-static-field']) | ||
'instance-field', // = ['public-instance-field', 'protected-instance-field', 'private-instance-field']) | ||
// Constructors | ||
'constructor', // = ['public-constructor', 'protected-constructor', 'private-constructor']) | ||
// Methods | ||
'static-method', // = ['public-static-method', 'protected-static-method', 'private-static-method']) | ||
'instance-method', // = ['public-instance-method', 'protected-instance-method', 'private-instance-method'] | ||
] | ||
``` | ||
### Member group types (with scope and accessibility) | ||
The third grouping option is to ignore both scope and accessibility. | ||
```json5 | ||
[ | ||
// Fields | ||
'field', // = ['public-static-field', 'protected-static-field', 'private-static-field', 'public-instance-field', 'protected-instance-field', 'private-instance-field']) | ||
// Constructors | ||
// Only the accessibility of constructors is configurable. See above. | ||
// Methods | ||
'method', // = ['public-static-method', 'protected-static-method', 'private-static-method', 'public-instance-method', 'protected-instance-method', 'private-instance-method']) | ||
] | ||
``` | ||
### Default configuration | ||
The default configuration looks as follows: | ||
```json | ||
{ | ||
"default": [ | ||
"public-static-field", | ||
"protected-static-field", | ||
"private-static-field", | ||
"public-instance-field", | ||
"protected-instance-field", | ||
"private-instance-field", | ||
"public-field", | ||
"protected-field", | ||
"private-field", | ||
"static-field", | ||
"instance-field", | ||
"field", | ||
"constructor", | ||
"public-static-method", | ||
"protected-static-method", | ||
"private-static-method", | ||
"public-instance-method", | ||
"protected-instance-method", | ||
"private-instance-method", | ||
"public-method", | ||
"protected-method", | ||
"private-method", | ||
"static-method", | ||
"instance-method", | ||
"method" | ||
] | ||
} | ||
``` | ||
Note: The default configuration contains member group types which contain other member types (see above). This is intentional to provide better error messages. | ||
## Examples | ||
### Custom `default` configuration | ||
Note: The `default` options are overwritten in these examples. | ||
#### Configuration: `{ "default": ["method", "constructor", "field"] }` | ||
##### Incorrect examples | ||
```ts | ||
// { "default": ["method", "constructor", "field"] } | ||
interface Foo { | ||
// -> field | ||
B: string; | ||
B: string; // -> field | ||
// -> constructor | ||
new (); | ||
new (); // -> constructor | ||
// -> method | ||
A(): void; | ||
A(): void; // -> method | ||
} | ||
``` | ||
Note: Wrong order. | ||
```ts | ||
type Foo = { | ||
// -> field | ||
B: string; | ||
B: string; // -> field | ||
// no constructor | ||
// -> method | ||
A(): void; | ||
A(): void; // -> method | ||
}; | ||
``` | ||
Note: Not all specified member types have to exist. | ||
```ts | ||
class Foo { | ||
// -> * field | ||
private C: string; | ||
public D: string; | ||
protected static E: string; | ||
private C: string; // -> field | ||
public D: string; // -> field | ||
protected static E: string; // -> field | ||
// -> constructor | ||
constructor() {} | ||
constructor() {} // -> constructor | ||
// -> * method | ||
public static A(): void {} | ||
public B(): void {} | ||
public static A(): void {} // -> method | ||
public B(): void {} // -> method | ||
} | ||
``` | ||
Note: Accessibility or scope are ignored with this ignored. | ||
```ts | ||
const Foo = class { | ||
// -> * field | ||
private C: string; | ||
public D: string; | ||
private C: string; // -> field | ||
public D: string; // -> field | ||
// -> constructor | ||
constructor() {} | ||
constructor() {} // -> constructor | ||
// -> * method | ||
public static A(): void {} | ||
public B(): void {} | ||
public static A(): void {} // -> method | ||
public B(): void {} // -> method | ||
// * field | ||
protected static E: string; | ||
protected static E: string; // -> field | ||
}; | ||
``` | ||
// { "default": ["public-instance-method", "public-static-field"] } | ||
Note: Not all members have to be grouped to find rule violations. | ||
// does not apply for interfaces/type literals (accessibility and scope are not part of interfaces/type literals) | ||
##### Correct examples | ||
class Foo { | ||
// private instance field | ||
private C: string; | ||
```ts | ||
interface Foo { | ||
A(): void; // -> method | ||
// public instance field | ||
public D: string; | ||
new (); // -> constructor | ||
// -> public static field | ||
public static E: string; | ||
B: string; // -> field | ||
} | ||
``` | ||
// constructor | ||
constructor() {} | ||
```ts | ||
type Foo = { | ||
A(): void; // -> method | ||
// public static method | ||
public static A(): void {} | ||
// no constructor | ||
// -> public instance method | ||
public B(): void {} | ||
} | ||
B: string; // -> field | ||
}; | ||
``` | ||
const Foo = class { | ||
// private instance field | ||
private C: string; | ||
```ts | ||
class Foo { | ||
public static A(): void {} // -> method | ||
public B(): void {} // -> method | ||
// -> public static field | ||
public static E: string; | ||
constructor() {} // -> constructor | ||
// public instance field | ||
public D: string; | ||
private C: string; // -> field | ||
public D: string; // -> field | ||
protected static E: string; // -> field | ||
} | ||
``` | ||
// constructor | ||
constructor() {} | ||
```ts | ||
const Foo = class { | ||
public static A(): void {} // -> method | ||
public B(): void {} // -> method | ||
// public static method | ||
public static A(): void {} | ||
constructor() {} // -> constructor | ||
// -> public instance method | ||
public B(): void {} | ||
private C: string; // -> field | ||
public D: string; // -> field | ||
protected static E: string; // -> field | ||
}; | ||
``` | ||
Examples of **correct** code for the `{ "default": [...] }` option: | ||
#### Configuration: `{ "default": ["public-instance-method", "public-static-field"] }` | ||
Note: This configuration does not apply to interfaces/type literals as accessibility and scope are not part of interfaces/type literals. | ||
##### Incorrect examples | ||
```ts | ||
// { "default": ["method", "constructor", "field"] } | ||
class Foo { | ||
private C: string; // (irrelevant) | ||
interface Foo { | ||
// -> method | ||
A() : void; | ||
public D: string; // (irrelevant) | ||
// -> constructor | ||
new(); | ||
public static E: string; // -> public static field | ||
// -> field | ||
B: string; | ||
} | ||
constructor() {} // (irrelevant) | ||
type Foo = { | ||
// -> method | ||
A() : void; | ||
public static A(): void {} // (irrelevant) | ||
// -> field | ||
B: string; | ||
public B(): void {} // -> public instance method | ||
} | ||
``` | ||
class Foo { | ||
// -> * method | ||
public static A(): void {} | ||
public B(): void {} | ||
Note: Public instance methods should come first before public static fields. Everything else can be placed anywhere. | ||
// -> constructor | ||
constructor() {} | ||
```ts | ||
const Foo = class { | ||
private C: string; // (irrelevant) | ||
// -> * field | ||
private C: string | ||
public D: string | ||
protected static E: string | ||
} | ||
public static E: string; // -> public static field | ||
const Foo = class { | ||
// -> * method | ||
public static A(): void {} | ||
public B(): void {} | ||
public D: string; // (irrelevant) | ||
// -> constructor | ||
constructor() {} | ||
constructor() {} // (irrelevant) | ||
// -> * field | ||
private C: string | ||
public D: string | ||
protected static E: string | ||
} | ||
public static A(): void {} // (irrelevant) | ||
// { "default": ["public-instance-method", "public-static-field"] } | ||
public B(): void {} // -> public instance method | ||
}; | ||
``` | ||
// does not apply for interfaces/type literals (accessibility and scope are not part of interfaces/type literals) | ||
Note: Public instance methods should come first before public static fields. Everything else can be placed anywhere. | ||
##### Correct examples | ||
```ts | ||
class Foo { | ||
// -> public instance method | ||
public B(): void {} | ||
public B(): void {} // -> public instance method | ||
// private instance field | ||
private C: string | ||
private C: string; // (irrelevant) | ||
// public instance field | ||
public D: string | ||
public D: string; // (irrelevant) | ||
// -> public static field | ||
public static E: string | ||
public static E: string; // -> public static field | ||
// constructor | ||
constructor() {} | ||
constructor() {} // (irrelevant) | ||
// public static method | ||
public static A(): void {} | ||
public static A(): void {} // (irrelevant) | ||
} | ||
``` | ||
```ts | ||
const Foo = class { | ||
// -> public instance method | ||
public B(): void {} | ||
public B(): void {} // -> public instance method | ||
// private instance field | ||
private C: string | ||
private C: string; // (irrelevant) | ||
// public instance field | ||
public D: string | ||
public D: string; // (irrelevant) | ||
// constructor | ||
constructor() {} | ||
constructor() {} // (irrelevant) | ||
// public static method | ||
public static A(): void {} | ||
public static A(): void {} // (irrelevant) | ||
// -> protected static field | ||
protected static: string | ||
} | ||
public static E: string; // -> public static field | ||
}; | ||
``` | ||
// { "default": ["public-static-field", "static-field", "instance-field"] } | ||
#### Configuration: `{ "default": ["public-static-field", "static-field", "instance-field"] }` | ||
// does not apply for interfaces/type literals (accessibility and scope are not part of interfaces/type literals) | ||
Note: This configuration does not apply to interfaces/type literals as accessibility and scope are not part of interfaces/type literals. | ||
##### Incorrect examples | ||
```ts | ||
class Foo { | ||
// -> public static field | ||
public static A: string; | ||
private E: string; // -> instance field | ||
// -> * static field | ||
private static B: string; | ||
protected statis C:string; | ||
private static D: string; | ||
private static B: string; // -> static field | ||
protected static C: string; // -> static field | ||
private static D: string; // -> static field | ||
// -> * instance field | ||
private E: string; | ||
public static A: string; // -> public static field | ||
} | ||
``` | ||
Note: Public static fields should come first, followed by static fields and instance fields. | ||
```ts | ||
const foo = class { | ||
// * method | ||
public T(): void {} | ||
public T(): void {} // (irrelevant) | ||
// -> public static field | ||
public static A: string; | ||
private static B: string; // -> static field | ||
// constructor | ||
constructor(){} | ||
constructor() {} // (irrelevant) | ||
// -> * static field | ||
private static B: string; | ||
protected statis C:string; | ||
private static D: string; | ||
private E: string; // -> instance field | ||
// -> * instance field | ||
private E: string; | ||
} | ||
protected static C: string; // -> static field | ||
private static D: string; // -> static field | ||
public static A: string; // -> public static field | ||
}; | ||
``` | ||
### classes | ||
Issue: Public static fields should come first, followed by static fields and instance fields. | ||
Disable using `never` or use one of the valid values (see default) to specify an order. | ||
##### Correct examples | ||
Examples of **incorrect** code for the `{ "classes": [...] }` option: | ||
```ts | ||
class Foo { | ||
public static A: string; // -> public static field | ||
private static B: string; // -> static field | ||
protected static C: string; // -> static field | ||
private static D: string; // -> static field | ||
private E: string; // -> instance field | ||
} | ||
``` | ||
```ts | ||
// { "classes": ["method", "constructor", "field"] } | ||
const foo = class { | ||
public static A: string; // -> public static field | ||
// does not apply for interfaces/type literals/class expressions. | ||
constructor() {} // -> constructor | ||
class Foo { | ||
// -> field | ||
private C: string; | ||
public D: string; | ||
protected static E: string; | ||
private static B: string; // -> static field | ||
protected static C: string; // -> static field | ||
private static D: string; // -> static field | ||
// -> constructor | ||
constructor() {} | ||
private E: string; // -> instance field | ||
// -> method | ||
public static A(): void {} | ||
public B(): void {} | ||
} | ||
public T(): void {} // -> method | ||
}; | ||
``` | ||
// { "classes": ["public-instance-method", "public-static-field"] } | ||
### Custom `classes` configuration | ||
// does not apply for interfaces/type literals/class expressions. | ||
Note: If this is not set, the `default` will automatically be applied to classes as well. If a `classes` configuration is provided, only this configuration will be used for `classes` (i.e. nothing will be merged with `default`). | ||
class Foo { | ||
// private instance field | ||
private C: string; | ||
Note: The configuration for `classes` does not apply to class expressions (use `classExpressions` for them). | ||
// public instance field | ||
public D: string; | ||
#### Configuration: `{ "classes": ["method", "constructor", "field"] }` | ||
// -> public static field | ||
public static E: string; | ||
##### Incorrect example | ||
// constructor | ||
constructor() {} | ||
```ts | ||
class Foo { | ||
private C: string; // -> field | ||
public D: string; // -> field | ||
protected static E: string; // -> field | ||
// public static method | ||
public static A(): void {} | ||
constructor() {} // -> constructor | ||
// -> public instance method | ||
public B(): void {} | ||
public static A(): void {} // -> method | ||
public B(): void {} // -> method | ||
} | ||
``` | ||
Examples of **correct** code for `{ "classes": [...] }` option: | ||
##### Correct example | ||
```ts | ||
// { "classes": ["method", "constructor", "field"] } | ||
// does not apply for interfaces/type literals/class expressions. | ||
class Foo { | ||
// -> * method | ||
public static A(): void {} | ||
public B(): void {} | ||
public static A(): void {} // -> method | ||
public B(): void {} // -> method | ||
// -> constructor | ||
constructor() {} | ||
constructor() {} // -> constructor | ||
// -> * field | ||
private C: string; | ||
public D: string; | ||
protected static E: string; | ||
private C: string; // -> field | ||
public D: string; // -> field | ||
protected static E: string; // -> field | ||
} | ||
``` | ||
// { "classes": ["public-instance-method", "public-static-field"] } | ||
#### Configuration: `{ "classes": ["public-instance-method", "public-static-field"] }` | ||
// does not apply for interfaces/type literals/class expressions. | ||
##### Incorrect example | ||
```ts | ||
class Foo { | ||
// private instance field | ||
private C: string; | ||
private C: string; // (irrelevant) | ||
// public instance field | ||
public D: string; | ||
public D: string; // (irrelevant) | ||
// -> public static field | ||
public static E: string; | ||
public static E: string; // -> public static field | ||
// constructor | ||
constructor() {} | ||
constructor() {} // (irrelevant) | ||
// public static method | ||
public static A(): void {} | ||
public static A(): void {} // (irrelevant) | ||
// -> public instance method | ||
public B(): void {} | ||
public B(): void {} // -> public instance method | ||
} | ||
``` | ||
### classExpressions | ||
##### Correct example | ||
Disable using `never` or use one of the valid values (see default) to specify an order. | ||
Examples of **correct** code for `{ "classes": [...] }` option: | ||
Examples of **incorrect** code for the `{ "classExpressions": [...] }` option: | ||
```ts | ||
// { "classExpressions": ["method", "constructor", "field"] } | ||
class Foo { | ||
private C: string; // (irrelevant) | ||
// does not apply for interfaces/type literals/class expressions. | ||
public D: string; // (irrelevant) | ||
const foo = class { | ||
// -> field | ||
private C: string; | ||
public D: string; | ||
protected static E: string; | ||
public static E: string; // -> public static field | ||
// -> constructor | ||
constructor() {} | ||
constructor() {} // (irrelevant) | ||
// -> method | ||
public static A(): void {} | ||
public B(): void {} | ||
}; | ||
public static A(): void {} // (irrelevant) | ||
// { "classExpressions": ["public-instance-method", "public-static-field"] } | ||
public B(): void {} // -> public instance method | ||
} | ||
``` | ||
// does not apply for interfaces/type literals/class expressions. | ||
### Custom `classExpressions` configuration | ||
const foo = class { | ||
// private instance field | ||
private C: string; | ||
Note: If this is not set, the `default` will automatically be applied to classes expressions as well. If a `classExpressions` configuration is provided, only this configuration will be used for `classExpressions` (i.e. nothing will be merged with `default`). | ||
// public instance field | ||
public D: string; | ||
Note: The configuration for `classExpressions` does not apply to classes (use `classes` for them). | ||
// -> public static field | ||
public static E: string; | ||
#### Configuration: `{ "classExpressions": ["method", "constructor", "field"] }` | ||
// constructor | ||
constructor() {} | ||
##### Incorrect example | ||
// public static method | ||
public static A(): void {} | ||
```ts | ||
const foo = class { | ||
private C: string; // -> field | ||
public D: string; // -> field | ||
protected static E: string; // -> field | ||
// -> public instance method | ||
public B(): void {} | ||
constructor() {} // -> constructor | ||
public static A(): void {} // -> method | ||
public B(): void {} // -> method | ||
}; | ||
``` | ||
Examples of **correct** code for `{ "classExpressions": [...] }` option: | ||
##### Correct example | ||
```ts | ||
// { "classExpressions": ["method", "constructor", "field"] } | ||
const foo = class { | ||
public static A(): void {} // -> method | ||
public B(): void {} // -> method | ||
// does not apply for interfaces/type literals/class expressions. | ||
constructor() {} // -> constructor | ||
private C: string; // -> field | ||
public D: string; // -> field | ||
protected static E: string; // -> field | ||
}; | ||
``` | ||
#### Configuration: `{ "classExpressions": ["public-instance-method", "public-static-field"] }` | ||
##### Incorrect example | ||
```ts | ||
const foo = class { | ||
// -> * method | ||
public static A(): void {} | ||
public B(): void {} | ||
private C: string; // (irrelevant) | ||
// -> constructor | ||
constructor() {} | ||
public D: string; // (irrelevant) | ||
// -> * field | ||
private C: string; | ||
public D: string; | ||
protected static E: string; | ||
public static E: string; // -> public static field | ||
constructor() {} // (irrelevant) | ||
public static A(): void {} // (irrelevant) | ||
public B(): void {} // -> public instance method | ||
}; | ||
``` | ||
// { "classExpressions": ["public-instance-method", "public-static-field"] } | ||
##### Correct example | ||
// does not apply for interfaces/type literals/class expressions. | ||
```ts | ||
const foo = class { | ||
// private instance field | ||
private C: string; | ||
private C: string; // (irrelevant) | ||
// public instance field | ||
public D: string; | ||
public D: string; // (irrelevant) | ||
// -> public static field | ||
public static E: string; | ||
public B(): void {} // -> public instance method | ||
// constructor | ||
constructor() {} | ||
public static E: string; // -> public static field | ||
// public static method | ||
public static A(): void {} | ||
constructor() {} // (irrelevant) | ||
// -> public instance method | ||
public B(): void {} | ||
public static A(): void {} // (irrelevant) | ||
}; | ||
``` | ||
### interfaces | ||
### Custom `interfaces` configuration | ||
Disable using `never` or use one of the following values to specify an order: | ||
`field` | ||
`constructor` | ||
`method` | ||
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`). | ||
Examples of **incorrect** code for the `{ "interfaces": [...] }` option: | ||
Note: The configuration for `interfaces` only allows a limited set of member types: `field`, `constructor` and `method`. | ||
```ts | ||
// { "interfaces": ["method", "constructor", "field"] } | ||
Note: The configuration for `interfaces` does not apply to type literals (use `typeLiterals` for them). | ||
// does not apply for classes/class expressions/type literals | ||
#### Configuration: `{ "interfaces": ["method", "constructor", "field"] }` | ||
##### Incorrect example | ||
```ts | ||
interface Foo { | ||
// -> field | ||
B: string; | ||
B: string; // -> field | ||
// -> constructor | ||
new (); | ||
new (); // -> constructor | ||
// -> method | ||
A(): void; | ||
A(): void; // -> method | ||
} | ||
``` | ||
Examples of **correct** code for the `{ "interfaces": [...] }` option: | ||
##### Correct example | ||
```ts | ||
// { "interfaces": ["method", "constructor", "field"] } | ||
// does not apply for classes/class expressions/type literals | ||
interface Foo { | ||
// -> method | ||
A(): void; | ||
A(): void; // -> method | ||
// -> constructor | ||
new (); | ||
new (); // -> constructor | ||
// -> field | ||
B: string; | ||
B: string; // -> field | ||
} | ||
``` | ||
### typeLiterals | ||
### Custom `typeLiterals` configuration | ||
Disable using `never` or use one of the valid values (see interfaces) to specify an order. | ||
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`). | ||
Examples of **incorrect** code for the `{ "typeLiterals": [...] }` option: | ||
Note: The configuration for `typeLiterals` only allows a limited set of member types: `field`, `constructor` and `method`. | ||
```ts | ||
// { "typeLiterals": ["method", "constructor", "field"] } | ||
Note: The configuration for `typeLiterals` does not apply to type literals (use `interfaces` for them). | ||
// does not apply for classes/class expressions/interfaces | ||
#### Configuration: `{ "typeLiterals": ["method", "constructor", "field"] }` | ||
##### Incorrect example | ||
```ts | ||
type Foo = { | ||
// -> field | ||
B: string; | ||
B: string; // -> field | ||
// -> method | ||
A(): void; | ||
A(): void; // -> method | ||
new (); // -> constructor | ||
}; | ||
``` | ||
Examples of **correct** code for the `{ "typeLiterals": [...] }` option: | ||
##### Correct example | ||
```ts | ||
// { "typeLiterals": ["method", "constructor", "field"] } | ||
// does not apply for classes/class expressions/interfaces | ||
type Foo = { | ||
// -> method | ||
A(): void; | ||
A(): void; // -> method | ||
// -> constructor | ||
new (); | ||
new (); // -> constructor | ||
// -> field | ||
B: string; | ||
B: string; // -> field | ||
}; | ||
@@ -595,0 +642,0 @@ ``` |
{ | ||
"name": "@typescript-eslint/eslint-plugin", | ||
"version": "1.4.3-alpha.4+18484a2", | ||
"version": "1.4.3-alpha.5+3b28cac", | ||
"description": "TypeScript plugin for ESLint", | ||
@@ -38,4 +38,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@typescript-eslint/parser": "1.4.3-alpha.4+18484a2", | ||
"@typescript-eslint/typescript-estree": "1.4.3-alpha.4+18484a2", | ||
"@typescript-eslint/parser": "1.4.3-alpha.5+3b28cac", | ||
"@typescript-eslint/typescript-estree": "1.4.3-alpha.5+3b28cac", | ||
"requireindex": "^1.2.0", | ||
@@ -51,3 +51,3 @@ "tsutils": "^3.7.0" | ||
}, | ||
"gitHead": "18484a2d88aecba27b076bb6193b9ea98ece844d" | ||
"gitHead": "3b28cacd49a1bc61ba0c3f8f76096f6902b92848" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
444901
4812