Automatic class sorting with Prettier (2022)
tailwindcss.com
tailwindcss.com
[0] https://biomejs.dev/ [1] https://github.com/biomejs/biome/pull/1362
The performance comparison on Biomejs’ site shows a Prettier run taking 14 seconds, which I can imagine on a very large code base might be true - but that’s a one-off case surely? Once it’s run, it’s just a case of format on save or commit which is back to near-instantaneous.
What’s the use case I’m missing here?
But still, formatting changed files on commit, even on CI ought to be a fraction of a second.
Biome can also format malformed code. It supports formatting as you type.
Biome has less known non-idempotent formatting (For some edge cases you need to run twice Prettier to get a stabilized output).
Biome is also a linter. You get two tools that are closely compatible.
Really like that they don't give options to change the settings. Just one less thing to bike shed within teams. Really doesn't matter what is picked, just as long as it is consistent (and not obviously stupid).
- https://prettier.io/docs/en/why-prettier - https://prettier.io/docs/en/option-philosophy
I switched to Rome (now Biome) after this debacle: https://github.com/prettier/prettier/issues/840
As to whether they do make obviously stupid choices - I personally don't mind any of their choices (even if I wouldn't have made the same choice myself), and I know I'm not alone in this position, which means that by definition they're not "obviously" stupid. You can disagree with the choices and the trade-offs, sure, that doesn't make it obviously stupid.
I also completely disagree with your reasoning above.
The fact that many people believe or do some thing does not mean that “by definition” that that thing is not obviously stupid. E.g., inhaling glue, smashing things with one’s head, “the secret”, mukbang videos… the list is nearly endless.
Finally, “the principle” behind Prettier is also flawed when taken to the extreme they do. Paraphrasing my final comment on the github issue,
> It can be used to defend literally any styling choices, even ones that deliberately misaligned conditional branches with others at its logical level (much like prettier already is doing on a small scale in the example I referenced).
> Yes human beings are adaptable, but some things are easier to adapt to than others. It's objectively easier to spell Spanish than English, for example. It pays off to have consistency at a deeper level than simply making the same idiosyncratic choices each time an identical situation comes up.
https://github.com/prettier/prettier/issues/840#issuecomment...
Consistency has more value than the subjective advantage of the proposal that you're comparing to the objective advantage of being phonetic. I think the prettier maintainers made the right choice.
Random user: Your software is unacceptable; add an option to my favorite subjective preference!
I wonder, are those people trolling?
Ultimately, the solution is to use Biome or another formatter instead, but many devs have Prettier forced on them at work.
What you don't do is insist the developer adds the option. Even if you feel like the developer is more approachable than your boss.
It’s a dishonest characterization of the issue thread to imply that it was its nature. People shared discussed the problem with the tool’s behavior, shared examples and motivations.
Prettier’s (IMO wrong) decision was theirs to make but the response was also gratuitously smug.
If the knife storage had been opinionated, we would have expended no effort and achieved consistency. The choice of direction was essentially arbitrary, but making a choice and sticking to it was valuable.
The ‘original’ quote, from someone explaining why gofmt has no configuration options is:
> The usual saying is that gofmt isn’t anybody’s preferred style, but it’s adequate for everybody.
And the interpretation from someone asking about configuring some aspect of it is (emphasis mine):
> The usual saying is that gofmt isn’t anybody’s preferred style, but it’s adequate for everybody who still using it
Being opinionated about defaults is often a positive thing. Removing any options just makes your tool less useful.
value = (a ? ((a * b) + c) : d);
It turns into: value = a ? a * b + c : d;
This is just a very basic example, there are many situations where the result is way worse. I feel pretty confident in saying that this is quite obviously stupid.Which order do they do it in? Later classes are later in the css so more likely to be applied?
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
> If the competing selectors have the same values in all the three columns, the proximity rule comes into play, wherein the last declared style gets precedence.
I’m well aware of how css works, I’ve been here since we did table layouts with shims!
Maybe we could write a formatter plugin in Elixir that does the same thing if this one isn't usable directly.
It saddens me to see people new to web development don't realize that to deploy a webpage, all it takes is just uploading (SFTP) a single .html file onto a web server.
Nothing more is technically required than that, but we've made it so complex you'd never know.
Deploy it to what? How? Via what? Who is managing it? Who is paying for it? Who physically installed the server, and setup your ability to DrawTheRestOfTheHTML?
Personally - while we want abstraction in our deployment understandings to smooth ramp understanding - its important to see all the supporting inputs that made your SFTP of an .html possible.
>>I once saw him teach a philosophy lesson about a pencil. A Fuckin' Pencil!
Yes, it's unfortunate that new developers don't know the basics. However, that's not an option for a multi-page site with complex user interactions.
There's no point in complaining about new tools being created which serve a need. If it makes someone's job easier when they're creating complex web apps, it's a good thing.
I guess you can get away with that because a tool can follow those rules.
But man, I <3 alpha sort.
But then I'm so old school I prefer just putting the CSS in the CSS, or even the `style` attribute. (I must say I do appreciate the pseudo-class support in tailwind.)
https://github.com/validator/validator/wiki/Markup-%C2%BB-Vo...
What do you mean by "never been specified"? They are in the spec: https://www.w3.org/html/wg/spec/syntax.html#start-tags
> Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.
[1] https://html.spec.whatwg.org/dev/input.html#the-input-elemen...
You will never find any HTML specification which will tell you a closing slash is required or that it has any meaning or does anything at all.
And the link you provided is specifically for the input tag, which has nothing to do with the syntax definition in general. Why would they repeat a generally applicable rule in more specific sections?
You also need to read up on what a foreign element actually is and it's not HTML.
Many people, myself included, prefer to have code that is easily parseable (both mentally and by a program) without requiring a lookahead or awareness of a list of special elements. A slash for self-closing elements achieves that. It just makes sense. Can you imagine JSX allowing this?
Though something is allowed, it is unspecified, not required, does nothing. So why would you want to write markup that is not needed and does nothing? This makes no sense whatsoever and I only find such discussions on public forums such as this one.
Do you add quotes to your single-word attribute values? Why? They are also unnecessary following the spec: https://html.spec.whatwg.org/#unquoted
Do you omit the opening html tag because it's optional? https://html.spec.whatwg.org/#optional-tags
Do you write unclosed <dd> tags? Do you close your paragraph elements?
The spec allows a lot of questionable styles, your argument that because something is not required it is superfluous doesn't hold any water.
The comments section of the guidelines offers some good rules of thumb: https://news.ycombinator.com/newsguidelines.html
I'm wondering why you are so triggered by that issue that you have to bring it up in a context where its off-topic (it could be brought up on any post related to Prettier).
The validator Wiki page even highlights that it's essentially a non-issue, except for interactions with unquoted attributes, which Prettier also converts to quoted attributes, so that interaction never happens. The other reason is for "teaching the wrong" mental model, which I guess is fair from the position of MDN, but Prettier was never designed as a "teaching formatter".
And if you, even with all that context want to opt-out of that formatting, there is a community-maintained plugin that adjusts the formatting to how you want it: https://github.com/awmottaz/prettier-plugin-void-html
Hope you never get tripped up by the "except for".
People were mixing XML and XHTML with HTML before React and got themselves into trouble.
Why are you so triggered by someone who thinks people should just follow the standard and not write unnecessary markup/code? That is a programmer's worst nightmare but people here seem to support it.