From f64e12aa3571726e2911337b33e096e31889f422 Mon Sep 17 00:00:00 2001 From: Edoardo Luppi Date: Thu, 6 Nov 2025 11:59:09 +0100 Subject: [PATCH] fix: use type-only imports whenever possible --- eslint.config.mjs | 2 ++ src/plugins/nx.ts | 2 +- src/types.ts | 7 ++++--- src/utils/resolve-module-name.ts | 2 +- src/utils/resolve-path-update-node.ts | 4 ++-- src/utils/ts-helpers.ts | 5 +++-- src/visitor.ts | 4 ++-- test/tests/transformer/general.test.ts | 2 +- test/tests/transformer/specific.test.ts | 4 ++-- test/utils/helpers.ts | 2 +- 10 files changed, 19 insertions(+), 15 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index b0b69497..33a174ed 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -13,6 +13,8 @@ export default [ rules: { "@typescript-eslint/no-empty-object-type": ["error", { allowInterfaces: "with-single-extends" }], "@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }], + "@typescript-eslint/no-import-type-side-effects": "error", + "@typescript-eslint/consistent-type-imports": ["error", { fixStyle: "inline-type-imports" }], "no-empty": ["error", { allowEmptyCatch: true }], "prefer-const": ["error", { destructuring: "all" }], }, diff --git a/src/plugins/nx.ts b/src/plugins/nx.ts index 02b23be8..44772265 100644 --- a/src/plugins/nx.ts +++ b/src/plugins/nx.ts @@ -1,7 +1,7 @@ // See nx-transformer-plugin.ts // https://github.com/nrwl/nx/blob/229f71ef1758ee625869aaa6fa6355dc3284fa5b/packages/js/src/utils/typescript/types.ts#L19-L32 // https://github.com/nrwl/nx/blob/master/packages/js/src/utils/typescript/load-ts-transformers.ts -import ts from "typescript"; +import type ts from "typescript"; import transformer from "../transformer.ts"; diff --git a/src/types.ts b/src/types.ts index 10480dbb..2ac1a938 100755 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,7 @@ -import { Minimatch } from "minimatch"; -import { type PluginConfig } from "ts-patch"; -import ts, { type CompilerOptions, type EmitHost, type Pattern, type SourceFile } from "typescript"; +import type { Minimatch } from "minimatch"; +import type { PluginConfig } from "ts-patch"; +import type ts from "typescript"; +import type { CompilerOptions, EmitHost, Pattern, SourceFile } from "typescript"; /* ****************************************************************************************************************** */ // region: TS Types diff --git a/src/utils/resolve-module-name.ts b/src/utils/resolve-module-name.ts index 1bfc0edd..fb989dca 100755 --- a/src/utils/resolve-module-name.ts +++ b/src/utils/resolve-module-name.ts @@ -2,7 +2,7 @@ import * as path from "node:path"; import { removeFileExtension, removeSuffix, type ResolvedModuleFull, type SourceFile } from "typescript"; -import { type VisitorContext } from "../types.ts"; +import type { VisitorContext } from "../types.ts"; import { isBaseDir, isURL, maybeAddRelativeLocalPrefix } from "./general-utils.ts"; import { getRelativePath } from "./get-relative-path.ts"; import { getOutputDirForSourceFile } from "./ts-helpers.ts"; diff --git a/src/utils/resolve-path-update-node.ts b/src/utils/resolve-path-update-node.ts index 74814923..e6a1dfe6 100755 --- a/src/utils/resolve-path-update-node.ts +++ b/src/utils/resolve-path-update-node.ts @@ -1,6 +1,6 @@ -import ts from "typescript"; +import type ts from "typescript"; -import { type VisitorContext } from "../types.ts"; +import type { VisitorContext } from "../types.ts"; import { isURL, maybeAddRelativeLocalPrefix } from "./general-utils.ts"; import { resolveModuleName } from "./resolve-module-name.ts"; import { isModulePathsMatch } from "./ts-helpers.ts"; diff --git a/src/utils/ts-helpers.ts b/src/utils/ts-helpers.ts index 0431270f..a1d42514 100755 --- a/src/utils/ts-helpers.ts +++ b/src/utils/ts-helpers.ts @@ -1,9 +1,10 @@ import path from "node:path"; import type { REGISTER_INSTANCE } from "ts-node"; -import ts, { type GetCanonicalFileName, type SourceFile } from "typescript"; +import type ts from "typescript"; +import type { GetCanonicalFileName, SourceFile } from "typescript"; -import { type VisitorContext } from "../types.ts"; +import type { VisitorContext } from "../types.ts"; /* ****************************************************************************************************************** */ // region: TS Helpers diff --git a/src/visitor.ts b/src/visitor.ts index 75b85563..bd4ee4b1 100755 --- a/src/visitor.ts +++ b/src/visitor.ts @@ -1,6 +1,6 @@ -import ts from "typescript"; +import type ts from "typescript"; -import { type VisitorContext } from "./types.ts"; +import type { VisitorContext } from "./types.ts"; import { elideImportOrExportDeclaration, resolvePathAndUpdateNode } from "./utils/index.ts"; const isAsyncImport = ({ tsInstance }: VisitorContext, node: ts.Node): node is ts.CallExpression => diff --git a/test/tests/transformer/general.test.ts b/test/tests/transformer/general.test.ts index d5cda027..52a9f59e 100755 --- a/test/tests/transformer/general.test.ts +++ b/test/tests/transformer/general.test.ts @@ -2,7 +2,7 @@ import * as path from "node:path"; import { before, describe, test } from "node:test"; -import { projectsPaths, ts, tsModules } from "../../config.ts"; +import { projectsPaths, type ts, tsModules } from "../../config.ts"; import { createTsProgram, getEmitResultFromProgram, type EmittedFiles } from "../../utils/index.ts"; /* ****************************************************************************************************************** * diff --git a/test/tests/transformer/specific.test.ts b/test/tests/transformer/specific.test.ts index ff2128a6..0a2e0d8f 100755 --- a/test/tests/transformer/specific.test.ts +++ b/test/tests/transformer/specific.test.ts @@ -3,9 +3,9 @@ import assert from "node:assert"; import * as path from "node:path"; import { before, describe, test } from "node:test"; -import TS from "typescript"; +import type TS from "typescript"; -import { type TsTransformPathsConfig } from "typescript-transform-paths"; +import type { TsTransformPathsConfig } from "typescript-transform-paths"; import { projectsPaths, ts, tsModules } from "../../config.ts"; import { diff --git a/test/utils/helpers.ts b/test/utils/helpers.ts index 49054322..c610c17b 100755 --- a/test/utils/helpers.ts +++ b/test/utils/helpers.ts @@ -1,6 +1,6 @@ import fs from "node:fs"; -import ts from "typescript"; +import type ts from "typescript"; import { default as tstpTransform, type TsTransformPathsConfig } from "typescript-transform-paths"; import * as config from "../config.ts";