diff --git a/tools/tslint-rules/noTypeOnlyImportExportRule.ts b/tools/tslint-rules/noTypeOnlyImportExportRule.ts new file mode 100644 index 000000000000..503a368060b3 --- /dev/null +++ b/tools/tslint-rules/noTypeOnlyImportExportRule.ts @@ -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); +} diff --git a/tslint.json b/tslint.json index b8ab009b44db..1ad9106d5d67 100644 --- a/tslint.json +++ b/tslint.json @@ -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,