我在使用ESLint CLI和--rule选项时遇到了问题。
# This is what I tried
eslint --rule "{no-console: error}" --fix-dry-run . 导致以下错误:
选项“规则”的无效值-预期类型对象,接收值:{no-控制台:。
使用--rule选项的正确方法是什么?我已经在本地安装了ESLint,并使用npx运行它。
.eslintrc.js
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'
}
};发布于 2020-11-28 16:10:56
这似乎是npx和Windows的一个bug。在本期中解释了删除--rule中的空格可以解决这个问题:
npx eslint --rule "no-console:error" --fix-dry-run .发布于 2020-11-28 14:21:02
您可以在"no-console": ["error"]规则中添加.eslintrc.js
module.exports = {
...
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'no-console': ['error']
}
};就跑吧
eslint --fix-dry-run ./或
eslint --rule "no-console: ['error']" --fix-dry-run .https://eslint.org/docs/user-guide/command-line-interface#-rule
https://stackoverflow.com/questions/65050338
复制相似问题