In the case where you have an override where you want to "downgrade" the js parser, how do you turn off the extends
from the parent? parserOptions
is easy to override because it is key-based. extends
as an empty array does nothing, as it tries to append an empty list to the original. If you set it to null
, you get a config parser error.
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
},
extends: [
'eslint:recommended'
],
overrides: [
{
files: ['vendor/**/*.js'],
parserOptions: {
ecmaVersion: 5,
sourceType: 'script'
},
extends: [] // I want 'eslint:recommended' removed.
}
]
};
The workaround involves looping over any extended rulesets and turning them all off.
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
},
extends: [
'eslint:recommended'
],
overrides: [
{
files: ['vendor/**/*.js'],
parserOptions: {
ecmaVersion: 5,
sourceType: 'script'
},
rules: Object.keys(require(path.resolve(path.dirname(require.resolve('eslint')), '../conf/eslint-recommended')).rules).reduce((rules, rule) => {
rules[rule] = 0;
return rules;
}, {})
}
]
};
Is there a cleaner way to do this?
Here are two ways to accomplish this:
Separate files:
You can place a different .eslintrc.js
file inside vendor/
with root: true
. That will ignore the .eslintrc.js
at your project root.
Separate overrides:
module.exports = {
root: true,
overrides: [
{
files: ['*.js'],
excludedFiles: 'vendor/**/*.js',
// OR
// files: ['src/**/*.js']
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
extends: ['eslint:recommended'],
},
{
files: ['vendor/**/*.js'],
parserOptions: {
ecmaVersion: 5,
sourceType: 'script',
},
},
],
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With