我有一些 linting 规则,.eslintrc.js
如下所示:
module.exports = {
root: true,
env: {
browser: true,
es6: true,
node: true,
},
extends: ['plugin:vue/recommended', 'eslint:recommended'],
parserOptions: {
parser: 'babel-eslint',
},
rules: {
'import/extensions': 0,
'import/no-unresolved': 0,
'import/prefer-default-export': 0,
'no-shadow': 0, // TODO: figure out this error in vuex state
'no-param-reassign': 0, // TODO: figure out this error in vuex state
'no-use-before-define': 0, // TODO: figure out this error in vuex state
'no-underscore-dangle': 0,
'no-useless-escape': 0,
semi: [2, 'never'],
'vue/no-v-html': 0,
'vue/custom-event-name-casing': 0,
'vue/html-indent': [
'error',
4,
{
attribute: 1,
baseIndent: 1,
closeBracket: 0,
alignAttributesVertically: true,
ignores: [],
},
],
'vue/script-indent': [
'error',
2,
{
baseIndent: 1,
switchCase: 1,
ignores: [],
},
],
'vue/max-attributes-per-line': [
'error',
{
singleline: 1,
multiline: {
max: 1,
allowFirstLine: true,
},
},
],
'vue/html-closing-bracket-newline': [
'error',
{
singleline: 'never',
multiline: 'never',
},
],
'vue/html-self-closing': [
'error',
{
html: {
void: 'always',
normal: 'always',
component: 'always',
},
svg: 'always',
math: 'always',
},
],
'vue/attribute-hyphenation': ['error', 'always'],
},
}
我将这些设置作为我的工作区设置:
{
"editor.tabSize": 4,
"editor.insertSpaces": false,
"editor.detectIndentation": false,
"vetur.format.options.useTabs": false,
"vetur.format.defaultFormatterOptions": {
"prettyhtml": {
"printWidth": 120,
"singleQuote": true
},
"js-beautify-html": {
"wrap_attributes": "force-aligned",
"indent_size": 4
}
},
"vetur.format.scriptInitialIndent": true,
"vetur.format.styleInitialIndent": true,
"vetur.format.defaultFormatter.js": "prettier-eslint",
"vetur.format.defaultFormatter.html": "js-beautify-html",
"html.format.wrapAttributes": "force",
"vetur.format.defaultFormatter.css": "none",
"vetur.format.defaultFormatter.scss": "prettier",
"editor.formatOnSave": true,
"vetur.validation.template": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
当我保存文件并格式化一切正常时,格式化工作。但是当我跑步时
eslint --fix --ext js,vue src
这显示了 lint 警告和错误,但不符合vue/html-indent
规则。
- 如果组件看起来像这样:
<transition
name="slide-fade"
mode="in-out">
<div
v-if="showDesktopSearch"
v-on-clickaway="away"
class="desktop-search-component"
:class="positionClass">
This is the body
</div>
</transition>
- 如果我保存组件如下所示:
<transition name="slide-fade"
mode="in-out">
<div v-if="showDesktopSearch"
v-on-clickaway="away"
class="desktop-search-component"
:class="positionClass">
This is the body
</div>
</transition>
- 但是如果我运行 linting 命令,它看起来像这样:
<transition
name="slide-fade"
mode="in-out">
<div
v-if="showDesktopSearch"
v-on-clickaway="away"
class="desktop-search-component"
:class="positionClass">
This is the body
</div>
</transition>
我想vue/html-indent
在运行 lint 命令时修复所有错误,但我在这里没有成功。如何从 cli 获取 vetur/eslint 格式?