首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有--规则选项的ESLint CLI

带有--规则选项的ESLint CLI
EN

Stack Overflow用户
提问于 2020-11-28 13:56:27
回答 2查看 1.1K关注 0票数 1

我在使用ESLint CLI和--rule选项时遇到了问题。

代码语言:javascript
复制
# This is what I tried
eslint --rule "{no-console: error}" --fix-dry-run . 

导致以下错误:

选项“规则”的无效值-预期类型对象,接收值:{no-控制台:。

使用--rule选项的正确方法是什么?我已经在本地安装了ESLint,并使用npx运行它。

  • Node.js版本14.15.0
  • ESLint版本7.14.0
  • 操作系统Windows 10

.eslintrc.js

代码语言:javascript
复制
module.exports = {
  env: {
    browser: true,
    es2021: true,
    node: true
  },
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:vue/vue3-recommended',
    'prettier',
    'prettier/vue'
  ],
  parser: 'vue-eslint-parser',
  parserOptions: {
    parser: '@typescript-eslint/parser',
    ecmaVersion: 12,
    sourceType: 'module'
  },
  plugins: ['@typescript-eslint'],
  rules: {
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    '@typescript-eslint/no-explicit-any': 'off'
  }
};
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-11-28 16:10:56

这似乎是npx和Windows的一个bug。在本期中解释了删除--rule中的空格可以解决这个问题:

代码语言:javascript
复制
npx eslint --rule "no-console:error" --fix-dry-run .
票数 2
EN

Stack Overflow用户

发布于 2020-11-28 14:21:02

您可以在"no-console": ["error"]规则中添加.eslintrc.js

代码语言:javascript
复制
module.exports = {
  ...
  rules: {
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    '@typescript-eslint/no-explicit-any': 'off',
    'no-console': ['error']
  }
};

就跑吧

代码语言:javascript
复制
eslint --fix-dry-run ./

代码语言:javascript
复制
eslint --rule "no-console: ['error']" --fix-dry-run .

https://eslint.org/docs/user-guide/command-line-interface#-rule

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65050338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档