Eslint: How to disable “unexpected console statement” in Node.js?

后端 未结 17 1581
遇见更好的自我
遇见更好的自我 2020-12-07 07:39

I\'m using eslint with Sublime Text 3 and I am writing gulpfile.js.

/*eslint-env node*/
var gulp = require(\'gulp\');

gulp.task(\'default\', fu         


        
相关标签:
17条回答
  • 2020-12-07 08:19

    I'm using Ember.js which generates a file named .eslintrc.js. Adding "no-console": 0 to the rules object did the job for me. The updated file looks like this:

    module.exports = {
      root: true,
      parserOptions: {
        ecmaVersion: 6,
        sourceType: 'module'
      },
      extends: 'eslint:recommended',
      env: {
        browser: true
      },
      rules: {
        "no-console": 0
      }
    };
    
    0 讨论(0)
  • 2020-12-07 08:19

    If you're still having trouble even after configuring your package.json according to the documentation (if you've opted to use package.json to track rather than separate config files):

    "rules": {
          "no-console": "off"
        },
    

    And it still isn't working for you, don't forget you need to go back to the command line and do npm install again. :)

    0 讨论(0)
  • 2020-12-07 08:19

    You should add one rule and add your env:

    {
      "rules": {
        "no-console": "off"
      },
      "env": {
        "browser": true
      }
    }
    

    you can add other envs.

    0 讨论(0)
  • 2020-12-07 08:20

    Alternatively instead of turning 'no-console' off, you can allow. In the .eslintrc.js file put

      rules: {
        "no-console": [
         "warn",
         { "allow": ["clear", "info", "error", "dir", "trace", "log"] }
        ]
      }
    

    This will allow you to do console.log and console.clear etc without throwing errors.

    0 讨论(0)
  • 2020-12-07 08:21

    2018 October,

    just do:

    // tslint:disable-next-line:no-console
    

    the anothers answer with

    // eslint-disable-next-line no-console
    

    does not work !

    0 讨论(0)
  • 2020-12-07 08:21

    Use Window Object

    window.console.log("..")

    0 讨论(0)
提交回复
热议问题