diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75494fa7573..079ab0bce5d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,6 +129,7 @@ jobs: 'eslint-plugin-internal', 'eslint-plugin-tslint', 'parser', + 'repo-tools', 'scope-manager', 'type-utils', 'typescript-estree', diff --git a/package.json b/package.json index fedf2374b46..bcf0aa91422 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "armano2", "Jed Fox" ], + "type": "commonjs", "license": "BSD-2-Clause", "repository": "typescript-eslint/typescript-eslint", "bugs": { @@ -121,13 +122,16 @@ "jest-resolve": "^29", "jest-util": "^29", "pretty-format": "^29", - "@swc/core-android-arm-eabi": "npm:dummypkg-a@1.0.0", - "@swc/core-android-arm64": "npm:dummypkg-a@1.0.0", - "@swc/core-freebsd-x64": "npm:dummypkg-a@1.0.0", - "@swc/core-linux-arm-gnueabihf": "npm:dummypkg-a@1.0.0", - "@swc/core-linux-arm64-gnu": "npm:dummypkg-a@1.0.0", - "@swc/core-linux-arm64-musl": "npm:dummypkg-a@1.0.0", - "@swc/core-win32-arm64-msvc": "npm:dummypkg-a@1.0.0", - "@swc/core-win32-ia32-msvc": "npm:dummypkg-a@1.0.0" + "@swc/core-android-arm-eabi": "file:./tools/dummypkg", + "@swc/core-android-arm64": "file:./tools/dummypkg", + "@swc/core-freebsd-x64": "file:./tools/dummypkg", + "@swc/core-linux-arm-gnueabihf": "file:./tools/dummypkg", + "@swc/core-linux-arm64-gnu": "file:./tools/dummypkg", + "@swc/core-linux-arm64-musl": "file:./tools/dummypkg", + "@swc/core-win32-arm64-msvc": "file:./tools/dummypkg", + "@swc/core-win32-ia32-msvc": "file:./tools/dummypkg", + "@types/eslint": "file:./tools/dummypkg", + "@types/eslint-scope": "file:./tools/dummypkg", + "@types/estree": "file:./tools/dummypkg" } } diff --git a/packages/ast-spec/tests/util/parsers/typescript-estree-import.ts b/packages/ast-spec/tests/util/parsers/typescript-estree-import.ts index c04f3d12ae2..7474f4eeecc 100644 --- a/packages/ast-spec/tests/util/parsers/typescript-estree-import.ts +++ b/packages/ast-spec/tests/util/parsers/typescript-estree-import.ts @@ -13,6 +13,4 @@ * This should be the only place in the package that we import from typescript-estree. */ -// We need to ignore this lint error regarding it being missing from the package.json, see above. -// eslint-disable-next-line import/no-extraneous-dependencies export { parse } from '@typescript-eslint/typescript-estree'; diff --git a/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts b/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts index 32ab1d41df1..72d26138256 100644 --- a/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts +++ b/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts @@ -528,7 +528,7 @@ export default createRule({ } const typeString = checker.typeToString(type); - if (/^RunTests\b/.test(typeString)) { + if (/^(TSESLint\.)?RunTests\b/.test(typeString)) { checkedObjects.add(node); for (const prop of node.properties) { @@ -558,12 +558,12 @@ export default createRule({ return; } - if (/^ValidTestCase\b/.test(typeString)) { + if (/^(TSESLint\.)?ValidTestCase\b/.test(typeString)) { checkInvalidTest(node); return; } - if (/^InvalidTestCase\b/.test(typeString)) { + if (/^(TSESLint\.)?InvalidTestCase\b/.test(typeString)) { checkInvalidTest(node); for (const testProp of node.properties) { if ( diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json index 375670356e7..ce8dba41af6 100644 --- a/packages/eslint-plugin-tslint/package.json +++ b/packages/eslint-plugin-tslint/package.json @@ -1,24 +1,26 @@ { "name": "@typescript-eslint/eslint-plugin-tslint", "version": "5.53.0", - "main": "dist/index.js", - "typings": "src/index.ts", "description": "ESLint plugin that wraps a TSLint configuration and lints the whole source using TSLint", - "keywords": [ - "eslint", - "eslintplugin", - "eslint-plugin", - "tslint" - ], - "engines": { - "node": "^14.18.0 || ^16.0.0 || >=18.0.0" - }, "files": [ "dist", "package.json", "README.md", "LICENSE" ], + "type": "commonjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js" + }, + "./package.json": { + "require": "./package.json" + } + }, + "engines": { + "node": "^14.18.0 || ^16.0.0 || >=18.0.0" + }, "repository": { "type": "git", "url": "https://github.com/typescript-eslint/typescript-eslint.git", @@ -28,6 +30,12 @@ "url": "https://github.com/typescript-eslint/typescript-eslint/issues" }, "license": "MIT", + "keywords": [ + "eslint", + "eslintplugin", + "eslint-plugin", + "tslint" + ], "scripts": { "build": "tsc -b tsconfig.build.json", "clean": "tsc -b tsconfig.build.json --clean", @@ -49,5 +57,9 @@ "devDependencies": { "@types/lodash": "*", "@typescript-eslint/parser": "5.53.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" } } diff --git a/packages/eslint-plugin-tslint/tests/tsconfig.json b/packages/eslint-plugin-tslint/tests/tsconfig.json deleted file mode 100644 index aee0ec940fc..00000000000 --- a/packages/eslint-plugin-tslint/tests/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "compilerOptions": { - "strict": true - } -} diff --git a/packages/eslint-plugin-tslint/tsconfig.build.json b/packages/eslint-plugin-tslint/tsconfig.build.json index ce8f56e7294..86650784975 100644 --- a/packages/eslint-plugin-tslint/tsconfig.build.json +++ b/packages/eslint-plugin-tslint/tsconfig.build.json @@ -1,6 +1,10 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { + // specifically disable declarations for the plugin + // see reasoning in packages/eslint-plugin/rules.d.ts + "declaration": false, + "declarationMap": false, "outDir": "./dist", "rootDir": "./src", "resolveJsonModule": true diff --git a/packages/eslint-plugin/index.d.ts b/packages/eslint-plugin/index.d.ts index 53a17f6fc33..7b4715f81f7 100644 --- a/packages/eslint-plugin/index.d.ts +++ b/packages/eslint-plugin/index.d.ts @@ -1,4 +1,9 @@ import type { TSESLint } from '@typescript-eslint/utils'; -export const rules: Record>; -export const configs: Record; +import type rules from './rules'; + +declare const cjsExport: { + configs: Record; + rules: typeof rules; +}; +export = cjsExport; diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 08112ad2934..7565816652b 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -2,15 +2,6 @@ "name": "@typescript-eslint/eslint-plugin", "version": "5.53.0", "description": "TypeScript plugin for ESLint", - "keywords": [ - "eslint", - "eslintplugin", - "eslint-plugin", - "typescript" - ], - "engines": { - "node": "^14.18.0 || ^16.0.0 || >=18.0.0" - }, "files": [ "dist", "docs", @@ -19,6 +10,23 @@ "README.md", "LICENSE" ], + "type": "commonjs", + "exports": { + ".": { + "types": "./index.d.ts", + "require": "./dist/index.js" + }, + "./package.json": { + "require": "./package.json" + }, + "./use-at-your-own-risk/rules": { + "types": "./rules.d.ts", + "require": "./dist/rules/index.js" + } + }, + "engines": { + "node": "^14.18.0 || ^16.0.0 || >=18.0.0" + }, "repository": { "type": "git", "url": "https://github.com/typescript-eslint/typescript-eslint.git", @@ -28,8 +36,12 @@ "url": "https://github.com/typescript-eslint/typescript-eslint/issues" }, "license": "MIT", - "main": "dist/index.js", - "types": "index.d.ts", + "keywords": [ + "eslint", + "eslintplugin", + "eslint-plugin", + "typescript" + ], "scripts": { "build": "tsc -b tsconfig.build.json", "check-docs": "jest tests/docs.test.ts --runTestsByPath --silent --runInBand", @@ -37,7 +49,7 @@ "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf coverage", "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", - "generate:breaking-changes": "yarn tsx tools/generate-breaking-changes.ts", + "generate:breaking-changes": "yarn tsx tools/generate-breaking-changes.mts", "generate:configs": "yarn tsx tools/generate-configs.ts", "lint": "nx lint", "test": "jest --coverage", @@ -61,9 +73,7 @@ "@types/marked": "*", "@types/natural-compare-lite": "^1.4.0", "@types/prettier": "*", - "chalk": "^5.0.1", "cross-fetch": "*", - "grapheme-splitter": "^1.0.4", "json-schema": "*", "markdown-table": "^3.0.2", "marked": "^4.0.15", diff --git a/packages/eslint-plugin/rules.d.ts b/packages/eslint-plugin/rules.d.ts new file mode 100644 index 00000000000..9a5272d205c --- /dev/null +++ b/packages/eslint-plugin/rules.d.ts @@ -0,0 +1,44 @@ +/* +We purposely don't generate types for our plugin because TL;DR: +1) there's no real reason that anyone should do a typed import of our rules, +2) it would require us to change our code so there aren't as many inferred types + +This type declaration exists as a hacky way to add a type to the export for our +internal packages that require it. + +*** Long reason *** + +When you turn on declaration files, TS requires all types to be "fully resolvable" +without changes to the code. +All of our lint rules `export default createRule(...)`, which means they all +implicitly reference the `TSESLint.Rule` type for the export. + +TS wants to transpile each rule file to this `.d.ts` file: + +```ts +import type { TSESLint } from '@typescript-eslint/utils'; +declare const _default: TSESLint.RuleModule; +export default _default; +``` + +Because we don't import `TSESLint` in most files, it means that TS would have to +insert a new import during the declaration emit to make this work. +However TS wants to avoid adding new imports to the file because a new module +could have type side-effects (like global augmentation) which could cause weird +type side-effects in the decl file that wouldn't exist in source TS file. + +So TS errors on most of our rules with the following error: +``` +The inferred type of 'default' cannot be named without a reference to +'../../../../node_modules/@typescript-eslint/utils/src/ts-eslint/Rule'. +This is likely not portable. A type annotation is necessary. ts(2742) +``` +*/ + +import type { RuleModule } from '@typescript-eslint/utils/ts-eslint'; + +export interface TypeScriptESLintRules { + [ruleName: string]: RuleModule; +} +declare const rules: TypeScriptESLintRules; +export = rules; diff --git a/packages/eslint-plugin/src/rules/prefer-ts-expect-error.ts b/packages/eslint-plugin/src/rules/prefer-ts-expect-error.ts index 55b5d2c56eb..8ef1c7ad927 100644 --- a/packages/eslint-plugin/src/rules/prefer-ts-expect-error.ts +++ b/packages/eslint-plugin/src/rules/prefer-ts-expect-error.ts @@ -1,9 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_TOKEN_TYPES } from '@typescript-eslint/utils'; -import type { - RuleFix, - RuleFixer, -} from '@typescript-eslint/utils/dist/ts-eslint'; +import type { RuleFix, RuleFixer } from '@typescript-eslint/utils/ts-eslint'; import * as util from '../util'; diff --git a/packages/eslint-plugin/src/util/astUtils.ts b/packages/eslint-plugin/src/util/astUtils.ts index 9140443390c..a4bf10251cd 100644 --- a/packages/eslint-plugin/src/util/astUtils.ts +++ b/packages/eslint-plugin/src/util/astUtils.ts @@ -4,7 +4,7 @@ import * as ts from 'typescript'; import { escapeRegExp } from './escapeRegExp'; // deeply re-export, for convenience -export * from '@typescript-eslint/utils/dist/ast-utils'; +export * from '@typescript-eslint/utils/ast-utils'; // The following is copied from `eslint`'s source code since it doesn't exist in eslint@5. // https://github.com/eslint/eslint/blob/145aec1ab9052fbca96a44d04927c595951b1536/lib/rules/utils/ast-utils.js#L1751-L1779 diff --git a/packages/eslint-plugin/src/util/collectUnusedVariables.ts b/packages/eslint-plugin/src/util/collectUnusedVariables.ts index 97b6386063d..a0ad2676a01 100644 --- a/packages/eslint-plugin/src/util/collectUnusedVariables.ts +++ b/packages/eslint-plugin/src/util/collectUnusedVariables.ts @@ -1,5 +1,4 @@ -import { ImplicitLibVariable } from '@typescript-eslint/scope-manager'; -import { Visitor } from '@typescript-eslint/scope-manager/dist/referencer/Visitor'; +import { ImplicitLibVariable, Visitor } from '@typescript-eslint/scope-manager'; import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES, diff --git a/packages/eslint-plugin/tests/RuleTester.ts b/packages/eslint-plugin/tests/RuleTester.ts index 7c46b9a12f5..efeaa707734 100644 --- a/packages/eslint-plugin/tests/RuleTester.ts +++ b/packages/eslint-plugin/tests/RuleTester.ts @@ -5,11 +5,13 @@ function getFixturesRootDir(): string { return path.join(__dirname, 'fixtures'); } -const { batchedSingleLineTests, RuleTester, noFormat } = ESLintUtils; +const { batchedSingleLineTests } = ESLintUtils; export { + RuleTester, RunTests, ValidTestCase, InvalidTestCase, -} from '@typescript-eslint/utils/dist/eslint-utils/rule-tester/RuleTester'; + noFormat, +} from '@typescript-eslint/utils/eslint-utils/rule-tester'; -export { batchedSingleLineTests, getFixturesRootDir, noFormat, RuleTester }; +export { batchedSingleLineTests, getFixturesRootDir }; diff --git a/packages/eslint-plugin/tests/configs.test.ts b/packages/eslint-plugin/tests/configs.test.ts index 4fcc7d0d5d0..07e204e1344 100644 --- a/packages/eslint-plugin/tests/configs.test.ts +++ b/packages/eslint-plugin/tests/configs.test.ts @@ -1,4 +1,4 @@ -import type { RuleRecommendation } from '@typescript-eslint/utils/src/ts-eslint'; +import type { RuleRecommendation } from '@typescript-eslint/utils/ts-eslint'; import plugin from '../src/index'; import rules from '../src/rules'; diff --git a/packages/eslint-plugin/tests/fixtures/consistent-type-exports.ts b/packages/eslint-plugin/tests/fixtures/consistent-type-exports.ts new file mode 100644 index 00000000000..0c883cbef77 --- /dev/null +++ b/packages/eslint-plugin/tests/fixtures/consistent-type-exports.ts @@ -0,0 +1,4 @@ +export type Type1 = 1; +export type Type2 = 1; +export const value1 = 2; +export const value2 = 2; diff --git a/packages/eslint-plugin/tests/fixtures/mixed-enums-decl.ts b/packages/eslint-plugin/tests/fixtures/mixed-enums-decl.ts new file mode 100644 index 00000000000..df407073367 --- /dev/null +++ b/packages/eslint-plugin/tests/fixtures/mixed-enums-decl.ts @@ -0,0 +1,4 @@ +export enum Enum { + A = 'A', + B = 'B', +} diff --git a/packages/eslint-plugin/tests/fixtures/tsconfig.json b/packages/eslint-plugin/tests/fixtures/tsconfig.json index 07d1352d839..6ae5e64730b 100644 --- a/packages/eslint-plugin/tests/fixtures/tsconfig.json +++ b/packages/eslint-plugin/tests/fixtures/tsconfig.json @@ -8,5 +8,10 @@ "lib": ["es2015", "es2017", "esnext"], "experimentalDecorators": true }, - "include": ["file.ts", "react.tsx"] + "include": [ + "file.ts", + "consistent-type-exports.ts", + "mixed-enums-decl.ts", + "react.tsx" + ] } diff --git a/packages/eslint-plugin/tests/rules/consistent-type-exports.test.ts b/packages/eslint-plugin/tests/rules/consistent-type-exports.test.ts index e5f7bfbc2d3..5ab0edf84f1 100644 --- a/packages/eslint-plugin/tests/rules/consistent-type-exports.test.ts +++ b/packages/eslint-plugin/tests/rules/consistent-type-exports.test.ts @@ -15,10 +15,12 @@ const ruleTester = new RuleTester({ ruleTester.run('consistent-type-exports', rule, { valid: [ + // unknown module should be ignored "export { Foo } from 'foo';", - "export type { AnalyzeOptions } from '@typescript-eslint/scope-manager';", - "export { BlockScope } from '@typescript-eslint/utils';", - "export type { BlockScope } from '@typescript-eslint/utils';", + + "export type { Type1 } from './consistent-type-exports';", + "export { value1 } from './consistent-type-exports';", + "export type { value1 } from './consistent-type-exports';", ` const variable = 1; class Class {} @@ -53,9 +55,8 @@ export { NonTypeNS }; ], invalid: [ { - code: "export { AnalyzeOptions } from '@typescript-eslint/scope-manager';", - output: - "export type { AnalyzeOptions } from '@typescript-eslint/scope-manager';", + code: "export { Type1 } from './consistent-type-exports';", + output: "export type { Type1 } from './consistent-type-exports';", errors: [ { messageId: 'typeOverValue', @@ -65,10 +66,10 @@ export { NonTypeNS }; ], }, { - code: "export { AnalyzeOptions, BlockScope } from '@typescript-eslint/scope-manager';", + code: "export { Type1, value1 } from './consistent-type-exports';", output: - `export type { AnalyzeOptions } from '@typescript-eslint/scope-manager';\n` + - `export { BlockScope } from '@typescript-eslint/scope-manager';`, + `export type { Type1 } from './consistent-type-exports';\n` + + `export { value1 } from './consistent-type-exports';`, errors: [ { messageId: 'singleExportIsType', @@ -79,15 +80,11 @@ export { NonTypeNS }; }, { code: ` -export { - AnalyzeOptions, - BlockScope, - CatchScope, -} from '@typescript-eslint/scope-manager'; +export { Type1, value1, value2 } from './consistent-type-exports'; `, output: ` -export type { AnalyzeOptions } from '@typescript-eslint/scope-manager'; -export { BlockScope, CatchScope } from '@typescript-eslint/scope-manager'; +export type { Type1 } from './consistent-type-exports'; +export { value1, value2 } from './consistent-type-exports'; `, errors: [ { @@ -99,16 +96,11 @@ export { BlockScope, CatchScope } from '@typescript-eslint/scope-manager'; }, { code: ` -export { - AnalyzeOptions, - BlockScope, - Definition, - CatchScope, -} from '@typescript-eslint/scope-manager'; +export { Type1, value1, Type2, value2 } from './consistent-type-exports'; `, output: ` -export type { AnalyzeOptions, Definition } from '@typescript-eslint/scope-manager'; -export { BlockScope, CatchScope } from '@typescript-eslint/scope-manager'; +export type { Type1, Type2 } from './consistent-type-exports'; +export { value1, value2 } from './consistent-type-exports'; `, errors: [ { @@ -119,9 +111,8 @@ export { BlockScope, CatchScope } from '@typescript-eslint/scope-manager'; ], }, { - code: "export { Definition as Foo } from '@typescript-eslint/scope-manager';", - output: - "export type { Definition as Foo } from '@typescript-eslint/scope-manager';", + code: "export { Type2 as Foo } from './consistent-type-exports';", + output: "export type { Type2 as Foo } from './consistent-type-exports';", errors: [ { messageId: 'typeOverValue', @@ -132,14 +123,11 @@ export { BlockScope, CatchScope } from '@typescript-eslint/scope-manager'; }, { code: ` -export { - Definition as Foo, - BlockScope, -} from '@typescript-eslint/scope-manager'; +export { Type2 as Foo, value1 } from './consistent-type-exports'; `, output: ` -export type { Definition as Foo } from '@typescript-eslint/scope-manager'; -export { BlockScope } from '@typescript-eslint/scope-manager'; +export type { Type2 as Foo } from './consistent-type-exports'; +export { value1 } from './consistent-type-exports'; `, errors: [ { @@ -152,14 +140,14 @@ export { BlockScope } from '@typescript-eslint/scope-manager'; { code: ` export { - Definition as Foo, - BlockScope as BScope, - CatchScope as CScope, -} from '@typescript-eslint/scope-manager'; + Type2 as Foo, + value1 as BScope, + value2 as CScope, +} from './consistent-type-exports'; `, output: ` -export type { Definition as Foo } from '@typescript-eslint/scope-manager'; -export { BlockScope as BScope, CatchScope as CScope } from '@typescript-eslint/scope-manager'; +export type { Type2 as Foo } from './consistent-type-exports'; +export { value1 as BScope, value2 as CScope } from './consistent-type-exports'; `, errors: [ { @@ -171,12 +159,12 @@ export { BlockScope as BScope, CatchScope as CScope } from '@typescript-eslint/s }, { code: ` -import { Definition } from '@typescript-eslint/scope-manager'; -export { Definition }; +import { Type2 } from './consistent-type-exports'; +export { Type2 }; `, output: ` -import { Definition } from '@typescript-eslint/scope-manager'; -export type { Definition }; +import { Type2 } from './consistent-type-exports'; +export type { Type2 }; `, errors: [ { @@ -188,13 +176,13 @@ export type { Definition }; }, { code: ` -import { CatchScope, Definition } from '@typescript-eslint/scope-manager'; -export { CatchScope, Definition }; +import { value2, Type2 } from './consistent-type-exports'; +export { value2, Type2 }; `, output: ` -import { CatchScope, Definition } from '@typescript-eslint/scope-manager'; -export type { Definition }; -export { CatchScope }; +import { value2, Type2 } from './consistent-type-exports'; +export type { Type2 }; +export { value2 }; `, errors: [ { @@ -367,15 +355,15 @@ export type { T, T }; { code: ` export { - AnalyzeOptions, - Definition as Foo, - type BlockScope as BScope, - CatchScope as CScope, -} from '@typescript-eslint/scope-manager'; + Type1, + Type2 as Foo, + type value1 as BScope, + value2 as CScope, +} from './consistent-type-exports'; `, output: ` -export type { AnalyzeOptions, Definition as Foo, BlockScope as BScope } from '@typescript-eslint/scope-manager'; -export { CatchScope as CScope } from '@typescript-eslint/scope-manager'; +export type { Type1, Type2 as Foo, value1 as BScope } from './consistent-type-exports'; +export { value2 as CScope } from './consistent-type-exports'; `, dependencyConstraints: { typescript: '4.5', @@ -392,19 +380,19 @@ export { CatchScope as CScope } from '@typescript-eslint/scope-manager'; { code: ` export { - AnalyzeOptions, - Definition as Foo, - type BlockScope as BScope, - CatchScope as CScope, -} from '@typescript-eslint/scope-manager'; + Type1, + Type2 as Foo, + type value1 as BScope, + value2 as CScope, +} from './consistent-type-exports'; `, output: ` export { - type AnalyzeOptions, - type Definition as Foo, - type BlockScope as BScope, - CatchScope as CScope, -} from '@typescript-eslint/scope-manager'; + type Type1, + type Type2 as Foo, + type value1 as BScope, + value2 as CScope, +} from './consistent-type-exports'; `, dependencyConstraints: { typescript: '4.5', diff --git a/packages/eslint-plugin/tests/rules/no-mixed-enums.test.ts b/packages/eslint-plugin/tests/rules/no-mixed-enums.test.ts index 3847fda0131..b3aace8cc81 100644 --- a/packages/eslint-plugin/tests/rules/no-mixed-enums.test.ts +++ b/packages/eslint-plugin/tests/rules/no-mixed-enums.test.ts @@ -189,19 +189,19 @@ enum Foo { } `, ` -import { AST_NODE_TYPES } from '@typescript-eslint/types'; +import { Enum } from './mixed-enums-decl'; -declare module '@typescript-eslint/types' { - enum AST_NODE_TYPES { +declare module './mixed-enums-decl' { + enum Enum { StringLike = 'StringLike', } } `, ` -import { TSESTree } from '@typescript-eslint/types'; +import { Enum } from "module-that-does't-exist"; -declare module '@typescript-eslint/types' { - enum TSESTree { +declare module "module-that-doesn't-exist" { + enum Enum { StringLike = 'StringLike', } } @@ -552,10 +552,10 @@ namespace Different { }, { code: ` -import { AST_NODE_TYPES } from '@typescript-eslint/types'; +import { Enum } from './mixed-enums-decl'; -declare module '@typescript-eslint/types' { - enum AST_NODE_TYPES { +declare module './mixed-enums-decl' { + enum Enum { Numeric = 0, } } diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts index 96cad00c908..325960802d3 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts @@ -1,7 +1,7 @@ import type { InvalidTestCase, TestCaseError, -} from '@typescript-eslint/utils/dist/ts-eslint'; +} from '@typescript-eslint/utils/ts-eslint'; import * as path from 'path'; import type { diff --git a/packages/eslint-plugin/tests/rules/promise-function-async.test.ts b/packages/eslint-plugin/tests/rules/promise-function-async.test.ts index 089e6ba617b..0f084d5d78f 100644 --- a/packages/eslint-plugin/tests/rules/promise-function-async.test.ts +++ b/packages/eslint-plugin/tests/rules/promise-function-async.test.ts @@ -1,7 +1,5 @@ -import { noFormat } from '@typescript-eslint/utils/src/eslint-utils'; - import rule from '../../src/rules/promise-function-async'; -import { getFixturesRootDir, RuleTester } from '../RuleTester'; +import { getFixturesRootDir, noFormat, RuleTester } from '../RuleTester'; const rootDir = getFixturesRootDir(); const messageId = 'missingAsync'; diff --git a/packages/eslint-plugin/tools/generate-breaking-changes.ts b/packages/eslint-plugin/tools/generate-breaking-changes.mts similarity index 88% rename from packages/eslint-plugin/tools/generate-breaking-changes.ts rename to packages/eslint-plugin/tools/generate-breaking-changes.mts index bb24d0ebbe1..d4ec9233e6c 100644 --- a/packages/eslint-plugin/tools/generate-breaking-changes.ts +++ b/packages/eslint-plugin/tools/generate-breaking-changes.mts @@ -1,20 +1,17 @@ +import type { TypeScriptESLintRules } from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules'; import { fetch } from 'cross-fetch'; +// markdown-table is ESM, hence this file needs to be `.mts` import { markdownTable } from 'markdown-table'; -import type RulesFile from '../src/rules'; - -interface RulesObject { - default: { - default: typeof RulesFile; - }; -} - async function main(): Promise { - const { - default: { default: rules }, - } = - // @ts-expect-error -- We don't support ESM imports of local code yet. - (await import('../dist/rules/index.js')) as RulesObject; + const rulesImport = await import('../src/rules/index.js'); + /* + weird TS resolution which adds an additional default layer in the type like: + { default: { default: Rules }} + instead of just + { default: Rules } + @ts-expect-error */ + const rules = rulesImport.default as TypeScriptESLintRules; // Annotate which rules are new since the last version async function getNewRulesAsOfMajorVersion( @@ -33,7 +30,7 @@ async function main(): Promise { // Normally we wouldn't condone using the 'eval' API... // But this is an internal-only script and it's the easiest way to convert // the JS raw text into a runtime object. 🤷 - let oldRulesObject!: { rules: typeof RulesFile }; + let oldRulesObject!: { rules: TypeScriptESLintRules }; eval('oldRulesObject = ' + oldObjectText); const oldRuleNames = new Set(Object.keys(oldRulesObject.rules)); diff --git a/packages/eslint-plugin/tools/generate-configs.ts b/packages/eslint-plugin/tools/generate-configs.ts index 7e54b6d3286..e9e1f3a7047 100644 --- a/packages/eslint-plugin/tools/generate-configs.ts +++ b/packages/eslint-plugin/tools/generate-configs.ts @@ -1,5 +1,4 @@ import type { TSESLint } from '@typescript-eslint/utils'; -import chalk from 'chalk'; import * as fs from 'fs'; import * as path from 'path'; import prettier from 'prettier'; @@ -7,6 +6,15 @@ import * as url from 'url'; import type RulesFile from '../src/rules'; +// no need for us to bring in an entire dependency for a few simple terminal colors +const chalk = { + dim: (val: string): string => `\x1B[2m${val}\x1B[22m`, + green: (val: string): string => `\x1B[32m${val}\x1B[39m`, + red: (val: string): string => `\x1B[31m${val}\x1B[39m`, + blueBright: (val: string): string => `\x1B[94m${val}\x1B[39m`, + gray: (val: string): string => `\x1B[90m${val}\x1B[39m`, +}; + interface RulesObject { default: { default: typeof RulesFile; diff --git a/packages/eslint-plugin/tsconfig.build.json b/packages/eslint-plugin/tsconfig.build.json index af60c77e84f..49f58646073 100644 --- a/packages/eslint-plugin/tsconfig.build.json +++ b/packages/eslint-plugin/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "../../tsconfig.base.json", "compilerOptions": { // specifically disable declarations for the plugin + // see reasoning in packages/eslint-plugin/rules.d.ts "declaration": false, "declarationMap": false, "outDir": "./dist", diff --git a/packages/eslint-plugin/tsconfig.json b/packages/eslint-plugin/tsconfig.json index 7801773b539..fa20841493f 100644 --- a/packages/eslint-plugin/tsconfig.json +++ b/packages/eslint-plugin/tsconfig.json @@ -4,7 +4,7 @@ "composite": false, "rootDir": "." }, - "include": ["src", "typings", "tests", "tools", "index.d.ts"], + "include": ["src", "typings", "tests", "tools", "index.d.ts", "rules.d.ts"], "references": [ { "path": "../utils/tsconfig.build.json" }, { "path": "../parser/tsconfig.build.json" }, diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index cf85fd44ac2..346b72a7b26 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -143,7 +143,7 @@ declare module 'eslint/lib/rules/indent' { declare module 'eslint/lib/rules/key-spacing' { import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; - import type { RuleFunction } from '@typescript-eslint/utils/dist/ts-eslint'; + import type { RuleFunction } from '@typescript-eslint/utils/ts-eslint'; type Options = [ { @@ -195,7 +195,7 @@ declare module 'eslint/lib/rules/key-spacing' { declare module 'eslint/lib/rules/keyword-spacing' { import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; - import type { RuleFunction } from '@typescript-eslint/utils/dist/ts-eslint'; + import type { RuleFunction } from '@typescript-eslint/utils/ts-eslint'; type Options = [ { diff --git a/packages/parser/package.json b/packages/parser/package.json index 9adbd33835d..2b12f18893a 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -2,14 +2,22 @@ "name": "@typescript-eslint/parser", "version": "5.53.0", "description": "An ESLint custom parser which leverages TypeScript ESTree", - "main": "dist/index.js", - "types": "dist/index.d.ts", "files": [ "dist", "_ts4.2", "README.md", "LICENSE" ], + "type": "commonjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js" + }, + "./package.json": { + "require": "./package.json" + } + }, "engines": { "node": "^14.18.0 || ^16.0.0 || >=18.0.0" }, diff --git a/packages/parser/tests/lib/parser.ts b/packages/parser/tests/lib/parser.ts index e554c4bfde7..3098152b095 100644 --- a/packages/parser/tests/lib/parser.ts +++ b/packages/parser/tests/lib/parser.ts @@ -1,6 +1,6 @@ -import * as scopeManager from '@typescript-eslint/scope-manager/dist/analyze'; +import * as scopeManager from '@typescript-eslint/scope-manager'; import type { ParserOptions } from '@typescript-eslint/types'; -import * as typescriptESTree from '@typescript-eslint/typescript-estree/dist/parser'; +import * as typescriptESTree from '@typescript-eslint/typescript-estree'; import { parse, parseForESLint } from '../../src/parser'; diff --git a/packages/parser/tests/tools/ts-error-serializer.ts b/packages/parser/tests/tools/ts-error-serializer.ts index 6d24367a526..5267898b526 100644 --- a/packages/parser/tests/tools/ts-error-serializer.ts +++ b/packages/parser/tests/tools/ts-error-serializer.ts @@ -1,4 +1,4 @@ -import { TSError } from '@typescript-eslint/typescript-estree/dist/node-utils'; +import { TSError } from '@typescript-eslint/typescript-estree'; import type { Plugin } from 'pretty-format'; export const serializer: Plugin = { diff --git a/packages/repo-tools/jest.config.js b/packages/repo-tools/jest.config.js index 72e29aa600b..7d2ec5530a1 100644 --- a/packages/repo-tools/jest.config.js +++ b/packages/repo-tools/jest.config.js @@ -5,4 +5,5 @@ module.exports = { ...require('../../jest.config.base.js'), coveragePathIgnorePatterns: ['src/index.ts$', 'src/configs/.*.ts$'], + passWithNoTests: true, }; diff --git a/packages/scope-manager/package.json b/packages/scope-manager/package.json index 4c81b1f0f93..98efa0e55ab 100644 --- a/packages/scope-manager/package.json +++ b/packages/scope-manager/package.json @@ -2,20 +2,29 @@ "name": "@typescript-eslint/scope-manager", "version": "5.53.0", "description": "TypeScript scope analyser for ESLint", - "keywords": [ - "eslint", - "typescript", - "estree" - ], - "engines": { - "node": "^14.18.0 || ^16.0.0 || >=18.0.0" - }, "files": [ "dist", "package.json", "README.md", "LICENSE" ], + "type": "commonjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js" + }, + "./package.json": { + "require": "./package.json" + }, + "./use-at-your-own-risk/analyze": { + "types": "./dist/analyze.d.ts", + "require": "./dist/analyze.js" + } + }, + "engines": { + "node": "^14.18.0 || ^16.0.0 || >=18.0.0" + }, "repository": { "type": "git", "url": "https://github.com/typescript-eslint/typescript-eslint.git", @@ -25,8 +34,11 @@ "url": "https://github.com/typescript-eslint/typescript-eslint/issues" }, "license": "MIT", - "main": "dist/index.js", - "types": "dist/index.d.ts", + "keywords": [ + "eslint", + "typescript", + "estree" + ], "scripts": { "build": "nx build", "clean": "nx clean", diff --git a/packages/type-utils/package.json b/packages/type-utils/package.json index c2deaba17bd..67848dd4b9a 100644 --- a/packages/type-utils/package.json +++ b/packages/type-utils/package.json @@ -2,14 +2,6 @@ "name": "@typescript-eslint/type-utils", "version": "5.53.0", "description": "Type utilities for working with TypeScript + ESLint together", - "keywords": [ - "eslint", - "typescript", - "estree" - ], - "engines": { - "node": "^14.18.0 || ^16.0.0 || >=18.0.0" - }, "files": [ "dist", "_ts4.2", @@ -17,6 +9,19 @@ "README.md", "LICENSE" ], + "type": "commonjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js" + }, + "./package.json": { + "require": "./package.json" + } + }, + "engines": { + "node": "^14.18.0 || ^16.0.0 || >=18.0.0" + }, "repository": { "type": "git", "url": "https://github.com/typescript-eslint/typescript-eslint.git", @@ -26,8 +31,11 @@ "url": "https://github.com/typescript-eslint/typescript-eslint/issues" }, "license": "MIT", - "main": "dist/index.js", - "types": "dist/index.d.ts", + "keywords": [ + "eslint", + "typescript", + "estree" + ], "scripts": { "build": "tsc -b tsconfig.build.json", "postbuild": "downlevel-dts dist _ts4.2/dist --to=4.2", diff --git a/packages/types/package.json b/packages/types/package.json index 3c30aa1dfbf..a2d8c2c7d5a 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -2,14 +2,6 @@ "name": "@typescript-eslint/types", "version": "5.53.0", "description": "Types for the TypeScript-ESTree AST spec", - "keywords": [ - "eslint", - "typescript", - "estree" - ], - "engines": { - "node": "^14.18.0 || ^16.0.0 || >=18.0.0" - }, "files": [ "dist", "_ts4.2", @@ -17,6 +9,19 @@ "README.md", "LICENSE" ], + "type": "commonjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js" + }, + "./package.json": { + "require": "./package.json" + } + }, + "engines": { + "node": "^14.18.0 || ^16.0.0 || >=18.0.0" + }, "repository": { "type": "git", "url": "https://github.com/typescript-eslint/typescript-eslint.git", @@ -26,8 +31,11 @@ "url": "https://github.com/typescript-eslint/typescript-eslint/issues" }, "license": "MIT", - "main": "dist/index.js", - "types": "dist/index.d.ts", + "keywords": [ + "eslint", + "typescript", + "estree" + ], "scripts": { "prebuild": "tsx ./tools/copy-ast-spec.ts", "build": "tsc -b tsconfig.build.json", @@ -66,6 +74,9 @@ } } }, + "devDependencies": { + "typescript": "*" + }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" @@ -76,8 +87,5 @@ "_ts4.2/*" ] } - }, - "devDependencies": { - "typescript": "*" } } diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 58647494896..54678d6f631 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -2,14 +2,34 @@ "name": "@typescript-eslint/typescript-estree", "version": "5.53.0", "description": "A parser that converts TypeScript source code into an ESTree compatible form", - "main": "dist/index.js", - "types": "dist/index.d.ts", "files": [ "dist", "_ts4.2", "README.md", "LICENSE" ], + "type": "commonjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js" + }, + "./package.json": { + "require": "./package.json" + }, + "./use-at-your-own-risk/ast-converter": { + "types": "./dist/ast-converter.d.ts", + "require": "./dist/ast-converter.js" + }, + "./use-at-your-own-risk/parseSettings": { + "types": "./dist/parseSettings/index.d.ts", + "require": "./dist/parseSettings/index.js" + }, + "./use-at-your-own-risk/getScriptKind": { + "types": "./dist/create-program/getScriptKind.d.ts", + "require": "./dist/create-program/getScriptKind.js" + } + }, "engines": { "node": "^14.18.0 || ^16.0.0 || >=18.0.0" }, diff --git a/packages/typescript-estree/src/index.ts b/packages/typescript-estree/src/index.ts index f11336e9694..afe277f547c 100644 --- a/packages/typescript-estree/src/index.ts +++ b/packages/typescript-estree/src/index.ts @@ -18,6 +18,7 @@ export { createProgramFromConfigFile as createProgram } from './create-program/u export * from './create-program/getScriptKind'; export { typescriptVersionIsAtLeast } from './version-check'; export * from './getModifiers'; +export { TSError } from './node-utils'; export * from './clear-caches'; // note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder diff --git a/packages/utils/package.json b/packages/utils/package.json index 3bb96c3757d..26d17d42629 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -2,14 +2,6 @@ "name": "@typescript-eslint/utils", "version": "5.53.0", "description": "Utilities for working with TypeScript + ESLint together", - "keywords": [ - "eslint", - "typescript", - "estree" - ], - "engines": { - "node": "^14.18.0 || ^16.0.0 || >=18.0.0" - }, "files": [ "dist", "_ts4.2", @@ -17,6 +9,39 @@ "README.md", "LICENSE" ], + "type": "commonjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js" + }, + "./ast-utils": { + "types": "./dist/ast-utils/index.d.ts", + "require": "./dist/ast-utils/index.js" + }, + "./eslint-utils": { + "types": "./dist/eslint-utils/index.d.ts", + "require": "./dist/eslint-utils/index.js" + }, + "./eslint-utils/rule-tester": { + "types": "./dist/eslint-utils/rule-tester/RuleTester.d.ts", + "require": "./dist/eslint-utils/rule-tester/RuleTester.js" + }, + "./json-schema": { + "types": "./dist/json-schema.d.ts", + "require": "./dist/json-schema.js" + }, + "./ts-eslint": { + "types": "./dist/ts-eslint/index.d.ts", + "require": "./dist/ts-eslint/index.js" + }, + "./package.json": { + "require": "./package.json" + } + }, + "engines": { + "node": "^14.18.0 || ^16.0.0 || >=18.0.0" + }, "repository": { "type": "git", "url": "https://github.com/typescript-eslint/typescript-eslint.git", @@ -26,8 +51,11 @@ "url": "https://github.com/typescript-eslint/typescript-eslint/issues" }, "license": "MIT", - "main": "dist/index.js", - "types": "dist/index.d.ts", + "keywords": [ + "eslint", + "typescript", + "estree" + ], "scripts": { "build": "tsc -b tsconfig.build.json", "postbuild": "downlevel-dts dist _ts4.2/dist --to=4.2", diff --git a/packages/utils/src/eslint-utils/rule-tester/RuleTester.ts b/packages/utils/src/eslint-utils/rule-tester/RuleTester.ts index 7350de3a975..84e521f325a 100644 --- a/packages/utils/src/eslint-utils/rule-tester/RuleTester.ts +++ b/packages/utils/src/eslint-utils/rule-tester/RuleTester.ts @@ -1,4 +1,4 @@ -import type * as TSESLintParserType from '@typescript-eslint/parser'; +import type * as TSESTreeType from '@typescript-eslint/typescript-estree'; import assert from 'assert'; import { version as eslintVersion } from 'eslint/package.json'; import * as path from 'path'; @@ -112,7 +112,7 @@ class RuleTester extends BaseRuleTester.RuleTester { try { // instead of creating a hard dependency, just use a soft require // a bit weird, but if they're using this tooling, it'll be installed - const parser = require(TS_ESLINT_PARSER) as typeof TSESLintParserType; + const parser = require(TS_ESLINT_PARSER) as typeof TSESTreeType; parser.clearCaches(); } catch { // ignored on purpose diff --git a/packages/visitor-keys/package.json b/packages/visitor-keys/package.json index 00695140c3d..d41b1a0fd46 100644 --- a/packages/visitor-keys/package.json +++ b/packages/visitor-keys/package.json @@ -2,14 +2,6 @@ "name": "@typescript-eslint/visitor-keys", "version": "5.53.0", "description": "Visitor keys used to help traverse the TypeScript-ESTree AST", - "keywords": [ - "eslint", - "typescript", - "estree" - ], - "engines": { - "node": "^14.18.0 || ^16.0.0 || >=18.0.0" - }, "files": [ "dist", "_ts4.2", @@ -17,6 +9,23 @@ "README.md", "LICENSE" ], + "type": "commonjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js" + }, + "./package.json": { + "require": "./package.json" + }, + "./use-at-your-own-risk/visitor-keys": { + "types": "./dist/visitor-keys.d.ts", + "require": "./dist/visitor-keys.js" + } + }, + "engines": { + "node": "^14.18.0 || ^16.0.0 || >=18.0.0" + }, "repository": { "type": "git", "url": "https://github.com/typescript-eslint/typescript-eslint.git", @@ -26,8 +35,11 @@ "url": "https://github.com/typescript-eslint/typescript-eslint/issues" }, "license": "MIT", - "main": "dist/index.js", - "types": "dist/index.d.ts", + "keywords": [ + "eslint", + "typescript", + "estree" + ], "scripts": { "build": "tsc -b tsconfig.build.json", "postbuild": "downlevel-dts dist _ts4.2/dist --to=4.2", diff --git a/packages/website-eslint/package.json b/packages/website-eslint/package.json index d9a3784dbda..9678f8bf706 100644 --- a/packages/website-eslint/package.json +++ b/packages/website-eslint/package.json @@ -3,14 +3,19 @@ "version": "5.53.0", "private": true, "description": "ESLint which works in browsers.", - "engines": { - "node": "^14.18.0 || ^16.0.0 || >=18.0.0" - }, - "types": "types/index.d.ts", - "main": "dist/index.js", "files": [ "dist" ], + "type": "commonjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "require": "./dist/index.js" + } + }, + "engines": { + "node": "^14.18.0 || ^16.0.0 || >=18.0.0" + }, "scripts": { "build": "rollup --config=rollup.config.js", "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", @@ -32,7 +37,7 @@ "@typescript-eslint/typescript-estree": "5.53.0", "@typescript-eslint/visitor-keys": "5.53.0", "eslint": "*", - "magic-string": "^0.25.9", + "magic-string": "0.25.9", "rollup": "^2.75.4", "rollup-plugin-terser": "^7.0.2", "semver": "^7.3.7" diff --git a/packages/website-eslint/rollup.config.js b/packages/website-eslint/rollup.config.js index 5fde0fd0569..db727e0578d 100644 --- a/packages/website-eslint/rollup.config.js +++ b/packages/website-eslint/rollup.config.js @@ -112,6 +112,7 @@ module.exports = { }), resolve({ browser: true, + exportConditions: ['require'], preferBuiltins: false, }), commonjs(), diff --git a/packages/website-eslint/src/linter/linter.js b/packages/website-eslint/src/linter/linter.js index 60051b675a7..9264674487a 100644 --- a/packages/website-eslint/src/linter/linter.js +++ b/packages/website-eslint/src/linter/linter.js @@ -1,9 +1,13 @@ +/* +NOTE - this file intentionally uses deep `/use-at-your-own-risk` imports into our packages. +This is so that rollup can properly tree-shake and only include the necessary code. +This saves us having to mock unnecessary things and reduces our bundle size. +*/ // @ts-check import 'vs/language/typescript/tsWorker'; -// @ts-expect-error -- we don't do types for the plugins -import rules from '@typescript-eslint/eslint-plugin/dist/rules'; +import rules from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules'; import { Linter } from 'eslint'; export function createLinter() { @@ -14,7 +18,7 @@ export function createLinter() { return linter; } -export { analyze } from '@typescript-eslint/scope-manager/dist/analyze'; -export { visitorKeys } from '@typescript-eslint/visitor-keys/dist/visitor-keys'; -export { astConverter } from '@typescript-eslint/typescript-estree/dist/ast-converter'; -export { getScriptKind } from '@typescript-eslint/typescript-estree/dist/create-program/getScriptKind'; +export { analyze } from '@typescript-eslint/scope-manager/use-at-your-own-risk/analyze'; +export { visitorKeys } from '@typescript-eslint/visitor-keys/use-at-your-own-risk/visitor-keys'; +export { astConverter } from '@typescript-eslint/typescript-estree/use-at-your-own-risk/ast-converter'; +export { getScriptKind } from '@typescript-eslint/typescript-estree/use-at-your-own-risk/getScriptKind'; diff --git a/packages/website-eslint/types/index.d.ts b/packages/website-eslint/types/index.d.ts deleted file mode 100644 index 2b2d4d6a0de..00000000000 --- a/packages/website-eslint/types/index.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { analyze } from '@typescript-eslint/scope-manager/dist/analyze'; -import type { astConverter } from '@typescript-eslint/typescript-estree/dist/ast-converter'; -import type { getScriptKind } from '@typescript-eslint/typescript-estree/dist/create-program/getScriptKind'; -import type { TSESLint } from '@typescript-eslint/utils'; - -export interface LintUtils { - createLinter: () => TSESLint.Linter; - analyze: typeof analyze; - visitorKeys: TSESLint.SourceCode.VisitorKeys; - astConverter: typeof astConverter; - getScriptKind: typeof getScriptKind; -} diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index d5b9e06335e..38300beb6c0 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -1,4 +1,4 @@ -import * as eslintPlugin from '@typescript-eslint/eslint-plugin'; +import pluginRules from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules'; import * as tseslintParser from '@typescript-eslint/parser'; import * as fs from 'fs'; import type { JSONSchema7 } from 'json-schema'; @@ -40,7 +40,7 @@ export const generatedRuleDocs: Plugin = () => { return; } - const rule = eslintPlugin.rules[file.stem]; + const rule = pluginRules[file.stem]; const meta = rule?.meta; if (!meta?.docs) { return; diff --git a/packages/website/rulesMeta.ts b/packages/website/rulesMeta.ts index 8aa5f317469..e29058983e4 100644 --- a/packages/website/rulesMeta.ts +++ b/packages/website/rulesMeta.ts @@ -1,15 +1,13 @@ -import * as eslintPlugin from '@typescript-eslint/eslint-plugin'; +import rules from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules'; -export const rulesMeta = Object.entries(eslintPlugin.rules).map( - ([name, content]) => ({ - name, - type: content.meta.type, - docs: content.meta.docs, - fixable: content.meta.fixable, - hasSuggestions: content.meta.hasSuggestions, - deprecated: content.meta.deprecated, - replacedBy: content.meta.replacedBy, - }), -); +export const rulesMeta = Object.entries(rules).map(([name, content]) => ({ + name, + type: content.meta.type, + docs: content.meta.docs, + fixable: content.meta.fixable, + hasSuggestions: content.meta.hasSuggestions, + deprecated: content.meta.deprecated, + replacedBy: content.meta.replacedBy, +})); export type RulesMeta = typeof rulesMeta; diff --git a/packages/website/src/components/editor/config.ts b/packages/website/src/components/editor/config.ts index 2428a550269..aee01fb11f0 100644 --- a/packages/website/src/components/editor/config.ts +++ b/packages/website/src/components/editor/config.ts @@ -1,4 +1,4 @@ -import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema'; +import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; import type Monaco from 'monaco-editor'; import { getTypescriptOptions } from '../config/utils'; diff --git a/packages/website/src/components/editor/loadSandbox.ts b/packages/website/src/components/editor/loadSandbox.ts index c92c806e4c1..db722666a72 100644 --- a/packages/website/src/components/editor/loadSandbox.ts +++ b/packages/website/src/components/editor/loadSandbox.ts @@ -1,9 +1,9 @@ -import type { LintUtils } from '@typescript-eslint/website-eslint'; import type MonacoType from 'monaco-editor'; import type * as TSType from 'typescript'; import type * as SandboxFactory from '../../vendor/sandbox'; import type * as TsWorker from '../../vendor/tsWorker'; +import type { LintUtils } from '../linter/WebLinter'; type Monaco = typeof MonacoType; type TS = typeof TSType; diff --git a/packages/website/src/components/linter/CompilerHost.ts b/packages/website/src/components/linter/CompilerHost.ts index addbff4de35..22fd9fa83c6 100644 --- a/packages/website/src/components/linter/CompilerHost.ts +++ b/packages/website/src/components/linter/CompilerHost.ts @@ -1,6 +1,7 @@ -import type { LintUtils } from '@typescript-eslint/website-eslint'; import type { CompilerHost, SourceFile, System } from 'typescript'; +import type { LintUtils } from './WebLinter'; + /** * Creates an in-memory CompilerHost -which is essentially an extra wrapper to System * which works with TypeScript objects - returns both a compiler host, and a way to add new SourceFile diff --git a/packages/website/src/components/linter/WebLinter.ts b/packages/website/src/components/linter/WebLinter.ts index 3ffd4da2c09..eb7c18e450c 100644 --- a/packages/website/src/components/linter/WebLinter.ts +++ b/packages/website/src/components/linter/WebLinter.ts @@ -1,8 +1,10 @@ import { createVirtualCompilerHost } from '@site/src/components/linter/CompilerHost'; import { parseSettings } from '@site/src/components/linter/config'; +import type { analyze } from '@typescript-eslint/scope-manager'; import type { ParserOptions } from '@typescript-eslint/types'; +import type { astConverter } from '@typescript-eslint/typescript-estree/use-at-your-own-risk/ast-converter'; +import type { getScriptKind } from '@typescript-eslint/typescript-estree/use-at-your-own-risk/getScriptKind'; import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; -import type { LintUtils } from '@typescript-eslint/website-eslint'; import type { CompilerHost, CompilerOptions, @@ -12,6 +14,14 @@ import type { const PARSER_NAME = '@typescript-eslint/parser'; +export interface LintUtils { + createLinter: () => TSESLint.Linter; + analyze: typeof analyze; + visitorKeys: TSESLint.SourceCode.VisitorKeys; + astConverter: typeof astConverter; + getScriptKind: typeof getScriptKind; +} + export class WebLinter { private readonly host: CompilerHost; diff --git a/packages/website/src/components/linter/config.ts b/packages/website/src/components/linter/config.ts index 0c821575bec..2360a3106b5 100644 --- a/packages/website/src/components/linter/config.ts +++ b/packages/website/src/components/linter/config.ts @@ -1,4 +1,4 @@ -import type { ParseSettings } from '@typescript-eslint/typescript-estree/dist/parseSettings'; +import type { ParseSettings } from '@typescript-eslint/typescript-estree/use-at-your-own-risk/parseSettings'; export const parseSettings: ParseSettings = { code: '', diff --git a/packages/website/tests/index.spec.ts b/packages/website/tests/index.spec.ts index 77d6c73cda2..81b7f0c42d9 100644 --- a/packages/website/tests/index.spec.ts +++ b/packages/website/tests/index.spec.ts @@ -10,9 +10,16 @@ test.describe('Website', () => { test('should have no errors', async ({ page }) => { const errorMessages: string[] = []; page.on('console', msg => { - if (['error', 'warning'].includes(msg.type())) { - errorMessages.push(`[${msg.type()}] ${msg.text()}`); + const type = msg.type(); + if (!['error', 'warning'].includes(type)) { + return; } + const text = msg.text(); + // this log is fine because the ReactDOM usage is controlled by docusaurus, not us + if (text.includes('ReactDOM.render is no longer supported in React 18')) { + return; + } + errorMessages.push(`[${type}] ${text}`); }); await page.goto('/'); expect(errorMessages).toStrictEqual([]); diff --git a/patches/eslint+8.34.0.patch b/patches/eslint+8.34.0.patch new file mode 100644 index 00000000000..d9302432437 --- /dev/null +++ b/patches/eslint+8.34.0.patch @@ -0,0 +1,15 @@ +diff --git a/node_modules/eslint/lib/rules/indent.js b/node_modules/eslint/lib/rules/indent.js +index cda0203..66714b4 100644 +--- a/node_modules/eslint/lib/rules/indent.js ++++ b/node_modules/eslint/lib/rules/indent.js +@@ -12,7 +12,9 @@ + // Requirements + //------------------------------------------------------------------------------ + +-const { OrderedMap } = require("js-sdsl"); ++// make this a deep import so that rollup doesn't attempt to bundle the downleveled ESM build ++// https://github.com/js-sdsl/js-sdsl/issues/158 ++const { default: OrderedMap } = require("js-sdsl/dist/cjs/container/TreeContainer/OrderedMap"); + + const astUtils = require("./utils/ast-utils"); + diff --git a/patches/ts-api-utils+0.0.21.patch b/patches/ts-api-utils+0.0.21.patch new file mode 100644 index 00000000000..e7ed2ef0bdf --- /dev/null +++ b/patches/ts-api-utils+0.0.21.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/ts-api-utils/package.json b/node_modules/ts-api-utils/package.json +index 41ee37c..e4279d1 100644 +--- a/node_modules/ts-api-utils/package.json ++++ b/node_modules/ts-api-utils/package.json +@@ -8,7 +8,7 @@ + }, + "license": "MIT", + "author": "Josh Goldberg ", +- "type": "module", ++ "type": "commonjs", + "exports": { + ".": { + "types": "./lib/index.d.ts", diff --git a/tools/dummypkg/README.md b/tools/dummypkg/README.md new file mode 100644 index 00000000000..a1e34930477 --- /dev/null +++ b/tools/dummypkg/README.md @@ -0,0 +1,3 @@ +# dummy-pkg + +This exists as a way for us to shim-out npm packages that we don't want to install in our repo. diff --git a/tools/dummypkg/index.d.ts b/tools/dummypkg/index.d.ts new file mode 100644 index 00000000000..cb0ff5c3b54 --- /dev/null +++ b/tools/dummypkg/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tools/dummypkg/index.js b/tools/dummypkg/index.js new file mode 100644 index 00000000000..5a0e9a5b821 --- /dev/null +++ b/tools/dummypkg/index.js @@ -0,0 +1 @@ +exports.value = 'a'; diff --git a/tools/dummypkg/package.json b/tools/dummypkg/package.json new file mode 100644 index 00000000000..4c5cdcf8737 --- /dev/null +++ b/tools/dummypkg/package.json @@ -0,0 +1,6 @@ +{ + "name": "dummypkg", + "version": "1.0.0", + "main": "./index.js", + "types": "./index.d.ts" +} diff --git a/tsconfig.base.json b/tsconfig.base.json index 4116456c219..fd7ed6a809f 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -6,8 +6,8 @@ "declaration": true, "declarationMap": true, "esModuleInterop": true, - "module": "commonjs", - "moduleResolution": "node", + "module": "Node16", + "moduleResolution": "node16", "noImplicitReturns": true, "pretty": true, "skipLibCheck": true, diff --git a/yarn.lock b/yarn.lock index 7810f852d15..54d2b8cdeab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3185,10 +3185,11 @@ "@svgr/plugin-jsx" "^6.2.1" "@svgr/plugin-svgo" "^6.2.0" -"@swc/core-android-arm-eabi@1.3.4", "@swc/core-android-arm-eabi@npm:dummypkg-a@1.0.0", "@swc/core-android-arm64@1.3.4", "@swc/core-android-arm64@npm:dummypkg-a@1.0.0", "@swc/core-freebsd-x64@1.3.4", "@swc/core-freebsd-x64@npm:dummypkg-a@1.0.0", "@swc/core-linux-arm-gnueabihf@1.3.4", "@swc/core-linux-arm-gnueabihf@npm:dummypkg-a@1.0.0", "@swc/core-linux-arm64-gnu@1.3.4", "@swc/core-linux-arm64-gnu@npm:dummypkg-a@1.0.0", "@swc/core-linux-arm64-musl@1.3.4", "@swc/core-linux-arm64-musl@npm:dummypkg-a@1.0.0", "@swc/core-win32-arm64-msvc@1.3.4", "@swc/core-win32-arm64-msvc@npm:dummypkg-a@1.0.0", "@swc/core-win32-ia32-msvc@1.3.4", "@swc/core-win32-ia32-msvc@npm:dummypkg-a@1.0.0": +"@swc/core-android-arm-eabi@1.3.4", "@swc/core-android-arm-eabi@file:./tools/dummypkg": + version "1.0.0" + +"@swc/core-android-arm64@1.3.4", "@swc/core-android-arm64@file:./tools/dummypkg": version "1.0.0" - resolved "https://registry.yarnpkg.com/dummypkg-a/-/dummypkg-a-1.0.0.tgz#02868251461af84d70603446ef5908b72c5c8435" - integrity sha512-V9qLfUzVlmSW/ayzlchss1XjAqWXqHmJtzGwnfg/jsnloIUyLKR5a0Djfdgj/Jv3yoNAljIUaelTVjptxtTyGA== "@swc/core-darwin-arm64@1.3.4": version "1.3.4" @@ -3200,6 +3201,18 @@ resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.4.tgz#4742a7f83de9f6ba50801e9f6500b538856853ea" integrity sha512-A6KMZsUJ3j5TVxAizbv+UEjCNvMgWBm9jw4R3biaw8kbgu3XUWHdkiheXO+c2kjjjgwr1jhkHcLgRjffwpLYFA== +"@swc/core-freebsd-x64@1.3.4", "@swc/core-freebsd-x64@file:./tools/dummypkg": + version "1.0.0" + +"@swc/core-linux-arm-gnueabihf@1.3.4", "@swc/core-linux-arm-gnueabihf@file:./tools/dummypkg": + version "1.0.0" + +"@swc/core-linux-arm64-gnu@1.3.4", "@swc/core-linux-arm64-gnu@file:./tools/dummypkg": + version "1.0.0" + +"@swc/core-linux-arm64-musl@1.3.4", "@swc/core-linux-arm64-musl@file:./tools/dummypkg": + version "1.0.0" + "@swc/core-linux-x64-gnu@1.3.4": version "1.3.4" resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.4.tgz#1cc63f9a86074cac7454796ccbe3836ac7f6451b" @@ -3210,6 +3223,12 @@ resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.4.tgz#f65abb7e149ad3f20ca98c933331aa98c190cd9f" integrity sha512-stVnU7KXQxSbh67UiIVxZsgjkRSXApPTEU3CYnwsdH7G+ynfO1WocSatzjIKpJfhcY2Nss8/33yDaOKZXVhbIA== +"@swc/core-win32-arm64-msvc@1.3.4", "@swc/core-win32-arm64-msvc@file:./tools/dummypkg": + version "1.0.0" + +"@swc/core-win32-ia32-msvc@1.3.4", "@swc/core-win32-ia32-msvc@file:./tools/dummypkg": + version "1.0.0" + "@swc/core-win32-x64-msvc@1.3.4": version "1.3.4" resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.4.tgz#7bf6cd6f5c3197d7d807b273d12dd666e23b238e" @@ -3359,41 +3378,19 @@ dependencies: "@types/ms" "*" -"@types/eslint-scope@^3.7.3": - version "3.7.3" - resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.3.tgz#125b88504b61e3c8bc6f870882003253005c3224" - integrity sha512-PB3ldyrcnAicT35TWPs5IcwKD8S333HMaa2VVv4+wdvebJkjWuW/xESoB8IwRcog8HYVYamb1g/R31Qv5Bx03g== - dependencies: - "@types/eslint" "*" - "@types/estree" "*" +"@types/eslint-scope@^3.7.3", "@types/eslint-scope@file:./tools/dummypkg": + version "1.0.0" "@types/eslint-visitor-keys@*", "@types/eslint-visitor-keys@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== -"@types/eslint@*": - version "7.28.2" - resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.28.2.tgz#0ff2947cdd305897c52d5372294e8c76f351db68" - integrity sha512-KubbADPkfoU75KgKeKLsFHXnU4ipH7wYg0TRT33NK3N3yiu7jlFAAoygIWBV+KbuHx/G+AvuGX6DllnK35gfJA== - dependencies: - "@types/estree" "*" - "@types/json-schema" "*" - -"@types/estree@*", "@types/estree@^1.0.0": +"@types/eslint@file:./tools/dummypkg": version "1.0.0" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.0.tgz#5fb2e536c1ae9bf35366eed879e827fa59ca41c2" - integrity sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ== - -"@types/estree@0.0.39": - version "0.0.39" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" - integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== -"@types/estree@^0.0.51": - version "0.0.51" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40" - integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ== +"@types/estree@*", "@types/estree@0.0.39", "@types/estree@^0.0.51", "@types/estree@^1.0.0", "@types/estree@file:./tools/dummypkg": + version "1.0.0" "@types/express-serve-static-core@*", "@types/express-serve-static-core@^4.17.18": version "4.17.28" @@ -4801,11 +4798,6 @@ chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2: ansi-styles "^4.1.0" supports-color "^7.1.0" -chalk@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.0.1.tgz#ca57d71e82bb534a296df63bbacc4a1c22b2a4b6" - integrity sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w== - char-regex@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/char-regex/-/char-regex-1.0.2.tgz#d744358226217f981ed58f479b1d6bcc29545dcf" @@ -9695,7 +9687,7 @@ lzstring.ts@^2.0.2: dependencies: tslib "^1.10.0" -magic-string@^0.25.0, magic-string@^0.25.7, magic-string@^0.25.9: +magic-string@0.25.9, magic-string@^0.25.0, magic-string@^0.25.7: version "0.25.9" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c" integrity sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==