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.

[eslint-config-react-app] Can't disable rule "@typescript-eslint/no-unused-vars" in config, outside of CRA

See original GitHub issue
Related

https://github.com/facebook/create-react-app/issues/6871 https://github.com/facebook/create-react-app/issues/6915

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

no-unused-vars, etc.

Environment

eslint-config-react-app@^4.0.0:
  version "4.0.0"
eslint@^5.16.0:
  version "5.16.0"
"@typescript-eslint/eslint-plugin@^1.7.0":
  version "1.7.0"
"@typescript-eslint/parser@1.7.0", "@typescript-eslint/parser@^1.7.0":
  version "1.7.0"

Steps to Reproduce

In .eslintrc.js, when react-app is extended, e.g. extends: ['plugin:@typescript-eslint/recommended', "react-app"], it is impossible to disable the @typescript-eslint/no-unused-vars rule, e.g.,

    "rules": {
        "no-unused-vars":"off",
        "@typescript-eslint/no-unused-vars": "off",

eslint is invoked at the command line using

npx eslint --ext .js,.jsx,.ts,.tsx src No error message regarding the configuration is emitted; it simply ignores the configuration.

After reading the code, I suspect that these rules also suffer from the same petrification.

Workaround

Include this at the top level of the config object:

    "overrides": {
        files: ['**/*.ts', '**/*.tsx'],
        parser: '@typescript-eslint/parser',
        parserOptions: {
            ecmaVersion: 2018,
            sourceType: 'module',
            ecmaFeatures: {
                jsx: true,
            },

            // typescript-eslint specific options
            warnOnUnsupportedTypeScriptVersion: true,
        },
        plugins: ['@typescript-eslint'],

        rules: {
            "@typescript-eslint/no-unused-vars": "off",
        }
    },

This workaround is probably much more verbose than is wise or necessary, but it is sufficient.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:30
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

20reactions
jednanocommented, Sep 26, 2019

solipsistic

[ˌsäləpˈsistik] DEFINITION adjective form of solipsism


solipsism

[ˈsäləpˌsizəm] NOUN the view or theory that the self is all that can be known to exist.

19reactions
sahilrajput03commented, Jul 26, 2020

Actually this can be solved easily via putting this at the start of the file.(although we’d need to do it for all files) /* eslint-disable @typescript-eslint/no-unused-vars */

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript eslint disable no-unused-vars - Stack Overflow
"eslintConfig": { "extends": "react-app", "rules": { "@typescript-eslint/no-unused-vars": "off" } },. I tried moving the rules into a .eslintrc.
Read more >
12 essential ESLint rules for React - LogRocket Blog
All versions of react-scripts (one of CRA's packages) from v3 and later utilize an inbuilt Create React App ESLint configuration which is ...
Read more >
Setting Up Your Editor | Create React App
Note that even if you customise your ESLint config, these changes will ... note that any rules that are set to "error" will...
Read more >
How to Setup ESLint and Prettier for Your React Apps
It means it checks out the code without executing it. But why use a linter, you might think? Because you can build an...
Read more >
Strict Mode - React
StrictMode is a tool for highlighting potential problems in an application. Like Fragment , StrictMode does not render any visible UI.
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