From dc08df5540f3bbd2211ed363b4de3b7f193bdb2b Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 5 Feb 2019 16:15:50 -0600 Subject: [PATCH] Fix curly statement newlines rule when prefixed with newlines --- rules/src/curlyStatementNewlinesRule.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rules/src/curlyStatementNewlinesRule.ts b/rules/src/curlyStatementNewlinesRule.ts index 18b7f0a9f..317eba63a 100644 --- a/rules/src/curlyStatementNewlinesRule.ts +++ b/rules/src/curlyStatementNewlinesRule.ts @@ -5,8 +5,7 @@ import * as Lint from "tslint"; * Curly statement newlines rule. */ export class Rule extends Lint.Rules.AbstractRule { - - public static FAILURE_STRING = "curly statements must separate with newlines"; + public static FAILURE_STRING = "Curly statements must separate with newlines"; /** * Apply the rule. @@ -14,24 +13,21 @@ export class Rule extends Lint.Rules.AbstractRule { public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new CurlyStatementNewlinesWalker(sourceFile, this.getOptions())); } - } /** * Curly statement newlines walker. */ class CurlyStatementNewlinesWalker extends Lint.RuleWalker { - /** * Visit if statements. */ public visitIfStatement(node: ts.IfStatement): void { - const splitLength = node.getFullText().split("\n").length; + const splitLength = node.getFullText().trim().split("\n").length; if (splitLength <= 2) { this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING); } super.visitIfStatement(node); } - }