Skip to content

build: add fixer to import spacing rule #15818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions tools/tslint-rules/noImportSpacingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ class Walker extends Lint.RuleWalker {
return super.visitImportDeclaration(node);
}

const importClause = node.importClause.getText();
const importClauseText = node.importClause.getText();

if (importClauseText.startsWith('{') && importClauseText.endsWith('}') && (
importClauseText.includes('{ ') || importClauseText.includes(' }'))) {

const fix = new Lint.Replacement(
node.importClause.getStart(), node.importClause.getWidth(),
importClauseText.replace(/{\s+/, '{').replace(/\s+}/, '}')
);

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.');
'opening brace or before the closing one.', fix);
}

super.visitImportDeclaration(node);
Expand Down