Override not working as anticipated
See original GitHub issueeslint 7.6.0
I’m trying to add TS & JS linting, but with different rules, settings, etc… While making the right config and looking at the docs, I was a little confused, so I asked in discord about it. First, the documentation for overrides was a little sparse, so I’m not sure what the intended functionality is. I would think that the overrides would override any config ‘higher up’ the config, but it seems that this is not really the case. It seems like the entire rules block is overridden.
Example: In my config, I have "no-restricted-syntax"
in the base config, so I can use for-of (which I think the original settings for that are in airbnb-base, and they disallow for-of). This rule works fine in JS files, but when I split out the overrides for TS files, I would expect the rule to also apply to them, but it doesn’t (verified by --print-config on a TS file).
Basically, my question/change request would be: Does the Overrides block override the rules block, or does/should it be augmenting it? Do the documents needs to be updated to make the correct implementation more clear? Or is this a bug?
eslint config
module.exports = {
env: {
es6: true,
es2017: true,
es2020: true,
node: true,
},
extends: [
"airbnb-base",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:promise/recommended",
"plugin:node/recommended",
"plugin:unicorn/recommended",
"prettier",
"plugin:prettier/recommended",
],
// Ignore my dist folders so I don't lint transpiled files
ignorePatterns: "dist/**/*",
overrides: [
{
// Test Javascript Files Override Block
files: ["**/tests/*.js"],
rules: {
"node/no-unpublished-require": 0,
},
},
{
// Typescript Override Block
extends: [
"airbnb-base",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:promise/recommended",
"plugin:node/recommended",
"plugin:unicorn/recommended",
"prettier",
"plugin:prettier/recommended",
"prettier/@typescript-eslint",
],
files: ["**/*.ts", "**/*.tsx"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
},
plugins: [
"@typescript-eslint",
"typescript-sort-keys",
"import",
"node",
"prettier",
"promise",
"unicorn",
],
rules: {
// Make sure we don't require .ts and .tsx
"import/extensions": [
"error",
"ignorePackages",
{
ts: "never",
tsx: "never",
},
],
// Typescript uses Imports for transpiling
"node/no-unsupported-features/es-syntax": [
"error",
{
ignores: ["modules"],
},
],
},
settings: {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/resolver": {
// user <root>/tsconfig.json
"typescript": {
"alwaysTryTypes": true,
}
},
node: {
// Make sure we are looking for Typescript files as well
tryExtensions: [".js", ".json", ".node", ".ts", ".d.ts"],
},
},
},
],
parser: "esprima",
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
},
plugins: ["import", "node", "prettier", "promise", "unicorn"],
rules: {
// disallow certain syntax forms, allows for-of
// http://eslint.org/docs/rules/no-restricted-syntax
"no-restricted-syntax": [
"error",
"ForInStatement",
"LabeledStatement",
"WithStatement",
],
"sort-keys": [
"error",
"asc",
{
natural: true,
},
],
// Allow aws-sdk to exist in optionalDependencies and be used in production
"import/no-extraneous-dependencies": [
"error",
{
optionalDependencies: true,
},
],
},
};
relevant sections of a --print-config on a ts file
...
"no-restricted-syntax": [
"error",
{
"selector": "ForInStatement",
"message": "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array."
},
{
"selector": "ForOfStatement",
"message": "iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations."
},
{
"selector": "LabeledStatement",
"message": "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand."
},
{
"selector": "WithStatement",
"message": "`with` is disallowed in strict mode because it makes code impossible to predict and optimize."
}
],
...
"sort-keys": [
"off",
"asc",
{
"caseSensitive": false,
"natural": true
}
],
...
</detailsIssue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
I’m seeing that now. I was assuming that if I used
extends
in anoverride
, it would overwrite the top level config instead of … extending it 😄I think we’re good now.
The overrides should be merged into the top-level config. If that’s not happening, it sounds like something might be misconfigured or we there’s been some kind of regression in the config system. Any chance you could make a Git repository with the minimal reproduction case so we can get a better idea of what’s going?
Re documentation, PRs are welcome to improve it!