Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Support multiple old-style options. #2123

Merged
merged 2 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
540 changes: 290 additions & 250 deletions src/rules/memberOrderingRule.ts

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions test/rules/member-ordering/custom-categories/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class C {
static foo() {}
protected static bar = 0;
static baz();

constructor();

static bang();
~~~~~~~~~~~~~~ [Declaration of static non-private not allowed after declaration of constructor. Instead, this should come at the beginning of the class/interface.]
}
18 changes: 18 additions & 0 deletions test/rules/member-ordering/custom-categories/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"rules": {
"member-ordering": [true, {
"order": [
{
"name": "static non-private",
"kinds": [
"public-static-field",
"protected-static-field",
"public-static-method",
"protected-static-method"
]
},
"constructor"
]
}]
}
}
16 changes: 16 additions & 0 deletions test/rules/member-ordering/mix-old-options/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Foo {
public static x: number;
private static y: number;
public x: number;
private y: number;

public static m() {}
private static n() {}

constructor() {}
public m() {}
private n() {}

z: number;
~~~~~~~~~~ [Declaration of public instance field not allowed after declaration of private instance method. Instead, this should come after private static fields.]
}
9 changes: 9 additions & 0 deletions test/rules/member-ordering/mix-old-options/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"rules": {
"member-ordering": [true,
"public-before-private",
"static-before-instance",
"variables-before-functions"
]
}
}
12 changes: 12 additions & 0 deletions test/rules/member-ordering/omit-access-modifier/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class C {
private static x = 0;
static y = 1;

x = 0;
private y = 1;

constructor() {}

static z = 2;
~~~~~~~~~~~~~ [Declaration of static field not allowed after declaration of constructor. Instead, this should come at the beginning of the class/interface.]
}
9 changes: 9 additions & 0 deletions test/rules/member-ordering/omit-access-modifier/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"rules": {
"member-ordering": [true, { "order": [
"static-field",
"instance-field",
"constructor"
]}]
}
}
10 changes: 0 additions & 10 deletions test/rules/member-ordering/private/test.ts.lint

This file was deleted.

10 changes: 10 additions & 0 deletions test/rules/member-ordering/public-before-private/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Foo {
private x: number;
private bar(): any {
var bla: { a: string } = {a: '1'};
}
y: number;
~~~~~~~~~~ [0]
}

[0]: Declaration of public member not allowed after declaration of private member. Instead, this should come at the beginning of the class/interface.
10 changes: 10 additions & 0 deletions test/rules/member-ordering/static-before-instance/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Foo {
x: number;
static y: number;
~~~~~~~~~~~~~~~~~ [0]
constructor() {
// nothing to do
}
}

[0]: Declaration of static member not allowed after declaration of instance member. Instead, this should come at the beginning of the class/interface.
10 changes: 0 additions & 10 deletions test/rules/member-ordering/static/test.ts.lint

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,20 @@ class Constructor2 {
~~~~~~~~~~~~~~~~~ [0]
}

[0]: Declaration of public instance member variable not allowed to appear after declaration of public instance member function
// Works for type literal, just like interface
type T = {
x(): void;
y: number;
~~~~~~~~~~ [0]
}

// Works for class inside object literal
const o = {
foo: class C {
x(): void;
y: number;
~~~~~~~~~~ [0]
}
}

[0]: Declaration of field not allowed after declaration of method. Instead, this should come at the beginning of the class/interface.