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

Treat a property foo: () => void like foo = () => {}: as a method declaration. #1849

Closed
Closed
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
5 changes: 3 additions & 2 deletions src/rules/memberOrderingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ export class MemberOrderingWalker extends Lint.RuleWalker {
}

public visitPropertyDeclaration(node: ts.PropertyDeclaration) {
const { initializer } = node;
const isFunction = initializer != null
const { initializer, type } = node;
const isFunction = type && type.kind === ts.SyntaxKind.FunctionType
|| initializer != null
&& (initializer.kind === ts.SyntaxKind.ArrowFunction || initializer.kind === ts.SyntaxKind.FunctionExpression);
this.checkModifiersAndSetPrevious(node, getModifiers(isFunction, node.modifiers));
this.pushMember(getNodeAndModifiers(node, isFunction));
Expand Down
2 changes: 1 addition & 1 deletion test/rules/member-ordering/method/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ interface IArrowMethods {

class ArrowMethods {
public a = 5;
private callback: () => void
public b = "foo";
private callback: () => void;
public c() {}
public d = () => {};
public e = function() {};
Expand Down
3 changes: 2 additions & 1 deletion test/rules/member-ordering/order/fields-first/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ class Good {
protected static h() {}
private static i = () => {};
j = () => {};
jj: () => void;
protected k() {};
private l = () => {};
}

interface IGood {
foo: number;
arrowsAreFields: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ class Good {
private f = foo();
constructor() {}
j = () => {};
jj: () => void;
protected k() {};
private l = () => {};
public static g() {}
protected static h() {}
private static i = () => {};
}

interface IGood {
foo: number;
arrowsAreFields: () => void;
Expand Down
3 changes: 2 additions & 1 deletion test/rules/member-ordering/order/statics-first/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ class Good {
private f = foo();
constructor() {}
j = () => {};
jj: () => void;
protected k() {};
private l = () => {};
}

interface IGood {
foo: number;
arrowsAreFields: () => void;
Expand Down