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.

P2.x - Group HTML classes by prefix instead of forcing onto one line

See original GitHub issue

Unfortunately we cannot upgrade to 2.x until the change mentioned here: https://prettier.io/blog/2020/03/21/2.0.0.html#format-value-of-html-class-attribute-7555httpsgithubcomprettierprettierpull7555-by-fiskerhttpsgithubcomfisker

… is parameterized and made optional. This would seriously affect the readability and maintainability of our templates.

The reasoning behind the change given here: https://github.com/prettier/prettier/issues/5482 is:

An example of such an attribute is class, where class=" a b c " should be semantically equivalent to class="a b c". However, note that if the user is parsing element.className directly, this change is not safe. 

We do not parse className directly; we do, however, make extensive use of long BEM class names and of bootstrap.

Here’s a typical example:


<div class="ProviderMeasuresContainer__heading-row
            d-flex
            flex-column flex-lg-row
            justify-content-start justify-content-lg-between
            align-items-start align-items-lg-center"
...

vs.

<div class="ProviderMeasuresContainer__heading-row d-flex flex-column flex-lg-row justify-content-start justify-content-lg-between align-items-start align-items-lg-center"

You can see this greatly reduces the readability of the element. This leads to longer development and debugging cycles as information in some arbitrary position to the right of the viewing screen is the missing piece on why XYZ is styled incorrectly.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:34 (18 by maintainers)

github_iconTop GitHub Comments

3reactions
thorn0commented, May 1, 2020

Because, in general, Prettier never does that. I don’t feel strongly about that, would be good to hear other people’s thoughts.

E.g. look at this example: https://github.com/prettier/prettier/issues/7863#issuecomment-620914539

Looks like it’s important for the author that the lg:border-... classes are placed directly after border-....

1reaction
pburkindinecommented, Aug 13, 2020

@thorn0 just checking on this one

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS · Bootstrap
Global CSS settings, fundamental HTML elements styled and enhanced with extensible classes, and an advanced grid system. Overview. Get the lowdown on the...
Read more >
Could Grouping HTML Classes Make Them More Readable?
You can have multiple classes on an HTML element: ... like primary names and variations as one group, then utility classes as another...
Read more >
Selectors Level 4 - W3C
Selectors are patterns that match against elements in a tree, and as such form one of several technologies that can be used to...
Read more >
Content Configuration - Tailwind CSS
Configuring source paths. Tailwind CSS works by scanning all of your HTML, JavaScript components, and any other template files for class names, ...
Read more >
Grid layout using line-based placement - CSS - MDN Web Docs
The lines are numbered for columns and rows, and are indexed from 1. Note that grid is indexed according to the writing mode...
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