Skip to content

Commit

Permalink
build: add lint rule to disallow type-only imports/exports (angular#2…
Browse files Browse the repository at this point in the history
…4678)

Type-only imports and exports don't work with Closure so we can't use them.
  • Loading branch information
crisbeto authored and forsti0506 committed Apr 3, 2022
1 parent bdb379b commit 12ad974
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 12ad974

Please sign in to comment.