eslint-config-exzeo with eslint v9
Eslint v9 requires a new config file known as a flat config.
The eslint documentation has a detailed migration guide available for any in-depth issues with migrating, as well as full breaking changes list.
Migrating existing configs
For services with simple configs and limited ignores, you can delete all .eslintrc.json and .eslintignore files,and replace it with the following and have a working config with all default ignores:
import exzeoBaseConfig from 'eslint-config-exzeo/base';
import exzeoMochaConfig from 'eslint-config-exzeo/mocha';
export default [
exzeoBaseConfig,
exzeoMochaConfig
];
New configs, customization and updating migrated configs
You can get started quickly with a new config by importing the "base" config into an eslint.config.js
file. Importing the base config would look like this:
import exzeoBase from 'eslint-config-exzeo/base';
export default [
exzeoBase
];
Ignoring files
.eslintignore
files are deprecated in version 9. Add globally ignored files to the config using a glob. By default, the config ignores node_modules
and **/documentation
.
import exzeoBase from 'eslint-config-exzeo/base';
export default [
exzeoBase,
{ ignores: ['**/dist'] }
];
Linting tests
This package exports mocha specific configs for linting test files. You can specify which files get linted with which config by using a files array and a glob. By default, the mocha config will lint all tests with a file extension of *.test.js
.
import exzeoBaseConfig from 'eslint-config-exzeo/base';
import exzeoMochaConfig from 'eslint-config-exzeo/mocha';
export default [
exzeoBaseConfig,
{
...exzeoMochaConfig,
files: [...exzeoMochaConfig.files, 'test/**/*']
},
];
Extending the config
In most cases, you want to extend the config while leaving it mostly intact, by either adding additional ignores, disabling certain rules per config, or adding additional files. Use the spread operator to extend the config.
import exzeoBaseConfig from 'eslint-config-exzeo/base';
import exzeoMochaConfig from 'eslint-config-exzeo/mocha';
export default [
{
...exzeoBaseConfig,
rules: {
...exzeoBaseConfig.rules,
'thisrulesucks': 'off'
},
ignores: [...exzeoBaseConfig.ignores, 'scripts/**/*']
},
{
...exzeoMochaConfig,
files: [...exzeoMochaConfig.files, 'stress-test/**/*']
}
];
Overriding rules
You can customize rules by adding them to a rules object. Adding rules in a seperate object overrides the rules for all configs above them.
import exzeoBaseConfig from 'eslint-config-exzeo/base';
import exzeoMochaConfig from 'eslint-config-exzeo/mocha';
export default [
exzeoBaseConfig,
exzeoMochaConfig,
{
rules: {
'thisrulesucks': 'off'
}
}
];
Typescript Linting
There are preset typescript and typescript mocha configs exported from this package. You will need to install the typescript-eslint
package to use the configs. More information about how to set this up is available in the docs for this package. The 'extends' keyword is valid for this config, so you can easily extend using that instead of the spread operator. An example config for ts would look something like this:
import tseslint from 'typescript-eslint'
import exzeoTsConfig from 'eslint-config-exzeo/ts';
import exzeoTsMochaConfig from 'eslint-config-exzeo/ts-mocha';
export default tseslint.config(
...exzeoTsConfig,
{
files: ['test/**/*'],
extends: [exzeoTsMochaConfig],
rules: {
'@typescript-eslint/no-unused-vars': 'off'
},
},
{ ignores: ['dist/**/*', '**/node_modules'] }
)
Helpful commands for debugging configs
Debug logs for a given file:
npx eslint --debug file.js
Inspect config, includes a gui for examining how your config is built and what different rules/files/and ignores are applied to what:
npx eslint --inspect-config
Print out the config that is being used for a given file:
npx eslint --print-config file.js
Further debugging information available in eslint's documentation