首页 > 解决方案 > ESLint 没有为 console.log 发送警告

问题描述

我有以下 .eslintrc ...

{
  plugins: [
    'markdown',
    'json'
  ],
  parserOptions: {
    'ecmaVersion': 2017,
    'sourceType': 'module',
  },
  extends: [
    'eslint:recommended',
    'plugin:vue/essential'
  ]
}

为了测试它,我向 test.js 添加了一个控制台语句并运行./node_modules/.bin/eslint <folder>/test.js. 我希望看到类似...

警告 Unexpected console statement
no-console

但相反,我没有看到任何输出。我错过了什么?

标签: eslint

解决方案


我认为它会为你工作。注意扩展插件。我在我的项目中使用了这个结构,一切都很好。你console.log.js文件中添加了,eslint:recommended就可以了。

module.exports = {
  root: true,
  parserOptions: {
    parser: "babel-eslint",
    sourceType: "module"
  },
  env: {
    browser: true
  },
  extends: [
    "eslint:recommended",
    "plugin:vue/recommended"
  ],
  plugins: [
    "vue" // required to lint *.vue files
  ],
  // add your custom rules here
  rules: {
    "arrow-parens": 0,
    "generator-star-spacing": 0,
    "no-debugger": process.env.NODE_ENV === "production" ? 2 : 0
  }
}

推荐阅读