https://codesandbox.io/p/devbox/yjgd5f
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 conversion{
"extends": "next/core-web-vitals"
}
Knip is smart enough to know that next/core-web-vitals
comes from eslint-config-next
, so does not mark this dependency as unused.
eslint.config.js
after conversionnpx @eslint/migrate-config .eslintrc.json
β
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
export default [...compat.extends("next/core-web-vitals")];
Knip does not know about compat.extends("next/core-web-vitals")
, so marks eslint-config-next
as unused in package.json
.
Note that in the real world scenario the call may also look like this:
...flatCompat.extends('next/core-web-vitals', 'next/typescript')
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.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too