Reputation: 430
I'm having trouble using the ESLint CLI with the --rule
option.
# This is what I tried
eslint --rule "{no-console: error}" --fix-dry-run .
Resulting in the following error:
Invalid value for option 'rule' - expected type Object, received value: {no-console:.
What is the right way of using the --rule
option? I have ESLint installed locally and use npx
to run it.
.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'
}
};
Upvotes: 4
Views: 2618
Reputation: 430
It seems to be a bug with npx
and Windows. Explained in this issue removing the spaces inside --rule
solves the issue:
npx eslint --rule "no-console:error" --fix-dry-run .
Upvotes: 5
Reputation: 1255
You could add "no-console": ["error"]
in .eslintrc.js
rules
module.exports = {
...
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'no-console': ['error']
}
};
and just run
eslint --fix-dry-run ./
or
eslint --rule "no-console: ['error']" --fix-dry-run .
https://eslint.org/docs/user-guide/command-line-interface#-rule
Upvotes: 1