Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/rules/src/curlyStatementNewlinesRule.ts

34 lines
845 B
TypeScript

import * as ts from "typescript";
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";
/**
* Apply the rule.
*/
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().trim().split("\n").length;
if (splitLength <= 2) {
this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING);
}
super.visitIfStatement(node);
}
}