2

I use "eslint-plugin-vue"

I would like to use the rule "vue/singleline-html-element-content-newline" in my projects but it works inconvenient for me All the more because this rule is recommended:

This rule is included in all of "plugin:vue/vue3-strongly-recommended", "plugin:vue/strongly-recommended", "plugin:vue/vue3-recommended" and "plugin:vue/recommended". So, my problem is using text nodes without attributes:

<div attrs>
    <span attrs>Text<span>
</div>

that code is better for me than

<div attrs>
    <span attrs>
        Text
    <span>
</div>

because in the second case the text node is hanging in the air and it generates redundant code: \n\t\tText\n\t

  • I know about the option "ignoreWhenNoAttributes" but it works only when no attributes.
  • I can add all inline elements to the options list "ignores", but in this case, I have to add all my custom inline components. But eslint config creates for several projects.
  • Yes, I can add custom components into the config for the particular project. But this becomes inconsistent.
  • One more solution: wrap a text node into <span> element without attributes:
<div attrs>
    <my-component attrs>
        <span>Text<span>
    <span>
</div>

As I see it would be better to ignore the rule for text nodes.

Is there any other approach for text nodes?

belykh
  • 1,109
  • 10
  • 25
  • Redundant code isn't a problem if template minification is in effect. Just make sure that the presence or absence of empty lines doesn't affect the layout. – Estus Flask Sep 12 '21 at 21:36
  • Yes, redundant code, in general, is not a problem, I agree. I found an option for "vue-template-compiler" `whitespace: 'condense'` It transforms "\n\t\tText\n\t" to " Text " – belykh Sep 12 '21 at 22:34

0 Answers0