pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
vue/singleline-html-element-content-newline |
require a line break before and after the contents of a singleline element |
v5.0.0 |
require a line break before and after the contents of a singleline element
- ⚙️ This rule is included in all of
"plugin:vue/vue3-strongly-recommended"
,*.configs["flat/strongly-recommended"]
,"plugin:vue/strongly-recommended"
,*.configs["flat/vue2-strongly-recommended"]
,"plugin:vue/vue3-recommended"
,*.configs["flat/recommended"]
,"plugin:vue/recommended"
and*.configs["flat/vue2-recommended"]
. - 🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule.
This rule enforces a line break before and after the contents of a singleline element.
<template>
<!-- ✓ GOOD -->
<div attr>
content
</div>
<tr attr>
<td>
{{ data1 }}
</td>
<td>
{{ data2 }}
</td>
</tr>
<div attr>
<!-- comment -->
</div>
<!-- ✗ BAD -->
<div attr>content</div>
<tr attr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>
<div attr><!-- comment --></div>
</template>
{
"vue/singleline-html-element-content-newline": ["error", {
"ignoreWhenNoAttributes": true,
"ignoreWhenEmpty": true,
"ignores": ["pre", "textarea", ...INLINE_ELEMENTS],
"externalIgnores": []
}]
}
ignoreWhenNoAttributes
... allows having contents in one line, when given element has no attributes. defaulttrue
ignoreWhenEmpty
... disables reporting when element has no content. defaulttrue
ignores
... the configuration for element names to ignore line breaks style. default["pre", "textarea", ...INLINE_ELEMENTS]
externalIgnores
... the configuration for external element names to ignore line breaks style, it allows avoiding overwrite the default value of ignores. default[]
::: info All inline non void elements can be found here. :::
<template>
<!-- ✗ BAD -->
<div attr>content</div>
<tr attr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>
<div attr><!-- comment --></div>
</template>
<template>
<!-- ✗ BAD -->
<div>content</div>
<tr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>
<div><!-- comment --></div>
</template>
This rule was introduced in eslint-plugin-vue v5.0.0