Open kachkaev opened 1 week ago
In the long term most popular community plugins and configs will be converted to FlatConfig so will be imported natively using ESM.
My assumption was indeed that Knip didn't need extra work here. But I've already started in #806 to actually load eslint.config.*
files and start resolving dependencies. Was surprised to see this is necessary though :(
When I try that version of Knip in this CSB I'm getting this:
ERROR: Error loading /project/workspace/eslint.config.mjs
Reason: Cannot read config file: /project/workspace/node_modules/.pnpm/eslint-config-next@15.0.1_eslint@8.57.0_typescript@5.4.5/node_modules/eslint-config-next/index.js
Error: Failed to patch ESLint because the calling module was not recognized.
This happens because... it's complicated. But here's the gist.
The reason is an ESLint config/plugin loads some rushstack stuff (which throws the error):
Work-around in Knip:
This fix works fine so far. Apparently we're having a new scenario here in which the rushstack alias isn't active and I don't fancy jumping into this rabbit hole again.
Maybe the fix is easy, idk. This also just made me reconsider the work in #806 for now.
Ah yeah rushstack. Itβs causing problems in other tools, at least in ESLint config expector:
Thanks for sharing that! Will follow those issues for sure.
Prerequisites
Reproduction url
https://codesandbox.io/p/devbox/yjgd5f
Reproduction access
Description of the issue
With a recent end-of-life for ESLint v8, more people are migrating to FlatConfig. New
eslint.config.js
file is pretty standard, so most imports can be tracked without any special tricks. However, if this file refers to a config that is still relying on an old config system, Knip fails to detect that a project dependency is used.Here is an example for
eslint-config-next
:.eslintrc.json
before conversionKnip is smart enough to know that
next/core-web-vitals
comes fromeslint-config-next
, so does not mark this dependency as unused.eslint.config.js
after conversionβ
Knip does not know about
compat.extends("next/core-web-vitals")
, so markseslint-config-next
as unused inpackage.json
.Note that in the real world scenario the call may also look like this:
In the long term most popular community plugins and configs will be converted to FlatConfig so will be imported natively using ESM. But it would be great if Knip could handle
compat.extends
in the meantime to help folks with migration.