Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can get warning instead of error in ESLint for no-unused-vars?

Tags:

eslint

How I can get a warning instead of an error while using ESLint?

I use ESLint 6.7.2 version with a plugin for babel and react.

This is my actual .eslintrc.json:

{
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
    },
    "settings": {
        "react" : {
            "version": "16.7.0"
        }
    },
    "parser": "babel-eslint"
}
like image 733
Alessandro_russo Avatar asked Dec 07 '19 11:12

Alessandro_russo


People also ask

How do you ignore no-unused-vars ESLint?

To apply the ESLint no-unused-vars rule to a block of JavaScript code, we can wrap the code block that we want to apply the rule to with /* eslint-disable no-unused-vars */ and /* eslint-enable no-unused-vars */ respectively. to wrap the code that we want the rule to apply with the comments.

How do you remove unused variables from ESLint?

To automatically remove unused imports, we will need to add the eslint-plugin-unused-imports plugin. Now, when you run ESLint, you should see error lines saying error '<imported-var>' is defined but never used unused-imports/no-unused-imports for the files where you have unused imports.

How do I turn off rule ESLint?

If you want to disable an ESLint rule in a file or on a specific line, you can add a comment. On a single line: const message = 'foo'; console. log(message); // eslint-disable-line no-console // eslint-disable-next-line no-console console.


1 Answers

I've found the answer:

It enough to add a rule for no-unused-vars:

"rules": {
    "no-unused-vars": "warn"
},

Also, restart the server.

like image 147
Alessandro_russo Avatar answered Oct 20 '22 14:10

Alessandro_russo