Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule proposal: padding-lines-between-tags #1832

Closed
1 of 4 tasks
amiranagram opened this issue Mar 28, 2022 · 5 comments · Fixed by #1966
Closed
1 of 4 tasks

Rule proposal: padding-lines-between-tags #1832

amiranagram opened this issue Mar 28, 2022 · 5 comments · Fixed by #1966

Comments

@amiranagram
Copy link

amiranagram commented Mar 28, 2022

Please describe what the rule should do:

The rule, as demonstrated in #855 (comment) and #1829 should enforce line breaks between HTML tags in template. Not all tags, just siblings.

What category should the rule belong to?

  • Enforces code style (layout)
  • Warns about a potential error (problem)
  • Suggests an alternate way of doing something (suggestion)
  • Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

<!-- GOOD -->
<template>
    <div>
        <p>Item 1</p>

        <p>Item 2</p>
    </div>
</template>

<!-- BAD -->
<template>
    <div>
        <p>Item 1</p>
        <p>Item 2</p>
    </div>
</template>
<!-- GOOD -->
<template>
    <ul>
        <li>1</li>
        
        <li>2</li>

        <li>
            <ul>
                <li>3.1</li>
                
                <li>3.2</li>
            </ul>
        </li>

        <li>
            <ul>
                <li>4.1</li>
            </ul>
        </li>
    </ul>
</template>

<!-- BAD-->
<template>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>
            <ul>
                <li>3.1</li>
                <li>3.2</li>
            </ul>
        </li>
        <li>
            <ul>
                <li>4.1</li>
            </ul>
        </li>
    </ul>
</template>

Additional context

Similar to vue/padding-line-between-blocks https://eslint.vuejs.org/rules/padding-line-between-blocks.html

@ota-meshi
Copy link
Member

Thank you for the rule proposal.
I think it's probably better to be able to set options for each element before and after, like padding-line-between-statements. For example, I don't want to have padding before and after <br>.

https://eslint.org/docs/rules/padding-line-between-statements

@amiranagram
Copy link
Author

amiranagram commented Mar 31, 2022

Agree @ota-meshi. What do you think about "ignores" option where you can specify tags to ignore?

Example: https://eslint.vuejs.org/rules/multiline-html-element-content-newline.html#vue-multiline-html-element-content-newline

Also, here (#1834 (comment)) it's suggested for components, but why not for both with one rule.

@Evgenios95
Copy link

@amiranagram That would also be interesting and give crazy flexibility. Like a Regex configuration that you can define

@kiccer
Copy link

kiccer commented Apr 7, 2022

I recommend ignoring elements that are displayed on a single line. Only add blank lines before and after elements that contain child elements, and before and after elements that display attributes on multiple lines.
As for whether blank lines are required between parent and child elements, this could also be an optional option.


我建议忽略单行显示的元素。仅在包含子元素的元素前后增加空行,以及多行展示属性的元素前后增加空行。
至于父元素与子元素之间是否需要空行,也可以作为一个可选项。

<template>
    <div class="container">
        <ul>
            <li>
                <p>123</p>
                <p>123</p>
            </li>

            <li>
                <p>123</p>
                <p>123</p>
            </li>

            <li>
                <p>123</p>
                <p>123</p>
            </li>

            <li>
                <p>123</p>
                <p>123</p>
            </li>

            <li>
                <p>123</p>
                <p>123</p>
            </li>
        </ul>

        <p>123</p>
        <p>123</p>
        <p>123</p>

        <!-- Comp1 -->
        <Comp1 />
        
        <!-- Comp2 -->
        <Comp2 />
        
        <!-- Comp3 -->
        <Comp3 />

        <!-- Comp4 -->
        <Comp4
            prop1
            prop2
        />
    </div>
</template>

@dev1437
Copy link
Contributor

dev1437 commented Sep 10, 2022

Hi, I have created a rule for this @ota-meshi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants