Skip to content

Rule proposal: html-tag-spacing #229

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

Closed
michalsnik opened this issue Nov 5, 2017 · 3 comments
Closed

Rule proposal: html-tag-spacing #229

michalsnik opened this issue Nov 5, 2017 · 3 comments

Comments

@michalsnik
Copy link
Member

As pointed in #199 html-self-closing rule fix end tags, but doesn't care about proper spacing before end tags. It is an intended behaviour as one rule should do just one thing.

However currently we don't have a rule that would make it possible to check and fix wrong spacing in HTML tags.

I propose to add a similar rule to: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md

Possible settings:

{
  "closingSlash": "never | always",
  "beforeSelfClosing": "never | always",
  "afterOpening": "never | always",
  "beforeClosingOpening": "never | always"
}

Incorrect

<!-- closingSlash: "never" -->
<input/ >
<div>< /div>

<!-- beforeSelfClosing: "always" -->
<input/>

<!-- afterOpening: "never" -->
< input />

<!-- beforeClosingOpening: "never" -->
<div ></div>

Correct

<!-- closingSlash: "never" -->
<input/>
<div></div>

<!-- beforeSelfClosing: "always" -->
<input />

<!-- afterOpening: "never" -->
<input />

<!-- beforeClosingOpening: "never" -->
<div></div>
@mysticatea
Copy link
Member

I think that afterOpening and closingSlash is not necessary.

  • < div> is just a text rather than a tag. Here, <div is one token and HTML disallows a space at between the < and the div. The no-parsing-error rule reports it as invalid-first-character-of-tag-name` error.
  • < /div> is same as above. </div is one token which cannot be separated.
  • <input/ > is an opening tag and the / is ignored. The no-parsing-error rule reports it as unexpected-solidus-in-tag error.

Those are the reason that I wrote vue/space-before-tag-closing in #199 (comment).

@michalsnik
Copy link
Member Author

Okay, so your proposition was to add vue/space-before-tag-closing rule with the following settings:

"vue/space-before-tag-closing": ["error", {
    "normal": {
        "afterTagName": "always"/"never",
        "afterAttributeName": "always"/"never",
        "afterEqual": "always"/"never",
        "afterAttributeValue": "always"/"never",
    },
    "selfClosing": {
        "afterTagName": "always"/"never",
        "afterAttributeName": "always"/"never",
        "afterEqual": "always"/"never",
        "afterAttributeValue": "always"/"never",
    }
}]

I think we could simplify this and keep two settings only.

  • normal: always/never (default never)
<the-component></the-component>
<the-component foo></the-component>
<the-component foo="bar"></the-component>
  • selfClosing: always/never (default always)
<the-component />
<the-component foo />
<the-component foo="bar" />

@mysticatea
Copy link
Member

I'm OK with the simple version.
I thought that somebody wants to use <the-component/> and <the-component foo="bar" /> at that time.

@mysticatea mysticatea self-assigned this Dec 31, 2017
michalsnik pushed a commit that referenced this issue Jan 2, 2018
* New: html-closing-bracket-spacing rule (fixes #229)

* fix description

* add the check of columns

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

No branches or pull requests

2 participants