Skip to content

Commit

Permalink
no-empty: fix lack of methods handling (palantir#3897)
Browse files Browse the repository at this point in the history
* no-empty: ensure rule works for typed functions

* no-empty: prove lack of methods handling

* fix
  • Loading branch information
keradus authored and giladgray committed May 10, 2018
1 parent dc54347 commit 13723b5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rules/noEmptyRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ function isExcluded(node: ts.Node, options: Options): boolean {
}

if (options.allowEmptyFunctions &&
(node.kind === ts.SyntaxKind.FunctionDeclaration ||
(node.kind === ts.SyntaxKind.MethodDeclaration ||
node.kind === ts.SyntaxKind.FunctionDeclaration ||
node.kind === ts.SyntaxKind.FunctionExpression ||
node.kind === ts.SyntaxKind.ArrowFunction)) {
return true;
Expand Down
11 changes: 11 additions & 0 deletions test/rules/no-empty/allow-empty-catch/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const testFunction2 = () => { };
const testFunction3 = function() {}
~~ [block is empty]

const testFunction4 = function(): void {}
~~ [block is empty]

for (var x = 0; x < 1; ++x) { }
~~~ [block is empty]

Expand Down Expand Up @@ -70,6 +73,14 @@ class PublicClassConstructor {
~~ [block is empty]
}

class ClassMethod {
public methodWithoutResultTypehinting() {}
~~ [block is empty]

public methodWithResultTypehinting(): void {}
~~ [block is empty]
}

try {
throw new Error();
} catch (error) {}
8 changes: 8 additions & 0 deletions test/rules/no-empty/allow-empty-functions/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const testFunction2 = () => { };

const testFunction3 = function() {}

const testFunction4 = function(): void {}

for (var x = 0; x < 1; ++x) { }
~~~ [block is empty]

Expand Down Expand Up @@ -67,6 +69,12 @@ class PublicClassConstructor {
~~ [block is empty]
}

class ClassMethod {
public methodWithoutResultTypehinting() {}

public methodWithResultTypehinting(): void {}
}

try {
throw new Error();
} catch (error) {}
Expand Down
11 changes: 11 additions & 0 deletions test/rules/no-empty/default/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const testFunction2 = () => { };
const testFunction3 = function() {}
~~ [block is empty]

const testFunction4 = function(): void {}
~~ [block is empty]

for (var x = 0; x < 1; ++x) { }
~~~ [block is empty]

Expand Down Expand Up @@ -70,6 +73,14 @@ class PublicClassConstructor {
~~ [block is empty]
}

class ClassMethod {
public methodWithoutResultTypehinting() {}
~~ [block is empty]

public methodWithResultTypehinting(): void {}
~~ [block is empty]
}

try {
throw new Error();
} catch (error) {}
Expand Down

0 comments on commit 13723b5

Please sign in to comment.