question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Override not working as anticipated

See original GitHub issue

eslint 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
    }
  ],
...
</details

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Sparticuzcommented, Aug 18, 2020

I’m seeing that now. I was assuming that if I used extends in an override, it would overwrite the top level config instead of … extending it 😄

I think we’re good now.

1reaction
kaicataldocommented, Aug 18, 2020

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?

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Override not having expected effect on class - Stack Overflow
I am testing out extending a class and overriding functions. With the below I get no compile errors yet when I call JonsClass2.jonsCalcFromClass ......
Read more >
Overriding materials is not working as expected in 2.91 beta
It is possible to persistently override materials if the original material is linked to the object, however it does appear not to work...
Read more >
SIEM rule override not working as expected - Elastic Discuss
Hello, Recently tried to use the severity overrides functionality for a SIEM rule, but this doesn't seem to work as expected.
Read more >
#11384 (Django Internationalization override translation ...
The internationalization override is not working as expected. The documentation says: you can write applications that include their own translations, ...
Read more >
'Override standard actions with a Lightning component' setting ...
'Override standard actions with a Lightning component' setting in Community not working as expected when the edit button is not added to the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found