Prettier doesn't break template literals, but it will break non-literal sections of template strings. For example, if we wrote this:
const foo = `aaaaaaaaaaaaaaa${bbbbbbbbbbbbb}ccccccccccccccc${ddddddddddd}`;
prettier would fix it to const foo =
`aaaaaaaaaaaaaaa${
bbbbbbbbbbbbb
}ccccccccccccccc${
ddddddddddd
}`;
Which is not only much harder to read in it's own right, but now takes up 6 lines instead of one!Just needs another maintainer's stamp.
For the same reason, it often makes code written using composition more difficult to read since it won't let you decide when to put a sub-call on its own indented line for clarity.
I am sad it's not getting more popular
I do this occasionally, and especially with things like test tables. Linters/formatters are there to help in the common case, not to be some oppressive dogma.
I think rustfmt will actually also widen code you have put newlines in sometimes. But it's heuristic is somehow much better than prettier's.
So the whole "extremely opinionated, if you want configuration go somewhere else" is great in principle, when people are choosing to use the tool. But if it becomes the only option for certain swathes of users, a touch more configuration would really be appropriate.
If prettier worked more like gofmt I'd probably love it and have no complaints!
Wait, so prettier rewrites code incorrectly? Aka, it’s buggy?
// before prettier
var matrix = [
1, 0, 0,
0, 1, 0,
0, 0, 1,
]
var result = (num % divisor) | bitmask
// after
var matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1]
var result = num % divisor | bitmask
No difference in actual behavior, but the linebreaks and extra parens were there to indicate the developer's intent, not to affect behavior.Prettier's outlook is that this is intentional, and the developer should add "// prettier-ignore" comments to every line of code that has semantic information they want preserved.
This the same code, but I often use parens for semantic grouping or to be 110% sure the operator precedence is correct for a particular formula. It's not a dealbreaker, but it does remove some of the meaning I was trying to imbue on the code.
Besides that, I get the impression being a universal standard is kind of a non-issue for Prettier:
- If it was widespread, but highly configurable, that increases friction when switching projects, because there will be tiny formatting differences everywhere
- If it was not widespread, it would not be well known, increasing friction for users entering a project where it was used
This is clearly not true. Far and away the single most contentious JS style issue is ASI, and prettier has a config option for it and nobody bats an eye. Ditto for the prototypical style issues of indent size and tabs/spaces.
The value of prettier is enforcing a consistent style within a repo, and config options don't affect that. To the contrary, config options are part of why prettier is so popular - if they'd never added ASI then a lot of projects would never have adopted it.
Erm, that bounty was for the production of a program that behaves exactly like prettier in at least 95% of cases, as far as I understood what "prettier test suite" means.
Prettier will affect your diff in ways you didn't intend to.
Remove a member from a destructuring assignment that brings it below the line length limit, and suddenly your diff is +1/-5 instead of 0/-1, making it slightly more difficult for your reviewer to see what the exact difference is between those 5 lines removed and 1 line added - it's not immediately clear which member was removed.
You try to rewrite a previous commit to fix a typo using Git's interactive rebase, and now the next commits won't replay on top if it because Prettier decided to reformat an entire code block.
Another fun thing to try with prettier: add a precommit hook that runs prettier, and then try to stage partial file changes.
No thanks.
It treats new lines as significant in a lot of its formatting
How do you even justify that...