Open UnknownPlatypus opened 1 month ago
This must be behind a configuration option, but I'm not sure its naming.
This must be behind a configuration option, but I'm not sure its naming.
Maybe preferSingleLineOpeningTag
/preferSingleLineTag
because the same type of behavior could be nice for tags with no attributes at all. The flag could cover both cases.
For example, markup_fmt
currently wrap tags for the following snippet with small print width and I'd like to do a followup PR to avoid that and keep the snippet unchanged.
-<html>
- <body>
- </body>
-</html>
+<html
+>
+ <body
+ >
+ </body
+ >
+</html
+>
I added a configuration option and updated the tests accordingly. I went for preferSingleLineOpeningTag
for now, let me know if you want something else when you find a good naming for such option. I'll update the PR.
I set the default value to the current behavior, we could eventually do the opposite if you want to promote the new behavior.
Opening tags with a single attribute exceeding line width are wrapping but it's not really helping readability and adds a lot of vertical space (especially when nested). I added a bunch of test cases to showcase the formatting causing some churn on my work codebase (see the first commit).
This patch try to keep an opening HTML tag with a single attribute on a single line when applicable. This was really successful for me on my work codebase (~2k html files, 250k LOC, using mostly BEM classes or tailwind classes) with over 300 files fixed with clear readability wins!
Prettier suffer from the same issue (see https://github.com/prettier/prettier/issues/10918#issuecomment-971629374) and because of that, the tailwind team (and others) are using some crazy
printwidth
to workaround this behavior.It could maybe be behind a configuration flag like
keepSingleAttrOnSingleLine
or any other better naming you find. Let me know if I should add such flag.