This post goes over how to migrate ESLint from 8 to 9:
Config
Migrate the config:
npx @eslint/migrate-config .eslintrc.json
You may see the following:
Migrating .eslintrc.json
Wrote new config to ./eslint.config.mjs
You will need to install the following packages to use the new config:
- globals
- @eslint/js
- @eslint/eslintrc
You can install them using the following command:
npm install globals @eslint/js @eslint/eslintrc -D
Install the dependencies:
npm install globals @eslint/js @eslint/eslintrc -D
Delete the old config:
rm .eslintrc.json
Ignore
Install ESLint compatibility utilities:
npm install @eslint/compat -D
Update eslint.config.mjs
:
import { includeIgnoreFile } from '@eslint/compat';
// ...
const gitignorePath = path.resolve(__dirname, '.gitignore');
// ...
export default [
includeIgnoreFile(gitignorePath),
// ...
];
To ignore a directory like dist
:
// ...
export default [
{
ignores: ['dist/'],
},
// ...
];
Script
Run the script to ensure lint is working:
npx eslint .
Update package.json
scripts (if applicable).