require a line break before and after the contents of a singleline element (vue/singleline-html-element-content-newline)
- ⚙️ This rule is included in
"plugin:vue/strongly-recommended"
and"plugin:vue/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.
👎 Examples of incorrect code:
<div attr>content</div>
<tr attr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>
<div attr><!-- comment --></div>
👍 Examples of correct code:
<div attr>
content
</div>
<tr attr>
<td>
{{ data1 }}
</td>
<td>
{{ data2 }}
</td>
</tr>
<div attr>
<!-- comment -->
</div>
{
"vue/singleline-html-element-content-newline": ["error", {
"ignoreWhenNoAttributes": true,
"ignores": ["pre", "textarea"]
}]
}
ignoreWhenNoAttributes
... allows having contents in one line, when given element has no attributes. defaulttrue
ignores
... the configuration for element names to ignore line breaks style.
default["pre", "textarea"]
👎 Examples of incorrect code for {ignoreWhenNoAttributes: false}
:
/* eslint vue/singleline-html-element-content-newline: ["error", { "ignoreWhenNoAttributes": false}] */
<div>content</div>
<tr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>
<div><!-- comment --></div>
👍 Examples of correct code for {ignoreWhenNoAttributes: true}
(default):
/* eslint vue/singleline-html-element-content-newline: ["error", { "ignoreWhenNoAttributes": true}] */
<div>content</div>
<tr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>
<div><!-- comment --></div>
👎 Examples of incorrect code for {ignoreWhenNoAttributes: true}
(default):
/* eslint vue/singleline-html-element-content-newline: ["error", { "ignoreWhenNoAttributes": true}] */
<div attr>content</div>
<tr attr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>
<div attr><!-- comment --></div>
👍 Examples of correct code for ignores
:
/* eslint vue/singleline-html-element-content-newline: ["error", { "ignores": ["VueComponent", "pre", "textarea"]}] */
<VueComponent>content</VueComponent>
<VueComponent attr><span>content</span></VueComponent>