Skip to content

Commit

Permalink
build: add lint rule to disallow type-only imports/exports (#24678)
Browse files Browse the repository at this point in the history
Type-only imports and exports don't work with Closure so we can't use them.
  • Loading branch information
crisbeto authored Mar 27, 2022
1 parent 87ab4f4 commit 4f01bac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tools/tslint-rules/noTypeOnlyImportExportRule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ts from 'typescript';
import * as Lint from 'tslint';

/** Lint rule that doesn't allow usages of type-only imports/exports. */
export class Rule extends Lint.Rules.AbstractRule {
apply(sourceFile: ts.SourceFile) {
return this.applyWithFunction(sourceFile, walker);
}
}

function walker(context: Lint.WalkContext): void {
(function visitNode(node: ts.Node) {
if (ts.isTypeOnlyImportOrExportDeclaration(node)) {
context.addFailureAtNode(node, 'Type-only symbols are not allowed.');
}

ts.forEachChild(node, visitNode);
})(context.sourceFile);
}
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
// Custom Rules
"ts-loader": true,
"no-exposed-todo": true,
"no-type-only-import-export": true,
"no-private-getters": [true, "^_"],
"no-undecorated-base-class-di": true,
"no-undecorated-class-with-angular-features": true,
Expand Down

0 comments on commit 4f01bac

Please sign in to comment.