Skip to content

Commit

Permalink
feat(eslint-plugin): implement review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
timkraut committed Mar 31, 2020
1 parent d67a748 commit cd01479
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 55 deletions.
30 changes: 14 additions & 16 deletions packages/eslint-plugin/docs/rules/member-ordering.md
Expand Up @@ -166,8 +166,10 @@ The default configuration looks as follows:
```json5
{
default: [
// Index signature
'signature',

// Fields
'public-static-field',
'protected-static-field',
'private-static-field',
Expand Down Expand Up @@ -481,7 +483,7 @@ const foo = class {
};
```

Issue: Public static fields should come first, followed by static fields and instance fields.
Note: Public static fields should come first, followed by static fields and instance fields.

##### Correct examples

Expand Down Expand Up @@ -575,21 +577,19 @@ class Foo {

##### Correct example

Examples of **correct** code for `{ "classes": [...] }` option:

```ts
class Foo {
private C: string; // (irrelevant)

public D: string; // (irrelevant)

public static E: string; // -> public static field
public B(): void {} // -> public instance method

constructor() {} // (irrelevant)

public static A(): void {} // (irrelevant)

public B(): void {} // -> public instance method
public static E: string; // -> public static field
}
```

Expand Down Expand Up @@ -749,7 +749,7 @@ type Foo = {

It is possible to sort all members within a group alphabetically.

#### Configuration: `{ default: { order: 'alphabetically' } }`
#### Configuration: `{ default: { memberTypes: <Default Order>, order: 'alphabetically' } }`

This will apply the default order (see above) and enforce an alphabetic order within each group.

Expand All @@ -761,38 +761,36 @@ interface Foo {
b: x;
c: x;

new (): Bar;
(): Baz;

a(): void;
b(): void;
c(): void;

// Wrong group order, should be placed before all field definitions
[a: string]: number;
(): Baz;

new (): Bar;
}
```

Note: Wrong group order for `new () : Bar`.

```ts
interface Foo {
[a: string]: number;

a: x;
b: x;
c: x;

new (): Bar;
(): Baz;

// Wrong alphabetic order within group
c(): void;
b(): void;
a(): void;

[a: string]: number;
(): Baz;
}
```

Note: Wrong alphabetic order (should be `a(): void` --> `b(): void` --> `c(): void`).

### Sorting alphabetically while ignoring member groups

It is also possible to sort all members and ignore the member groups completely.
Expand Down
78 changes: 39 additions & 39 deletions packages/eslint-plugin/tests/rules/member-ordering.test.ts
Expand Up @@ -3629,14 +3629,14 @@ const sortedWithoutGroupingDefaultOption: TSESLint.RunTests<
{
code: `
interface Foo {
a : b;
[a: string] : number;
b() : void;
new () : Bar; // Will be ignored (no sortable identifier)
() : Baz; // Will be ignored (no sortable identifier)
a(): Foo;
(): Foo;
b(): Foo;
}
`,
options: [{ default: { memberTypes: 'never', order: 'alphabetically' } }],
options: [
{ default: { memberTypes: defaultOrder, order: 'alphabetically' } },
],
},

// default option + interface + lower/upper case
Expand Down Expand Up @@ -3668,8 +3668,8 @@ type Foo = {
a : b;
[a: string] : number;
b() : void;
new () : Bar; // Will be ignored (no sortable identifier)
() : Baz; // Will be ignored (no sortable identifier)
new () : Bar;
() : Baz;
}
`,
options: [{ default: { memberTypes: 'never', order: 'alphabetically' } }],
Expand Down Expand Up @@ -3704,7 +3704,7 @@ class Foo {
public static a : string;
protected static b : string = "";
private static c : string = "";
constructor() {} // Will be ignored (no sortable identifier)
constructor() {}
public d : string = "";
protected e : string = "";
private f : string = "";
Expand Down Expand Up @@ -3742,7 +3742,7 @@ const foo = class Foo {
public static a : string;
protected static b : string = "";
private static c : string = "";
constructor() {} // Will be ignored (no sortable identifier)
constructor() {}
public d : string = "";
protected e : string = "";
private f : string = "";
Expand Down Expand Up @@ -3781,8 +3781,8 @@ interface Foo {
b() : void;
a : b;
[a: string] : number;
new () : Bar; // Will be ignored (no sortable identifier)
() : Baz; // Will be ignored (no sortable identifier)
new () : Bar;
() : Baz;
}
`,
options: [{ default: { memberTypes: 'never', order: 'alphabetically' } }],
Expand Down Expand Up @@ -3832,8 +3832,8 @@ type Foo = {
b() : void;
a : b;
[a: string] : number;
new () : Bar; // Will be ignored (no sortable identifier)
() : Baz; // Will be ignored (no sortable identifier)
new () : Bar;
() : Baz;
}
`,
options: [{ default: { memberTypes: 'never', order: 'alphabetically' } }],
Expand Down Expand Up @@ -3883,7 +3883,7 @@ class Foo {
protected static b : string = "";
public static a : string;
private static c : string = "";
constructor() {} // Will be ignored (no sortable identifier)
constructor() {}
public d : string = "";
protected e : string = "";
private f : string = "";
Expand Down Expand Up @@ -3936,7 +3936,7 @@ const foo = class Foo {
protected static b : string = "";
public static a : string;
private static c : string = "";
constructor() {} // Will be ignored (no sortable identifier)
constructor() {}
public d : string = "";
protected e : string = "";
private f : string = "";
Expand Down Expand Up @@ -4068,7 +4068,7 @@ class Foo {
public static a : string;
protected static b : string = "";
private static c : string = "";
constructor() {} // Will be ignored (no sortable identifier)
constructor() {}
public d : string = "";
protected e : string = "";
private f : string = "";
Expand Down Expand Up @@ -4145,7 +4145,7 @@ class Foo {
protected static b : string = "";
public static a : string;
private static c : string = "";
constructor() {} // Will be ignored (no sortable identifier)
constructor() {}
public d : string = "";
protected e : string = "";
private f : string = "";
Expand Down Expand Up @@ -4333,7 +4333,7 @@ const foo = class Foo {
public static a : string;
protected static b : string = "";
private static c : string = "";
constructor() {} // Will be ignored (no sortable identifier)
constructor() {}
public d : string = "";
protected e : string = "";
private f : string = "";
Expand Down Expand Up @@ -4378,7 +4378,7 @@ const foo = class Foo {
protected static b : string = "";
public static a : string;
private static c : string = "";
constructor() {} // Will be ignored (no sortable identifier)
constructor() {}
public d : string = "";
protected e : string = "";
private f : string = "";
Expand Down Expand Up @@ -4442,8 +4442,8 @@ interface Foo {
[a: string] : number;
a : b;
b() : void;
new () : Bar; // Will be ignored (no sortable identifier)
() : Baz; // Will be ignored (no sortable identifier)
new () : Bar;
() : Baz;
}
`,
options: [
Expand Down Expand Up @@ -4615,8 +4615,8 @@ interface Foo {
b() : void;
a : b;
[a: string] : number;
new () : Bar; // Will be ignored (no sortable identifier)
() : Baz; // Will be ignored (no sortable identifier)
new () : Bar;
() : Baz;
}
`,
options: [
Expand Down Expand Up @@ -4719,8 +4719,8 @@ type Foo = {
[a: string] : number;
a : b;
b() : void;
new () : Bar; // Will be ignored (no sortable identifier)
() : Baz; // Will be ignored (no sortable identifier)
new () : Bar;
() : Baz;
}
`,
options: [
Expand Down Expand Up @@ -4850,8 +4850,8 @@ type Foo = {
b() : void;
a : b;
[a: string] : number;
new () : Bar; // Will be ignored (no sortable identifier)
() : Baz; // Will be ignored (no sortable identifier)
new () : Bar;
() : Baz;
}
`,
options: [
Expand Down Expand Up @@ -4921,7 +4921,7 @@ interface Foo {
b() : void;
c() : void;
() : Baz; // Will be ignored (no sortable identifier)
() : Baz;
}
`,
options: [
Expand All @@ -4944,7 +4944,7 @@ interface Foo {
c : x;
[a: string] : number;
() : Baz; // Will be ignored (no sortable identifier)
() : Baz;
}
`,
options: [
Expand Down Expand Up @@ -4973,7 +4973,7 @@ type Foo = {
b() : void;
c() : void;
() : Baz; // Will be ignored (no sortable identifier)
() : Baz;
}
`,
options: [
Expand All @@ -4997,7 +4997,7 @@ type Foo = {
b : x;
c : x;
() : Baz; // Will be ignored (no sortable identifier)
() : Baz;
}
`,
options: [
Expand Down Expand Up @@ -5115,7 +5115,7 @@ interface Foo {
b() : void;
a() : void;
() : Baz; // Will be ignored (no sortable identifier)
() : Baz;
new () : Bar;
}
Expand Down Expand Up @@ -5148,7 +5148,7 @@ type Foo = {
b() : void;
a() : void;
() : Baz; // Will be ignored (no sortable identifier)
() : Baz;
new () : Bar;
}
Expand Down Expand Up @@ -5533,7 +5533,7 @@ interface Foo {
new () : Bar;
() : Baz; // Will be ignored (no sortable identifier)
() : Baz;
}
`,
options: [
Expand Down Expand Up @@ -5561,7 +5561,7 @@ interface Foo {
c : x;
[a: string] : number;
() : Baz; // Will be ignored (no sortable identifier)
() : Baz;
}
`,
options: [
Expand Down Expand Up @@ -5647,7 +5647,7 @@ interface Foo {
b() : void;
a() : void;
() : Baz; // Will be ignored (no sortable identifier)
() : Baz;
new () : Bar;
}
Expand Down Expand Up @@ -5739,7 +5739,7 @@ type Foo = {
c : x;
[a: string] : number;
() : Baz; // Will be ignored (no sortable identifier)
() : Baz;
}
`,
options: [
Expand Down Expand Up @@ -5803,7 +5803,7 @@ type Foo = {
b() : void;
a() : void;
() : Baz; // Will be ignored (no sortable identifier)
() : Baz;
new () : Bar;
}
Expand Down

0 comments on commit cd01479

Please sign in to comment.