Skip to content

Commit f571633

Browse files
crisbetojelbourn
authored andcommitted
build: add fixer to import spacing rule (#15818)
Adds a fixer to the `noImportSpacing` rule so that it can be fixed automatically by IDEs.
1 parent 85f95f0 commit f571633

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

tools/tslint-rules/noImportSpacingRule.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ class Walker extends Lint.RuleWalker {
1616
return super.visitImportDeclaration(node);
1717
}
1818

19-
const importClause = node.importClause.getText();
19+
const importClauseText = node.importClause.getText();
20+
21+
if (importClauseText.startsWith('{') && importClauseText.endsWith('}') && (
22+
importClauseText.includes('{ ') || importClauseText.includes(' }'))) {
23+
24+
const fix = new Lint.Replacement(
25+
node.importClause.getStart(), node.importClause.getWidth(),
26+
importClauseText.replace(/{\s+/, '{').replace(/\s+}/, '}')
27+
);
2028

21-
if (importClause.startsWith('{') && importClause.endsWith('}') && (
22-
importClause.includes('{ ') || importClause.includes(' }'))) {
2329
this.addFailureAtNode(node.importClause, 'Import clauses should not have spaces after the ' +
24-
'opening brace or before the closing one.');
30+
'opening brace or before the closing one.', fix);
2531
}
2632

2733
super.visitImportDeclaration(node);

0 commit comments

Comments
 (0)