Fix curly statement newlines rule when prefixed with newlines
This commit is contained in:
parent
70ad911641
commit
dc08df5540
@ -5,8 +5,7 @@ import * as Lint from "tslint";
|
|||||||
* Curly statement newlines rule.
|
* Curly statement newlines rule.
|
||||||
*/
|
*/
|
||||||
export class Rule extends Lint.Rules.AbstractRule {
|
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.
|
* Apply the rule.
|
||||||
@ -14,24 +13,21 @@ export class Rule extends Lint.Rules.AbstractRule {
|
|||||||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
||||||
return this.applyWithWalker(new CurlyStatementNewlinesWalker(sourceFile, this.getOptions()));
|
return this.applyWithWalker(new CurlyStatementNewlinesWalker(sourceFile, this.getOptions()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Curly statement newlines walker.
|
* Curly statement newlines walker.
|
||||||
*/
|
*/
|
||||||
class CurlyStatementNewlinesWalker extends Lint.RuleWalker {
|
class CurlyStatementNewlinesWalker extends Lint.RuleWalker {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit if statements.
|
* Visit if statements.
|
||||||
*/
|
*/
|
||||||
public visitIfStatement(node: ts.IfStatement): void {
|
public visitIfStatement(node: ts.IfStatement): void {
|
||||||
const splitLength = node.getFullText().split("\n").length;
|
const splitLength = node.getFullText().trim().split("\n").length;
|
||||||
if (splitLength <= 2) {
|
if (splitLength <= 2) {
|
||||||
this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING);
|
this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
super.visitIfStatement(node);
|
super.visitIfStatement(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user