forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add lint rule to disallow type-only imports/exports (angular#2…
…4678) Type-only imports and exports don't work with Closure so we can't use them.
- Loading branch information
1 parent
bdb379b
commit 12ad974
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters