From 3008c6c4a27797cae310b50b5822a66bf643f2bb Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Sun, 27 Mar 2022 12:11:08 +0200 Subject: [PATCH] build: add lint rule to disallow type-only imports/exports Type-only imports and exports don't work with Closure so we can't use them. --- .../noTypeOnlyImportExportRule.ts | 19 +++++++++++++++++++ tslint.json | 1 + 2 files changed, 20 insertions(+) create mode 100644 tools/tslint-rules/noTypeOnlyImportExportRule.ts 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,