I’m sure this has been asked before, but I am finding it hard to locate a good solution.
Basically, I want to do things differently for different file types, or folders, or whatever. Before ESLint 9, this was accomplished with overrides
, and now with version 9 we are meant to have multiple objects in an array-like structure. So far, so good.
Where I am having trouble is in replicating the convenient functionality of the extends
keyword to this new format. In a .eslintrc.js
file, I was able to include multiple configs, with an array of strings, such as:
export default {
extends: ['airbnb', 'prettier'],
overrides: {
{
files: ['*.jsx'],
extends: ['plugin:react/jsx-runtime', 'plugin:react-hooks/recommended'],
},
},
};
In ESLint 9, the configs are no longer represented as simple strings, they are required & merged with the project’s configuration. This makes sense, and I generally agree, but I am running into trouble where multiple imported configs conflict with each other. Because there is no (easy/efficient) way to do deep merging in JavaScript, the recommendation for using multiple imported configs is to merge them together. However, if the 2 configs have different rules, this becomes problematic. For example, going back to the previous example, the easiest way to include the 2 react configs would be something like:
import prettier from 'eslint-config-prettier';
import airbnb from 'eslint-config-airbnb';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
export default {
prettier,
airbnb,
{
...react.configs.flat['jsx-runtime'],
...reactHooks.configs.recommended,
files: ['*.jsx'],
},
};
However, these 2 configs both have different rules, so the end result is that only the rules for the hooks are used, and I don’t get any errors when I use duplicate props or rest
props, but I get errors when I violate the rules of hooks.
How do I include multiple external configs in a folder-specific override without a whole bunch of manual merging?