File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ import * as ts from 'typescript' ;
2
+ import * as Lint from 'tslint' ;
3
+
4
+ /**
5
+ * Rule that ensures that there are no spaces before/after the braces in import clauses.
6
+ */
7
+ export class Rule extends Lint . Rules . AbstractRule {
8
+ apply ( sourceFile : ts . SourceFile ) {
9
+ return this . applyWithWalker ( new Walker ( sourceFile , this . getOptions ( ) ) ) ;
10
+ }
11
+ }
12
+
13
+ class Walker extends Lint . RuleWalker {
14
+ visitImportDeclaration ( node : ts . ImportDeclaration ) {
15
+ if ( ! node . importClause ) {
16
+ return super . visitImportDeclaration ( node ) ;
17
+ }
18
+
19
+ const importClause = node . importClause . getText ( ) ;
20
+
21
+ if ( importClause . startsWith ( '{' ) && importClause . endsWith ( '}' ) && (
22
+ importClause . includes ( '{ ' ) || importClause . includes ( ' }' ) ) ) {
23
+ this . addFailureAtNode ( node . importClause , 'Import clauses should not have spaces after the ' +
24
+ 'opening brace or before the closing one.' ) ;
25
+ }
26
+
27
+ super . visitImportDeclaration ( node ) ;
28
+ }
29
+ }
Original file line number Diff line number Diff line change 97
97
// Custom Rules
98
98
"ts-loader" : true ,
99
99
"no-exposed-todo" : true ,
100
+ "no-import-spacing" : true ,
100
101
"setters-after-getters" : true ,
101
102
"rxjs-imports" : true ,
102
103
"no-host-decorator-in-concrete" : [
You can’t perform that action at this time.
0 commit comments