我正在使用eslint与Sublime Text 3和我正在编写gulpfile.js。

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

gulp.task('default', function(){
    console.log('default task');
});

但是eslint一直显示error: " error: Unexpected console statement. "(no-console)”

我在这里找到了官方文件,但我仍然不知道如何禁用它。

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

/*eslint no-console: 2*/
gulp.task('default', function(){
    console.log('default task');
});

也不管用。

我的崇高文本3插件:升华和升华-contrib-eslint。

这是我的.eslintrc.js文件:

module.exports = {
    "rules": {
        "no-console":0,
        "indent": [
            2,
            "tab"
        ],
        "quotes": [
            2,
            "single"
        ],
        "linebreak-style": [
            2,
            "unix"
        ],
        "semi": [
            2,
            "always"
        ]
    },
    "env": {
        "browser": true,
        "node": true
    },
    "extends": "eslint:recommended"
};

当前回答

我使用Ember.js生成一个名为.eslintrc.js的文件。在rules对象中添加“no-console”:0对我来说就是这样。更新后的文件是这样的:

module.exports = {
  root: true,
  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module'
  },
  extends: 'eslint:recommended',
  env: {
    browser: true
  },
  rules: {
    "no-console": 0
  }
};

其他回答

我使用Ember.js生成一个名为.eslintrc.js的文件。在rules对象中添加“no-console”:0对我来说就是这样。更新后的文件是这样的:

module.exports = {
  root: true,
  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module'
  },
  extends: 'eslint:recommended',
  env: {
    browser: true
  },
  rules: {
    "no-console": 0
  }
};

如果你想只对一行禁用规则,下面的方法可以在VSCode中使用ESLint。

禁用下一行:

// eslint-disable-next-line no-console
console.log('hello world');

禁用当前行。

console.log('hello world'); // eslint-disable-line no-console

如果你在你的本地项目下安装eslint,你应该有一个目录/node_modules/eslint/conf/,在这个目录下有一个文件eslint.json。你可以编辑文件,并修改“no-console”条目的值为“off”(尽管也支持0值):

"rules": {
    "no-alert": "off",
    "no-array-constructor": "off",
    "no-bitwise": "off",
    "no-caller": "off",
    "no-case-declarations": "error",
    "no-catch-shadow": "off",
    "no-class-assign": "error",
    "no-cond-assign": "error",
    "no-confusing-arrow": "off",
    "no-console": "off",
    ....

我希望这个“配置”可以帮助你。

请确保颤振项目所在文件夹的名称。没有空格。这是我的错误

我的2美分贡献:

除了删除控制台警告(如上所示),最好从PROD环境中删除您的日志(出于安全原因)。 我发现最好的方法是把它添加到nuext .config.js中

  build: {
   terser: {
      terserOptions: {
        compress: {
          //this removes console.log from production environment
          drop_console: true
        }
      }
    }
  }

工作原理:Nuxt已经使用terser作为缩略词。该配置将强制terser在压缩期间忽略/删除所有控制台日志命令。