yeonjuan / html-eslint

ESLint plugin for linting HTML
https://html-eslint.org
MIT License
161 stars 28 forks source link

Rule `no-extra-spacing-attrs` removing other attributes. #137

Closed maheshbansod closed 1 year ago

maheshbansod commented 1 year ago

Noticed that if an attribute value with special characters (e.g. _ / { ) or some invalid value appears in HTML and the rule @html-eslint/no-extra-spacing-attrs is active then eslint (with --fix) strips off everything after the attribute name.

Example: HTML

<a target=”_blank” a b c d e f>
link
</a>

eslint config:

{
    "plugins": ["@html-eslint"],
    "overrides": [{
        "files": ["*.html"],
        "parser": "@html-eslint/parser",
        "rules": {
            "@html-eslint/no-extra-spacing-attrs": ["warn"]
        }
    }]
}

Observed result HTML:

<a target>
link
</a>

Edit: I've not quite figured out the actual problem.. after changing it to target="blank" (i.e. without special characters), I still get the same result - the other attributes are removed - this doesn't happen in case of href attribute.

yeonjuan commented 1 year ago

Hi @maheshbansod , Thanks for the reporting. I can reproduce it with but cannot reproduce with ". (Is the a typo?) But I think the autofix is wrong anyway.

maheshbansod commented 1 year ago

You're right, @yeonjuan , the " was a typo. Embarassd that I didn't notice it sooner :smile: I guess it's breaking for special characters then.

yeonjuan commented 1 year ago

It's bugs in es-html-parser. The parser produces incorrect location information.

스크린샷 2023-07-21 오전 12 32 25
yeonjuan commented 1 year ago

@maheshbansod It's fixed and released! (v1.9.1) Thanks!