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

Commit

Permalink
prefer-function-over-method should ignore abstract methods (#2307)
Browse files Browse the repository at this point in the history
Abstract methods have no body, and never use `this`, so the `prefer-function-over-method` rule should not apply to them.
  • Loading branch information
sbj42 authored and nchen63 committed Mar 7, 2017
1 parent 3923abf commit 5661bfb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules/preferFunctionOverMethodRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class PreferFunctionOverMethodWalker extends Lint.RuleWalker {
}

private shouldWarnForModifiers(node: ts.MethodDeclaration): boolean {
if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword)) {
if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword, ts.SyntaxKind.AbstractKeyword)) {
return false;
}
// TODO: Also return false if it's marked "override" (https://github.com/palantir/tslint/pull/2037)
Expand Down
4 changes: 4 additions & 0 deletions test/rules/prefer-function-over-method/default/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class C {
~~~~~~~~~~~~~~~~~ [0]
}

abstract class C2 {
abstract abstract(): void;
}

const o = {
x() {}
}
Expand Down

0 comments on commit 5661bfb

Please sign in to comment.