tslint-lines-between-class-members
Advanced tools
Comparing version
@@ -47,3 +47,4 @@ "use strict"; | ||
var isPrevLineOpeningBrace = this.isPrevLineOpeningBrace(node, this.getSourceFile()); | ||
if (!arePrevLinesBlank && !isPrevLineClassDec && !isPrevLineOpeningBrace) { | ||
var isClassMethod = this.isClassMethod(node); | ||
if (!arePrevLinesBlank && !isPrevLineClassDec && !isPrevLineOpeningBrace && isClassMethod) { | ||
this.onRuleLintFail(node); | ||
@@ -115,2 +116,9 @@ } | ||
/** | ||
* Tests whether method is within a class (as opposed to within an object literal) | ||
*/ | ||
LinesBetweenClassMembersWalker.prototype.isClassMethod = function (node) { | ||
var parentType = node.parent && node.parent.kind; | ||
return parentType === ts.SyntaxKind.ClassDeclaration; | ||
}; | ||
/** | ||
* Gets the text content of a line above the method | ||
@@ -117,0 +125,0 @@ * Any documenting comments are ignored and we start from the first line above those |
{ | ||
"name": "tslint-lines-between-class-members", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Custom rule for TSLint to enforce blank lines between class methods - achieves a similar thing to lines-between-class-members in ESLint", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -214,1 +214,21 @@ import test, {AssertContext} from 'ava'; | ||
}); | ||
test('ignores default exported object', (t: AssertContext) => { | ||
const results = TestHelpers.lint('passes/exportDefault.ts'); | ||
t.is(results.errorCount, 0); | ||
}); | ||
test('ignores default exported object with multiple methods', (t: AssertContext) => { | ||
const results = TestHelpers.lint('passes/exportDefaultMultipleMethods.ts'); | ||
t.is(results.errorCount, 0); | ||
}); | ||
test('ignores exported object', (t: AssertContext) => { | ||
const results = TestHelpers.lint('passes/export.ts'); | ||
t.is(results.errorCount, 0); | ||
}); | ||
test('ignores exported object with multiple methods', (t: AssertContext) => { | ||
const results = TestHelpers.lint('passes/exportMultipleMethods.ts'); | ||
t.is(results.errorCount, 0); | ||
}); |
@@ -38,3 +38,4 @@ import * as Lint from 'tslint'; | ||
const isPrevLineOpeningBrace = this.isPrevLineOpeningBrace(node, this.getSourceFile()); | ||
if (!arePrevLinesBlank && !isPrevLineClassDec && !isPrevLineOpeningBrace) { | ||
const isClassMethod = this.isClassMethod(node); | ||
if (!arePrevLinesBlank && !isPrevLineClassDec && !isPrevLineOpeningBrace && isClassMethod) { | ||
this.onRuleLintFail(node); | ||
@@ -113,2 +114,10 @@ } | ||
/** | ||
* Tests whether method is within a class (as opposed to within an object literal) | ||
*/ | ||
private isClassMethod(node: ts.FunctionLikeDeclaration): boolean { | ||
const parentType = node.parent && node.parent.kind; | ||
return parentType === ts.SyntaxKind.ClassDeclaration; | ||
} | ||
/** | ||
* Gets the text content of a line above the method | ||
@@ -115,0 +124,0 @@ * Any documenting comments are ignored and we start from the first line above those |
Sorry, the diff of this file is not supported yet
135320
1.34%54
8%945
5.47%