build: add tslint rule enforce import spacing (#12536)

This commit is contained in:
Kristiyan Kostadinov
2018-08-07 22:26:27 +02:00
committed by Joey Perrott
parent 1e1751f61e
commit 96923331e9
2 changed files with 30 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import * as ts from 'typescript';
import * as Lint from 'tslint';
/**
* Rule that ensures that there are no spaces before/after the braces in import clauses.
*/
export class Rule extends Lint.Rules.AbstractRule {
apply(sourceFile: ts.SourceFile) {
return this.applyWithWalker(new Walker(sourceFile, this.getOptions()));
}
}
class Walker extends Lint.RuleWalker {
visitImportDeclaration(node: ts.ImportDeclaration) {
if (!node.importClause) {
return super.visitImportDeclaration(node);
}
const importClause = node.importClause.getText();
if (importClause.startsWith('{') && importClause.endsWith('}') && (
importClause.includes('{ ') || importClause.includes(' }'))) {
this.addFailureAtNode(node.importClause, 'Import clauses should not have spaces after the ' +
'opening brace or before the closing one.');
}
super.visitImportDeclaration(node);
}
}
+1
View File
@@ -97,6 +97,7 @@
// Custom Rules
"ts-loader": true,
"no-exposed-todo": true,
"no-import-spacing": true,
"setters-after-getters": true,
"rxjs-imports": true,
"no-host-decorator-in-concrete": [