html-eslint icon indicating copy to clipboard operation
html-eslint copied to clipboard

[BUG] HTML indent removes code from first line

Open melvinmicallef opened this issue 3 years ago • 5 comments

Bug: When using the --fix option for eslint on the rule @html-eslint/indent, if there are multiple html elements on the first line, the code is altered as well. This is very confusing and prone to introducing bugs since elements are removed without notice. Please see replication steps for further info.

Replication steps: Configuration

...
       {
           "files": ["ng-app/**/*.html"],
           "parser": "@html-eslint/parser",
           "rules": {
               "max-lines": ["error", 400],
               "@html-eslint/no-duplicate-id": "error",
               "@html-eslint/no-inline-styles": "error",
               "@html-eslint/no-obsolete-tags": "error",
               "@html-eslint/require-closing-tags": ["error", {"selfClosing": "always"}],
               "@html-eslint/no-duplicate-attrs": "error",
               "@html-eslint/require-img-alt": "error",
               "@html-eslint/no-extra-spacing-attrs": "error",
               "@html-eslint/indent": ["error", 4],
               "@html-eslint/quotes":["error", "double"],
               "@html-eslint/id-naming-convention": ["error", "camelCase"],
               "@html-eslint/no-multiple-empty-lines": "error"
           }
...

Problematic HTML file:

<div class="outer-div"><div class="inner-div">
        inner div
    </div>
</div>

Expected formatting result

<div class="outer-div">
    <div class="inner-div">
        inner div
    </div>
</div>

Actual formatting result - The outer div is removed, breaking the HTML

    <div class="inner-div">
        inner div
    </div>
</div>

Notes: This issue only occurs if the two element next to eachother are on the first line of the HTML file. Formatting this file will be done as expected:

<div>This is the first line</div>
<div class="outer-div"><div class="inner-div">
        inner div
    </div>
</div>

Let me know if I can provide you with further information :)

melvinmicallef avatar May 20 '22 10:05 melvinmicallef

@melvinmicallef Thanks for the report. I can reproduce it - demo. I'll fix it as soon :)

yeonjuan avatar May 26 '22 10:05 yeonjuan

@yeonjuan , First of all, thank you for your quick action on this :)

I have encountered a similar issue but on the rule 'no-extra-spacing-attrs'. Please see the demo demo

melvinmicallef avatar May 30 '22 06:05 melvinmicallef

@melvinmicallef Thanks 👍 I'll fix it also

yeonjuan avatar May 31 '22 14:05 yeonjuan

@yeonjuan, kindly note that the issue mentioned in this demo is still not fixed in the latest version (0.13.2)

melvinmicallef avatar Jun 09 '22 14:06 melvinmicallef

@melvinmicallef Thanks for reminding me. I'm still working on it :) Thanks.

yeonjuan avatar Jun 11 '22 09:06 yeonjuan

Hi @melvinmicallef It's fixed in v0.14.0 by replacing the parser we use. Thanks for reporting it.

yeonjuan avatar Sep 15 '22 12:09 yeonjuan