question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

markup formatting - cost to overall structure readability very high

See original GitHub issue

Hi,

i am fully aware of Prettier’s option philosophy, but I still wanted to point something out that bugs me a great deal and that is that Prettier does not seem to acknowledge at all that there could be different format requirements for different languages/scenarios. I will try to give a small example of what I mean:

When you jump to a function in Java, you usually want to actually read the full code - Prettier is great for that!

Things are so very different when you are writing/reading markup (lets say HTML) though. One example of a div with multiple attributes (angular directives, style classes, aria-attributes and a data attribute). Prettier 2.7.1 Playground link

--parser html
--print-width 120

Input:

<div  ngIf="ability?.length > 0 && ! loading" myCustomDirective  data-cy="nav-header"
  class="col-lg responsive-input-wrapper d-flex align-items-center"
   tabindex="0" role="tooltip"  aria-label="Primary">
...

Output:

<div
  ngIf="ability?.length > 0 && ! loading"
  myCustomDirective
  data-cy="nav-header"
  class="col-lg responsive-input-wrapper d-flex align-items-center"
  tabindex="0"
  role="tooltip"
  aria-label="Primary"
>
  ...
</div>

Expected behavior: When reading HTML Code you are very rarely interested in all individual attributes. Far more often you are working on something where the general structure is more important than perfect readability of attributes. The Problem is that Prettier’s styling comes at a great cost to the readability of the overall structure. I’ve discussed this with multiple colleagues and we ended up agreeing that Prettier ends up creating HTML code that is actually were hard and frustrating to work on. It’s nice for simple examples, like a div with 2 attributes, but get’s very ugly quickly in more complex scenarios.

Coming back to the example: You can’t even fit 3 of those “vertical-space-monstrosities” on your actual screen! Working on the structure (e.g. change styles / classes) requires excessive scrolling and is very frustrating.

I think our biggest problem is with the “print width” - basically there are only 2 possible outcomes: a) the statement fits within the print-width - it’s collapsed into a single line (no matter if we wanted to break them up with newlines, but that’s another story) b) the statement doesn’t fit into the print-width: now it switches into “every attribute on a new line” mode There seems to be no option for any middle ground. The input-example above is an example of a possible middle ground. It adds manual linebreaks like so: a) Angular directives and other dynamic stuff go into the first line b) classes and styling go into the second line c) aria stuff in the third line

With that it is still reasonably easy to read attributes (especially since you know where to look for them) but you can still see and comprehend much more of the overall structure at once. I am not saying that Prettier should do THAT automatically, but is it really not possible to use sensible line-breaks, while still using Prettier? Why only the extremes? Please give us an option to let Prettier honor our linebreaks.

While I don’t agree with the options philosophy I do understand it. But doesn’t it go a bit TOO far? What the optimal code-style is is of course heavily opinionated - but formatting everything the same (Code and Markup) while completely ignoring the different requirements you have in reading the two seems a bit questionable to me personally.

Best regards, Mario

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
fiskercommented, Nov 24, 2022

It not clear to me what’s expected.

0reactions
matrium0commented, Nov 24, 2022

I would expect some options to prevent blowing up every html element to 12 lines- because as I mentioned this greatly reduces the readability of the overall structure - for the sake of improved readability of every single attribute (which unlike the structure you rarely need when editing markup code like HTML).

I would expect an option to either honor my newlines (as long as each line fits within the print-width) OR an option to prevent the “newline for each argument once print width is reached”.

The optimal code-style (let’s say it exists) between code and markup is vastly different and Prettier just bluntly styles markup the same as everything else - which leads to very hard to maintain HTML code

Read more comments on GitHub >

github_iconTop Results From Across the Web

SEO Content Readability: 5 Mistakes Your Plugin Won't Detect
Resist over-formatting; Link with mercy. Why HUMAN readability is important. As mentioned above, readability ranks. They say greater reading ...
Read more >
8 Tips for Better Readability - GetFeedback
So, to make sure your users are getting the most out of the content they do read, we've put together 8 guidelines to...
Read more >
Design for readability - Harvard's Digital Accessibility Services
Readability and legibility are key considerations for all users. For people with disabilities, these attributes can be essential to a successful user ...
Read more >
Intro to How Structured Data Markup Works - Google Developers
Google uses structured data markup to understand content. Explore this guide to discover how structured data works, review formats, and learn where to...
Read more >
A Primer on Machine Readability for Online Documents and ...
XML: (eXtensible Markup Language) A markup language that defines a set of rules for encoding documents in a format that can be both...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found