diff --git a/eslint.config.js b/eslint.config.js index c8507bd3..e8d4b6ba 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -56,6 +56,16 @@ export default tseslint.config( }, }, rules: { + "no-restricted-syntax": [ + "error", + // Forbid default import from "typescript" + { + message: 'Default import from "typescript" is not allowed.', + selector: + 'ImportDeclaration[source.value="typescript"] > ImportDefaultSpecifier', + }, + ], + // These off-by-default rules work well for this repo and we like them on. "logical-assignment-operators": [ "error", diff --git a/src/comments.test.ts b/src/comments.test.ts index f15e589b..47c6d6f9 100644 --- a/src/comments.test.ts +++ b/src/comments.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it, vitest } from "vitest"; import { forEachComment } from "./comments"; diff --git a/src/comments.ts b/src/comments.ts index cfb7c45d..f5dc7080 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { forEachToken } from "./tokens"; diff --git a/src/compilerOptions.test.ts b/src/compilerOptions.test.ts index 130a7529..ee91dae9 100644 --- a/src/compilerOptions.test.ts +++ b/src/compilerOptions.test.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it } from "vitest"; import { diff --git a/src/compilerOptions.ts b/src/compilerOptions.ts index f1ff1276..12996f94 100644 --- a/src/compilerOptions.ts +++ b/src/compilerOptions.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; /* eslint-disable jsdoc/informative-docs */ /** diff --git a/src/flags.ts b/src/flags.ts index 02461a0e..6a79a732 100644 --- a/src/flags.ts +++ b/src/flags.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; /** * Test if the given node has the given `ModifierFlags` set. diff --git a/src/modifiers.ts b/src/modifiers.ts index 933bfbca..d09483af 100644 --- a/src/modifiers.ts +++ b/src/modifiers.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; /** * Test if the given iterable includes a modifier of any of the given kinds. diff --git a/src/nodes/access.test.ts b/src/nodes/access.test.ts index 67c8929a..4522a26a 100644 --- a/src/nodes/access.test.ts +++ b/src/nodes/access.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it } from "vitest"; import { createNode } from "../test/utils"; diff --git a/src/nodes/access.ts b/src/nodes/access.ts index 92cba41f..eb9ca885 100644 --- a/src/nodes/access.ts +++ b/src/nodes/access.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { isAssignmentKind } from "../syntax"; diff --git a/src/nodes/typeGuards/compound.test.ts b/src/nodes/typeGuards/compound.test.ts index a4602651..08a43775 100644 --- a/src/nodes/typeGuards/compound.test.ts +++ b/src/nodes/typeGuards/compound.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it } from "vitest"; import { createNode } from "../../test/utils"; diff --git a/src/nodes/typeGuards/compound.ts b/src/nodes/typeGuards/compound.ts index d6dd979c..228034ae 100644 --- a/src/nodes/typeGuards/compound.ts +++ b/src/nodes/typeGuards/compound.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { isSuperExpression } from "./single"; import { diff --git a/src/nodes/typeGuards/single.test.ts b/src/nodes/typeGuards/single.test.ts index 02dc2157..7d1367f1 100644 --- a/src/nodes/typeGuards/single.test.ts +++ b/src/nodes/typeGuards/single.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it } from "vitest"; import { createNode } from "../../test/utils"; diff --git a/src/nodes/typeGuards/single.ts b/src/nodes/typeGuards/single.ts index 1e489511..b28502cd 100644 --- a/src/nodes/typeGuards/single.ts +++ b/src/nodes/typeGuards/single.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; /** * A node that represents the any keyword. diff --git a/src/nodes/typeGuards/union.test.ts b/src/nodes/typeGuards/union.test.ts index 52f4acb7..b345cfd0 100644 --- a/src/nodes/typeGuards/union.test.ts +++ b/src/nodes/typeGuards/union.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it } from "vitest"; import { createNode } from "../../test/utils"; diff --git a/src/nodes/typeGuards/union.ts b/src/nodes/typeGuards/union.ts index 9547bfad..e10656e2 100644 --- a/src/nodes/typeGuards/union.ts +++ b/src/nodes/typeGuards/union.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { isTsVersionAtLeast } from "../../utils"; import { diff --git a/src/nodes/utilities.ts b/src/nodes/utilities.ts index 2f111886..bdbd07f1 100644 --- a/src/nodes/utilities.ts +++ b/src/nodes/utilities.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { isTransientSymbolLinksFlagSet } from "../flags"; import { diff --git a/src/scopes.ts b/src/scopes.ts index a6662216..17ae6fdf 100644 --- a/src/scopes.ts +++ b/src/scopes.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; /** * Is the node a scope boundary, specifically due to it being a function. diff --git a/src/syntax.test.ts b/src/syntax.test.ts index ab482ec2..741f11b4 100644 --- a/src/syntax.test.ts +++ b/src/syntax.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it } from "vitest"; import { diff --git a/src/syntax.ts b/src/syntax.ts index 5626245d..c5ac1a48 100644 --- a/src/syntax.ts +++ b/src/syntax.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; /** * Test of the kind given is for assignment. diff --git a/src/test/utils.ts b/src/test/utils.ts index c173ccc8..5ee1cbc9 100644 --- a/src/test/utils.ts +++ b/src/test/utils.ts @@ -1,5 +1,5 @@ import * as tsvfs from "@typescript/vfs"; -import ts from "typescript"; +import * as ts from "typescript"; interface SourceFileAndTypeChecker { sourceFile: ts.SourceFile; diff --git a/src/tokens.ts b/src/tokens.ts index c14bfe0d..b4f0ea29 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -3,7 +3,7 @@ // Original license MIT: // https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; /** * Callback type used for {@link forEachToken}. diff --git a/src/types/getters.test.ts b/src/types/getters.test.ts index b095e2b9..ec1f409b 100644 --- a/src/types/getters.test.ts +++ b/src/types/getters.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it } from "vitest"; import { createSourceFileAndTypeChecker } from "../test/utils"; diff --git a/src/types/getters.ts b/src/types/getters.ts index 1384ef2c..fae87842 100644 --- a/src/types/getters.ts +++ b/src/types/getters.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { isNamedDeclarationWithName } from "../nodes/typeGuards"; import { diff --git a/src/types/typeGuards/compound.test.ts b/src/types/typeGuards/compound.test.ts index 021b434e..d7e5f585 100644 --- a/src/types/typeGuards/compound.test.ts +++ b/src/types/typeGuards/compound.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it } from "vitest"; import { createSourceFileAndTypeChecker } from "../../test/utils"; diff --git a/src/types/typeGuards/compound.ts b/src/types/typeGuards/compound.ts index 11f3a61e..aef122e3 100644 --- a/src/types/typeGuards/compound.ts +++ b/src/types/typeGuards/compound.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { type IntrinsicType, isIntrinsicType } from "./intrinsic"; import { isTupleType, isTypeReference } from "./objects"; diff --git a/src/types/typeGuards/intrinsic.test.ts b/src/types/typeGuards/intrinsic.test.ts index feed4d95..6dc0b3e7 100644 --- a/src/types/typeGuards/intrinsic.test.ts +++ b/src/types/typeGuards/intrinsic.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it } from "vitest"; import { createSourceFileAndTypeChecker } from "../../test/utils"; diff --git a/src/types/typeGuards/intrinsic.ts b/src/types/typeGuards/intrinsic.ts index 523df0e9..caf014f1 100644 --- a/src/types/typeGuards/intrinsic.ts +++ b/src/types/typeGuards/intrinsic.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { isTypeFlagSet } from "../../flags"; diff --git a/src/types/typeGuards/literal.test.ts b/src/types/typeGuards/literal.test.ts index 7787cd04..179dad3c 100644 --- a/src/types/typeGuards/literal.test.ts +++ b/src/types/typeGuards/literal.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it } from "vitest"; import { createSourceFileAndTypeChecker } from "../../test/utils"; diff --git a/src/types/typeGuards/literal.ts b/src/types/typeGuards/literal.ts index 93069344..f8a67bcf 100644 --- a/src/types/typeGuards/literal.ts +++ b/src/types/typeGuards/literal.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { isTypeFlagSet } from "../../flags"; import { type FreshableIntrinsicType } from "./compound"; diff --git a/src/types/typeGuards/objects.ts b/src/types/typeGuards/objects.ts index 78600f76..b840ac5f 100644 --- a/src/types/typeGuards/objects.ts +++ b/src/types/typeGuards/objects.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { isObjectFlagSet } from "../../flags"; import { isObjectType } from "./single"; diff --git a/src/types/typeGuards/single.test.ts b/src/types/typeGuards/single.test.ts index dfca717f..1524ab76 100644 --- a/src/types/typeGuards/single.test.ts +++ b/src/types/typeGuards/single.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, expectTypeOf, it } from "vitest"; import { createSourceFileAndTypeChecker } from "../../test/utils"; diff --git a/src/types/typeGuards/single.ts b/src/types/typeGuards/single.ts index a714177b..384ed1b9 100644 --- a/src/types/typeGuards/single.ts +++ b/src/types/typeGuards/single.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { isTypeFlagSet } from "../../flags"; diff --git a/src/types/utilities.test.ts b/src/types/utilities.test.ts index 6f7c69e4..30720d19 100644 --- a/src/types/utilities.test.ts +++ b/src/types/utilities.test.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, it } from "vitest"; import { createSourceFileAndTypeChecker } from "../test/utils"; diff --git a/src/types/utilities.ts b/src/types/utilities.ts index 3bdfdca4..edc51d9e 100644 --- a/src/types/utilities.ts +++ b/src/types/utilities.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { isModifierFlagSet, diff --git a/src/usage/Scope.ts b/src/usage/Scope.ts index e0d30c3c..679e9989 100644 --- a/src/usage/Scope.ts +++ b/src/usage/Scope.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import type { EnumScope, NamespaceScope } from "./scopes"; diff --git a/src/usage/UsageWalker.ts b/src/usage/UsageWalker.ts index 8fad9b38..917299f0 100644 --- a/src/usage/UsageWalker.ts +++ b/src/usage/UsageWalker.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { includesModifier } from "../modifiers"; import { DeclarationDomain } from "./declarations"; diff --git a/src/usage/collectVariableUsage.test.ts b/src/usage/collectVariableUsage.test.ts index 80706501..c5222367 100644 --- a/src/usage/collectVariableUsage.test.ts +++ b/src/usage/collectVariableUsage.test.ts @@ -1,5 +1,5 @@ import { query } from "@phenomnomnominal/tsquery"; -import ts from "typescript"; +import * as ts from "typescript"; import { describe, expect, test } from "vitest"; import { createSourceFile } from "../test/utils"; diff --git a/src/usage/collectVariableUsage.ts b/src/usage/collectVariableUsage.ts index de095b0d..0fe60580 100644 --- a/src/usage/collectVariableUsage.ts +++ b/src/usage/collectVariableUsage.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { UsageInfo } from "./usage"; import { UsageWalker } from "./UsageWalker"; diff --git a/src/usage/declarations.ts b/src/usage/declarations.ts index 5c9c9b48..f70637f0 100644 --- a/src/usage/declarations.ts +++ b/src/usage/declarations.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { identifierToKeywordKind } from "./utils"; diff --git a/src/usage/getPropertyName.ts b/src/usage/getPropertyName.ts index 70e6100f..ce87c159 100644 --- a/src/usage/getPropertyName.ts +++ b/src/usage/getPropertyName.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { isNumericOrStringLikeLiteral } from "../nodes/typeGuards/compound"; diff --git a/src/usage/getUsageDomain.ts b/src/usage/getUsageDomain.ts index 35c1f09b..a35574cb 100644 --- a/src/usage/getUsageDomain.ts +++ b/src/usage/getUsageDomain.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { identifierToKeywordKind } from "./utils"; diff --git a/src/usage/scopes.ts b/src/usage/scopes.ts index 96fd528f..5d2ed908 100644 --- a/src/usage/scopes.ts +++ b/src/usage/scopes.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { DeclarationDomain, diff --git a/src/usage/usage.ts b/src/usage/usage.ts index 4e8b7005..216dc3e9 100644 --- a/src/usage/usage.ts +++ b/src/usage/usage.ts @@ -1,7 +1,7 @@ // Code largely based on https://github.com/ajafff/tsutils // Original license: https://github.com/ajafff/tsutils/blob/26b195358ec36d59f00333115aa3ffd9611ca78b/LICENSE -import ts from "typescript"; +import * as ts from "typescript"; import { DeclarationDomain, DeclarationInfo } from "./declarations"; import { UsageDomain } from "./getUsageDomain"; diff --git a/src/usage/utils.ts b/src/usage/utils.ts index 7092538a..998e77c4 100644 --- a/src/usage/utils.ts +++ b/src/usage/utils.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; /** * Supports TypeScript<5 versions that don't have identifierToKeywordKind. diff --git a/src/utils.ts b/src/utils.ts index ade5996b..4bfcd311 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as ts from "typescript"; const [tsMajor, tsMinor] = ts.versionMajorMinor .split(".")