microsoft / vscode-html-languageservice

Language services for HTML
MIT License
219 stars 109 forks source link

Suggestion. Add option to allow using self-closing tag on all HTML elements. #189

Open Pentadome opened 3 months ago

Pentadome commented 3 months ago
<div/>

This is not valid HTML. The browser will act like the closing tag doesn't exist, like so:

<div>

And vscode will correctly mark it as wrong like so: image

But many html-like languages like Vue and JSX do allow self-closing tags, but vscode still marks it as wrong. It would be nice if we could allow all tags to be self-closed by setting a value in .vscode\settings.json

DominoPivot commented 2 weeks ago

The example you gave would cause an error in React because the DOM property is className, not class. JSX is not HTML, but an XML-like extension to JS that is processed into library code or DOM API calls.

Meanwhile, Vue allows for templates to be embedded in HTML, in which case they have to follow HTML syntax, and XML self-closing semantics do not apply in HTML as you pointed out (well, outside of foreign elements, like SVG).

In other words, VS Code is behaving as it should.

Pentadome commented 2 weeks ago

The example you gave would cause an error in React because the DOM property is className, not class. JSX is not HTML, but an XML-like extension to JS that is processed into library code or DOM API calls.

Meanwhile, Vue allows for templates to be embedded in HTML, in which case they have to follow HTML syntax, and XML self-closing semantics do not apply in HTML as you pointed out (well, outside of foreign elements, like SVG).

In other words, VS Code is behaving as it should.

Please read again. This is not a bug report.