html-eslint
html-eslint copied to clipboard
[BUG] HTML indent removes code from first line
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 Thanks for the report. I can reproduce it - demo. I'll fix it as soon :)
@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 Thanks 👍 I'll fix it also
@yeonjuan, kindly note that the issue mentioned in this demo is still not fixed in the latest version (0.13.2)
@melvinmicallef Thanks for reminding me. I'm still working on it :) Thanks.
Hi @melvinmicallef It's fixed in v0.14.0 by replacing the parser we use. Thanks for reporting it.