From 7a87a39f1f1901207f16812af0d7408a1d37d103 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Wed, 4 Sep 2024 19:35:44 +0800 Subject: [PATCH 1/3] fix: avoid side effects from `@typescript-eslint/typescript-estree` --- .changeset/twenty-jars-fix.md | 5 +++++ package.json | 1 - src/utils/parse.ts | 18 ++++++++++++++---- yarn.lock | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 .changeset/twenty-jars-fix.md diff --git a/.changeset/twenty-jars-fix.md b/.changeset/twenty-jars-fix.md new file mode 100644 index 000000000..b3a02b8f5 --- /dev/null +++ b/.changeset/twenty-jars-fix.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-import-x": patch +--- + +Fix https://github.com/nuxt/eslint/issues/494 by avoid importing from `@typescript-eslint/typescript-estree`. diff --git a/package.json b/package.json index 5c0333bf0..e31c3f021 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "eslint": "^8.57.0 || ^9.0.0" }, "dependencies": { - "@typescript-eslint/typescript-estree": "^8.1.0", "@typescript-eslint/utils": "^8.1.0", "debug": "^4.3.4", "doctrine": "^3.0.0", diff --git a/src/utils/parse.ts b/src/utils/parse.ts index afa08ae47..2ada09ab1 100644 --- a/src/utils/parse.ts +++ b/src/utils/parse.ts @@ -1,6 +1,6 @@ import path from 'node:path' -import { withoutProjectParserOptions } from '@typescript-eslint/typescript-estree' +// import { withoutProjectParserOptions } from '@typescript-eslint/typescript-estree' import type { TSESLint, TSESTree } from '@typescript-eslint/utils' import debug from 'debug' @@ -13,6 +13,18 @@ import type { import { moduleRequire } from './module-require' +function withoutProjectParserOptions( + opts: TSESLint.ParserOptions, +): Exclude< + TSESLint.ParserOptions, + 'EXPERIMENTAL_useProjectService' | 'project' | 'projectService' +> { + // eslint-disable-next-line @typescript-eslint/no-unused-vars -- The variables are meant to be omitted + const { EXPERIMENTAL_useProjectService, project, projectService, ...rest } = + opts + return rest +} + const log = debug('eslint-plugin-import-x:parse') function keysFromParser( @@ -90,9 +102,7 @@ export function parse( // "project" or "projects" in parserOptions. Removing these options means the parser will // only parse one file in isolate mode, which is much, much faster. // https://github.com/import-js/eslint-plugin-import/issues/1408#issuecomment-509298962 - parserOptions = withoutProjectParserOptions( - parserOptions, - ) as TSESLint.ParserOptions + parserOptions = withoutProjectParserOptions(parserOptions) // require the parser relative to the main module (i.e., ESLint) const parser = diff --git a/yarn.lock b/yarn.lock index f9f51603b..1da928b0f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2421,7 +2421,7 @@ semver "^7.3.7" tsutils "^3.21.0" -"@typescript-eslint/typescript-estree@8.1.0", "@typescript-eslint/typescript-estree@^8.1.0": +"@typescript-eslint/typescript-estree@8.1.0": version "8.1.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-8.1.0.tgz#c44e5667683c0bb5caa43192e27de6a994f4e4c4" integrity sha512-NTHhmufocEkMiAord/g++gWKb0Fr34e9AExBRdqgWdVBaKoei2dIyYKD9Q0jBnvfbEA5zaf8plUFMUH6kQ0vGg== From 5835a36e155c8de293a5a4969699df795b9adab3 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Wed, 4 Sep 2024 19:36:13 +0800 Subject: [PATCH 2/3] add comments --- src/utils/parse.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/parse.ts b/src/utils/parse.ts index 2ada09ab1..f1ce213a5 100644 --- a/src/utils/parse.ts +++ b/src/utils/parse.ts @@ -13,6 +13,7 @@ import type { import { moduleRequire } from './module-require' +// https://github.com/nuxt/eslint/issues/494 function withoutProjectParserOptions( opts: TSESLint.ParserOptions, ): Exclude< From aefd0fd4a06f790b2d04d49adafa0d222690666c Mon Sep 17 00:00:00 2001 From: SukkaW Date: Wed, 4 Sep 2024 19:42:32 +0800 Subject: [PATCH 3/3] chore: fix lint --- src/rules/no-rename-default.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/no-rename-default.ts b/src/rules/no-rename-default.ts index 084898541..e52ef03db 100644 --- a/src/rules/no-rename-default.ts +++ b/src/rules/no-rename-default.ts @@ -6,7 +6,7 @@ import path from 'node:path' -import type { TSESTree } from '@typescript-eslint/typescript-estree' +import type { TSESTree } from '@typescript-eslint/utils' import { createRule, ExportMap } from '../utils' import type { ModuleOptions } from '../utils'