Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off error for console.log on my eslint

I'm trying to turn off lint warning for my eslint at VS code.

My code is contains.

console.log('blabla..');

eslint said as below.

 error  Unexpected console statement                      no-console

Even though already add no-restricted-syntax at my .eslintrc.json, no fixed.

Here is my .eslintrc.json

{
    "env": {
        "es6": true,
        "node": true,
        "amd": true,
        "mocha": true
    },
    "extends": "eslint:recommended",
    "parserOptions": {
        "ecmaVersion": 2017,
        "sourceType": "module"
    },
    "rules": {
        "linebreak-style": [
            "error",
            "windows"
        ],
        "no-restricted-syntax": [
            "error",
            {
                "selector": "CallExpression[callee.object.name='console'][callee.property.name=/^(log|warn|error|info|trace)$/]",
                "message": "Unexpected property on console object was called"
            }
        ]
    }
}

What did I mistake?

like image 733
sungyong Avatar asked Feb 04 '23 03:02

sungyong


1 Answers

Allowing the console.log to stay in code is requiring a separate rule. You need to add 'no-console' statement to your eslint config rules.

Like so:

rules: {
  "no-console": 0
}

A better practice is to warn you about all the console.log in your code, like so:

rules: {
  "no-console": 1
}
like image 81
Elad Avatar answered Feb 08 '23 12:02

Elad