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

html-no-self-closing: Ignore components option #31

Closed
Akryum opened this issue Jun 17, 2017 · 7 comments
Closed

html-no-self-closing: Ignore components option #31

Akryum opened this issue Jun 17, 2017 · 7 comments

Comments

@Akryum
Copy link
Member

Akryum commented Jun 17, 2017

I think it is pretty common in Vue templates (for example inside .vue files, not in HTML page) to write self-closing component, for example: <ui-dropdown :options="options" />. It also don't cause any potential issue since the component will be rendered in HTML even before being put in the DOM thanks to the template compiler.

It would be nice if the recommended config had an option set to the html-no-self-closing rule to ignore non-HTML tags.

This should then be reported:

<div />
<ui-dropdown />

This shouldn't be reported:

<div></div>
<ui-dropdown />
@mysticatea
Copy link
Member

Thank you for this issue.

Sounds good to me.

Note: in beta, eslint-plugin-vue cannot handle self-closing as correct for Vue.js because it's pretty different to HTML. See also #29.

@michalsnik
Copy link
Member

@mysticatea are we good to fix this now with the new parser?

@mysticatea
Copy link
Member

Yes, we can go ahead.

As my comment before, I think a rule which has the option like below:

{
    "vue/html-self-closing": ["error", {
        "html": {
            "normal": "never",      // HTML elements. E.g. <div></div>
            "void": "never",        // HTML void elements. E.g. <img>
            "components": "always", // Vue.js components.
        },
        "svg": "always",
        "math": "always",
    }]
}
  • "always" ... Elements which don't have their content should be self-closing always.
    GOOD: <div/>
    BAD: <div></div>
  • "never" ... Elements should not be self-closing.
    GOOD: <div></div>
    BAD: <div/>
  • "any" ... no check.

@armano2
Copy link
Contributor

armano2 commented Aug 3, 2017

schema for this options

[
  {
    type: 'object',
    properties: {
      html: {
        type: 'object',
        properties: {
          normal: { // HTML elements. E.g. <div></div>
            enum: ['always', 'never', 'any'] // never
          },
          void: { // HTML void elements. E.g. <img>
            enum: ['always', 'never', 'any'] // never
          },
          components: { // Vue.js components.
            enum: ['always', 'never', 'any'] // always
          }
        },
        additionalProperties: false
      },
      svg: {
        enum: ['always', 'never', 'any'] // always
      },
      math: {
        enum: ['always', 'never', 'any'] // always
      }
    },
    additionalProperties: false
  }
]

@armano2
Copy link
Contributor

armano2 commented Aug 3, 2017

@mysticatea are you planing to work on this or should i do that?

i seen: vuejs/vue-eslint-parser@50814b3 - this is going to simplified this rule a lot 👍

@mysticatea
Copy link
Member

@armano2 Yeah, I'm working on this. I'm sorry that I didn't commented.

@michalsnik michalsnik added this to the Official release milestone Aug 3, 2017
michalsnik pushed a commit that referenced this issue Aug 8, 2017
* New: `html-self-closing-style` rule (fixes #31)

* add more tests.

* Docs: add replacedBy property to html-no-self-closing

* rename

* update for review
@molerat619
Copy link

I generally like <div></div> over </div> so I would like to use the rule accordingly. How can I turn that check off for certain tags like <img .../>, <br /> or <input ... />?

doug-wade pushed a commit to doug-wade/eslint-plugin-vue that referenced this issue Apr 17, 2022
…npm_and_yarn/javascript-package/core-js-3.22.0

Bump core-js from 3.21.1 to 3.22.0 in /javascript-package
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

5 participants