Appearance
vue/html-indent
强制
<template>
中的一致缩进
- ⚙️ 此规则包含在
"plugin:vue/strongly-recommended"
、*.configs["flat/strongly-recommended"]
、"plugin:vue/vue2-strongly-recommended"
、*.configs["flat/vue2-strongly-recommended"]
、"plugin:vue/recommended"
、*.configs["flat/recommended"]
、"plugin:vue/vue2-recommended"
和*.configs["flat/vue2-recommended"]
中。
🔧命令行 上的
--fix
选项可以自动修复此规则报告的一些问题。¥🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule.
📖 规则详情
此规则强制在 <template>
中使用一致的缩进样式。默认样式为 2 个空格。
¥This rule enforces a consistent indentation style in <template>
. The default style is 2 spaces.
此规则检查所有标签,以及指令和 mustache 中的所有表达式。
¥This rule checks all tags, also all expressions in directives and mustaches.
在表达式中,此规则支持 ECMAScript 2022 语法。它会忽略未知的 AST 节点,但可能会与非标准语法混淆。
¥In the expressions, this rule supports ECMAScript 2022 syntaxes. It ignores unknown AST nodes, but it might be confused by non-standard syntaxes.
🔧选项
¥🔧 Options
json
{
"vue/html-indent": ["error", type, {
"attribute": 1,
"baseIndent": 1,
"closeBracket": 0,
"alignAttributesVertically": true,
"ignores": []
}]
}
type
(number | "tab"
) ...缩进类型。默认值为2
。如果这是一个数字,则它表示一次缩进的空格数。如果这是"tab"
,则它使用一个制表符进行一次缩进。¥
type
(number | "tab"
) ... The type of indentation. Default is2
. If this is a number, it's the number of spaces for one indent. If this is"tab"
, it uses one tab for one indent.attribute
(integer
) ...属性的缩进乘数。默认值为1
。¥
attribute
(integer
) ... The multiplier of indentation for attributes. Default is1
.baseIndent
(integer
) ...顶层语句的缩进乘数。默认值为1
。¥
baseIndent
(integer
) ... The multiplier of indentation for top-level statements. Default is1
.closeBracket
(integer | object
) ...右括号的缩进乘数。默认值为0
。你可以通过设置数字值来应用以下所有内容。¥
closeBracket
(integer | object
) ... The multiplier of indentation for right brackets. Default is0
.\ You can apply all of the following by setting a number value.closeBracket.startTag
(integer
) ...开始标记右括号的缩进乘数(<div>
)。默认值为0
。¥
closeBracket.startTag
(integer
) ... The multiplier of indentation for right brackets of start tags (<div>
). Default is0
.closeBracket.endTag
(integer
) ...结束标记右括号的缩进乘数(</div>
)。默认值为0
。¥
closeBracket.endTag
(integer
) ... The multiplier of indentation for right brackets of end tags (</div>
). Default is0
.closeBracket.selfClosingTag
(integer
) ...开始标记右括号的缩进乘数(<div/>
)。默认值为0
。¥
closeBracket.selfClosingTag
(integer
) ... The multiplier of indentation for right brackets of start tags (<div/>
). Default is0
.
alignAttributesVertically
(boolean
) ...在多行情况下,属性是否应垂直对齐到第一个属性的条件。默认值为true
¥
alignAttributesVertically
(boolean
) ... Condition for whether attributes should be vertically aligned to the first attribute in multiline case or not. Default istrue
ignores
(string[]
) ...忽略节点的选择器。AST 规范是 此处。你可以使用 esquery 来选择节点。默认值为空数组。¥
ignores
(string[]
) ... The selector to ignore nodes. The AST spec is here. You can use esquery to select nodes. Default is an empty array.
2, {"attribute": 1, "closeBracket": 1}
2, {"attribute": 2, "closeBracket": 1}
2, {"ignores": ["VAttribute"]}
2, {"alignAttributesVertically": false}
2, {"baseIndent": 0}
🚀版本
¥🚀 Version
此规则在 eslint-plugin-vue v3.14.0 中引入
¥This rule was introduced in eslint-plugin-vue v3.14.0
🔍代码实现
¥🔍 Implementation