mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build: add tslint rule enforce import spacing (#12536)
This commit is contained in:
committed by
Joey Perrott
parent
1e1751f61e
commit
96923331e9
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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": [
|
||||
|
||||
Reference in New Issue
Block a user