4 ms·
Author here! I used to have strong feelings about formatting stuff like this, but I since realised there are better things to spend effort on. For formatting,
by jaffathecake 5y ago
Author here! I used to have strong feelings about formatting stuff like this, but I since realised there are better things to spend effort on.
For formatting, I just let https://prettier.io/ https://prettier.io/ do it's thing, and it added the />. Although I do configure it to use single quotes in JS, so I guess I still have some opinion there.
In terms of HTML, how far does your "but it isn't necessary" opinion go? Lots of closing elements are unnecessary in HTML, for instance, check out the source of https://fetch.spec.whatwg.org/ https://fetch.spec.whatwg.org/
- chrismorgan 5y agoWell, for my own personal stuff I omit just about all that I can—head/body start and end tags, html end tag (not start tag because it has at least a lang attribute), tbody start tag where possible, thead/tbody/tfoot/tr/th/td/li/dt/dd/p end tags almost all of the time, attribute value quotes where valid… mostly just because it’s fun doing so, and in some cases because it makes things decidedly cleaner (especially tables). I also don’t use autoformatters because I will often disagree with their opinions in specific cases. For stuff I’m working on with others, I’ll act more like a normal person, though I will still prefer to drop at least <head></head><body></body></html>, and I’ve never worked with anyone that wanted to put trailing slashes on void elements (and haven’t ever used Prettier on HTML, evidently). As for Prettier putting the trailing slash in: huh, that’s a really weird decision (and no flag for it!), given that they’re not emitting valid XML (not escaping >, at the least), so it’s just the personal preference thing, for something that was just added as an XHTML compatibility mechanism.
- jaffathecake 5y agoSeems like your HTML formatting opinions are very similar to the owner of the fetch spec! Yeah, I don't always agree with Prettier, but ugh, I wasted hours in my early career arguing about formatting with teammates, but now I just let Prettier do it's thing, get over it, and spend the time on something else.
- chrismorgan 5y agoHence me only living life on the edge like that in personal projects! Most of what I write with others these days is in Rust, and I definitely go along with using rustfmt on such projects, even if I regularly dislike its opinions (sometimes even strongly).
- jaffathecake 5y agoIf you're interested, the discussion rages on in https://github.com/prettier/prettier/issues/5246 https://github.com/prettier/prettier/issues/5246
- floppydiskette 5y agoThis is the way! I used to get annoyed by unnecessary trailing slashes, but it’s really a non-issue. Not to mention it’s required in JSX anyway.
- adminscoffee 5y agovery cool, wish dart/flutter made the list.