JS.VUE.SINGLELINE.HTML.ELEMENT.CONTENT.NEWLINE

Require a line break before and after the contents of a singleline element

Rule Details

This rule enforces a line break before and after the contents of a singleline element.

{'vue/singleline-html-element-content-newline': ['error']}

Copy
<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>

Options

Copy
{
  "vue/singleline-html-element-content-newline": ["error", {
    "ignoreWhenNoAttributes": true,
    "ignoreWhenEmpty": true,
    "ignores": ["pre", "textarea", ...INLINE_ELEMENTS]
  }]
}
  • ignoreWhenNoAttributes ... allows having contents in one line, when given element has no attributes. default true
  • ignoreWhenEmpty ... disables reporting when element has no content. default true
  • ignores ... the configuration for element names to ignore line breaks style. default ["pre", "textarea", ...INLINE_ELEMENTS].

All inline non void elements can be found here (https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/utils/inline-non-void-elements.json).

"ignoreWhenNoAttributes": true

{'vue/singleline-html-element-content-newline': ['error', {'ignoreWhenNoAttributes': true}]}

Copy
<template>
  <!-- BAD -->
  <div attr>content</div>

  <tr attr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>

  <div attr><!-- comment --></div>
</template>

"ignoreWhenNoAttributes": false

{'vue/singleline-html-element-content-newline': ['error', {'ignoreWhenNoAttributes': false}]}

Copy
<template>
  <!-- BAD -->
  <div>content</div>

  <tr><td>{{ data1 }}</td><td>{{ data2 }}</td></tr>

  <div><!-- comment --></div>
</template>

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/