import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.38k stars 1.54k forks source link

Error parsing git format in package.json (pnpm) #3020

Open nobiit opened 1 week ago

nobiit commented 1 week ago

If package.json has a package installed from git, it will include sha in the path, and this seems to cause an error with the import/namespace rule

Error

admin@NobiPC ➜ materio git:(develop) ✗ eslint src/db/server/server.ts

Oops! Something went wrong! :(

ESLint: 8.57.0

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string, Uint8Array, or URL without null bytes. Received '/Users/admin/<user>/<repo>/node_modules/.pnpm/<repo>@git+https+++git@github.com+<user>+<repo>.git\x00#6affeaa31c0e...
Occurred while linting /Users/admin/nobidev/materio/src/db/server/server.ts:1
Rule: "import/namespace"
    at Object.statSync (node:fs:1657:10)
    at ExportMap.for (/Users/admin/nobidev/materio/node_modules/.pnpm/eslint-plugin-import@2.29.1_@typescript-eslint+parser@7.13.0_eslint@8.57.0_typescript@5.4.5___pi7blvkmllwoqjthpibydoafqm/node_modules/eslint-plugin-import/lib/ExportMap.js:802:69)
    at ExportMap.get (/Users/admin/nobidev/materio/node_modules/.pnpm/eslint-plugin-import@2.29.1_@typescript-eslint+parser@7.13.0_eslint@8.57.0_typescript@5.4.5___pi7blvkmllwoqjthpibydoafqm/node_modules/eslint-plugin-import/lib/ExportMap.js:801:465)
    at processBodyStatement (/Users/admin/nobidev/materio/node_modules/.pnpm/eslint-plugin-import@2.29.1_@typescript-eslint+parser@7.13.0_eslint@8.57.0_typescript@5.4.5___pi7blvkmllwoqjthpibydoafqm/node_modules/eslint-plugin-import/lib/rules/namespace.js:11:40)
    at /Users/admin/nobidev/materio/node_modules/.pnpm/eslint-plugin-import@2.29.1_@typescript-eslint+parser@7.13.0_eslint@8.57.0_typescript@5.4.5___pi7blvkmllwoqjthpibydoafqm/node_modules/eslint-plugin-import/lib/rules/namespace.js:84:40
    at Array.forEach (<anonymous>)
    at Program (/Users/admin/nobidev/materio/node_modules/.pnpm/eslint-plugin-import@2.29.1_@typescript-eslint+parser@7.13.0_eslint@8.57.0_typescript@5.4.5___pi7blvkmllwoqjthpibydoafqm/node_modules/eslint-plugin-import/lib/rules/namespace.js:84:18)
    at ruleErrorHandler (/Users/admin/nobidev/materio/node_modules/.pnpm/eslint@8.57.0/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /Users/admin/nobidev/materio/node_modules/.pnpm/eslint@8.57.0/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)

Other information:

eslint-plugin-import version v2.29.1

{
  "dependencies": {
    "<repo>": "<user>/<repo>#<sha>",
  }
}
import {a,b,c} from '<user>/<repo>';
pnpm install
eslint src/main.ts
nobiit commented 1 week ago

It seems to be related to this paragraph.

https://github.com/import-js/eslint-plugin-import/blob/main/src/exportMap/builder.js#L52

I think I need to cut off the fragment in the path?

nobiit commented 1 week ago

I see a '\x00' character in the path variable. Does it make sense?

nobiit commented 1 week ago

I had success with this little patch, it works for me :D

https://github.com/nobiit/eslint-plugin-import/commit/27e886257db3a448a4fb46d16b50b258d156ff45

It seems the problem comes from eslint-import-resolver-typescript . I hope if someone sees this problem confirm it (to avoid blame on my part)


P/s: eslint-import-resolver-typescript: v3.6.1

ljharb commented 6 days ago

It is very very strange to see a null character in any string, especially here.

Can you confirm that eslint-import-resolver-typescript is producing that character? If so, please file an issue there.