From 10ca2a048cc419372fd4d968432373eb1a8d8b14 Mon Sep 17 00:00:00 2001 From: James Clark Date: Mon, 6 Mar 2017 20:51:31 -0500 Subject: [PATCH 1/2] Test case for issue 2305 `prefer-function-over-method` should ignore abstract methods. In this commit, the new test case fails. --- test/rules/prefer-function-over-method/default/test.ts.lint | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/rules/prefer-function-over-method/default/test.ts.lint b/test/rules/prefer-function-over-method/default/test.ts.lint index 7cc2e39d5ac..2fcc46149a3 100644 --- a/test/rules/prefer-function-over-method/default/test.ts.lint +++ b/test/rules/prefer-function-over-method/default/test.ts.lint @@ -44,6 +44,10 @@ class C { ~~~~~~~~~~~~~~~~~ [0] } +abstract class C2 { + abstract abstract(): void; +} + const o = { x() {} } From 3336ff540133f10d632e49fd999b638c6d935dea Mon Sep 17 00:00:00 2001 From: James Clark Date: Mon, 6 Mar 2017 20:59:10 -0500 Subject: [PATCH 2/2] Ignore abstract methods in `prefer-function-...` Abstract methods have no body, and never use `this`, so the `prefer-function-over-method` rule should not apply to them. --- src/rules/preferFunctionOverMethodRule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/preferFunctionOverMethodRule.ts b/src/rules/preferFunctionOverMethodRule.ts index a3eefc34492..7939efb9cc9 100644 --- a/src/rules/preferFunctionOverMethodRule.ts +++ b/src/rules/preferFunctionOverMethodRule.ts @@ -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)