Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling "smart formatting" of HTML class attribute #10918

Closed
luukdv opened this issue May 20, 2021 · 87 comments
Closed

Disabling "smart formatting" of HTML class attribute #10918

luukdv opened this issue May 20, 2021 · 87 comments
Labels
help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! lang:html Issues affecting HTML (and SVG but not JSX) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:enhancement A potential new feature to be added, or an improvement to how we print something

Comments

@luukdv
Copy link

luukdv commented May 20, 2021

"We get a lot of requests for adding options, but Prettier is built on the principle of being opinionated about code formatting."

I totally understand this, and so I apologize beforehand for opening this issue. The reason I think this is a valid issue is because the opinion about this seems to have changed from the perspective of Prettier, even though it was mentioned that there's no community interest for this change (and a lot of pushback) in the introducing pull request.

The issue
When using frameworks like Tailwind, readability has lowered drastically since this feature:

References

I'd love to still be able to use Prettier, but this is a blocking issue for me and many others.

The solution
Respecting the class attribute to stay on a single line, and only applying formatting it when a user already has a multi-line approach for class. Alternatively, an option to disable this feature.

Thanks in advance for considering this!

@thorn0 thorn0 added lang:html Issues affecting HTML (and SVG but not JSX) status:needs discussion Issues needing discussion and a decision to be made before action can be taken labels May 20, 2021
@thorn0
Copy link
Member

thorn0 commented May 20, 2021

Respecting the class attribute to stay on a single line, and only applying formatting it when a user already has a multi-line approach for class.

This sounds like a good trade-off to me, but probably it can be improved. I guess developers who don't use Tailwind and have longer class names would prefer to keep the new behavior. So can Prettier probably somehow detect whether a single-line class attribute is "Tailwind-like"?

@alexander-akait
Copy link
Member

@luukdv

Respecting the class attribute to stay on a single line, and only applying formatting it when a user already has a multi-line approach for class. Alternatively, an option to disable this feature.

just interesting, what is the problem with multi line, I found it more readable

@tkalmar
Copy link
Contributor

tkalmar commented May 20, 2021

I find the single line approach problematic when having many classes (like in a tailwind app with multiple breakpoints)
The big advantage i see is diffability (is this even a word?) i see clearly which classes are changed when i look at the diff.
There are multiple approaches i can imagine:

  • don't switch style either single line or multiline warn if mixed at most
  • leave class as is. we use multiline approach to group matching classes for different breakpoints, some group by prefix ... it is very hard to find a OOB solution which fit's all needs
  • make the grouping configurable/pluggable so i can enforce multiline but decide which classes are kept together (the current solution with a little bit more flexibility

@thorn0
Copy link
Member

thorn0 commented May 20, 2021

it is very hard to find a OOB solution which fit's all needs

Nonetheless, I'd say we're almost there because so far looks like the current OOB solution is good enough for everyone else except Tailwind users. So we only need to find a way to improve it for Tailwind.

@luukdv Could you please replace the image in your post with a code block, so that it would be easier to experiment with reformatting that code?

@thorn0
Copy link
Member

thorn0 commented May 20, 2021

Just another brain storm comment, how about grouping all ungrouped classes at the end of the class list, after all the prefixed groups (only if there are prefixed groups)?

foo
bar
baz-one baz-two baz-three
qux-one qux-two
quuux lorem-ipsum bla-bla

@tkalmar
Copy link
Contributor

tkalmar commented May 20, 2021

Sometimes there are different needs/preferences
Sort similar properties together

foo
bar
baz-one md:baz-one-12 xl:baz-one-22
baz-two md:baz-two-12 xl:baz-two-22

vs. keep properties for the same purpose (in this case breakpoint) together

foo
bar
baz-one baz-two baz-three
md:baz-one-12 md:baz-two-12 md:baz-three-12

Perhaps a viable solution is to break it into single chunks if the line is to long, and leave it as is as long as line length is not exceeded.
So it would initialy break all classes on a single line, and leave them alone after the grouping through the developer, still i need to touch every single file, where this happens, but afterwards i have a workable solution.

@luukdv
Copy link
Author

luukdv commented May 21, 2021

I found it more readable

@alexander-akait I guess it's a matter of preference then. For me, if I consider the following:

[...]

<div class="grid grid-cols-2 sm:grid-cols-3 gap-2 sm:gap-4 md:gap-8 max-w-screen-xl mx-auto px-5 sm:px-10">
  <a href="" class="relative bg-gray-200 group block transform border-2 border-white rounded-lg">
    <img src="" alt="" class="z-10 object-cover absolute top-0 left-0 w-full h-full block h-auto w-full" />

    <div class="absolute z-30 overflow-hidden hidden lg:flex flex-col font-medium justify-center text-white px-8 top-0 left-0 w-full h-full transition-opacity ease-cubic duration-400 opacity-0 lg:group-hover:opacity-100">
      <p class="mb-4 last:mb-0 text-gray-800 italic inline-block text-sm px-2 leading-relaxed z-10">
        Some text
      </p>
    </div>
  </a>
</div>

[...]

I'd see what's going on HTML-wise at a glance. With the new approach, it's less readable, especially since there's even more of these blocks above and below:

[...]

<div
  class="
    grid
    grid-cols-2
    sm:grid-cols-3
    gap-2
    sm:gap-4
    md:gap-8
    max-w-screen-xl
    mx-auto
    px-5
    sm:px-10
  "
>
  <a
    href=""
    class="
      relative
      bg-gray-200
      group
      block
      transform
      border-2
      border-white
      rounded-lg
    "
  >
    <img
      src=""
      alt=""
      class="
        z-10
        object-cover
        absolute
        top-0
        left-0
        w-full
        h-full
        block
        h-auto
        w-full
      "
    />

    <div
      class="
        absolute
        z-30
        overflow-hidden
        hidden
        lg:flex
        flex-col
        font-medium
        justify-center
        text-white
        px-8
        top-0
        left-0
        w-full
        h-full
        transition-opacity
        ease-cubic
        duration-400
        opacity-0
        lg:group-hover:opacity-100
      "
    >
      <p
        class="
          mb-4
          last:mb-0
          text-gray-800
          italic
          inline-block
          text-sm
          px-2
          leading-relaxed
          z-10
        "
      >
        Some text
      </p>
    </div>
  </a>
</div>

[...]

Could you please replace the image in your post with a code block, so that it would be easier to experiment with reformatting that code?

@thorn0 Sure thing:

<div
  class="
    rounded-t
    lg:rounded
    overflow-hidden
    border
    border-gray-200
    group-hover:border-transparent
    group-hover:ring-2
    ring-offset-2
    ring-secondary-500
    object-cover
    w-full
    h-full
    absolute
    inset-0
    cursor-pointer
    z-1
  "
/>

<div
  class="
    bg-secondary-500
    text-white
    cursor-pointer
    hidden
    lg:block
    lg:invisible
    lg:group-hover:visible
    rounded
    shadow-lg
    px-6
    py-2
    font-medium
    absolute
    position-center
    z-3
  "
>
  <span>View</span>
</div>

<div
  class="
    lg:hidden
    bg-white
    bg-opacity-90
    rounded
    shadow-lg
    px-2
    py-1
    text-sm
    font-medium
    absolute
    right-[5px]
    top-[5px]
  "
/>

@alexander-akait
Copy link
Member

@thorn0 looks reasonable to have this in one line

@vinayakkulkarni
Copy link

vinayakkulkarni commented May 21, 2021

Firstly, thanks for improving DX by bringing such brilliant features in prettier! Cheers!

Right now, I'm facing issues while saving the code.. + S causes the linted file to revert the css classes, have to again run the linter manually to save the styles as per the new prettier "smart formatting" rules. Demo:

Screen.Recording.2021-05-22.at.1.27.54.AM.mov

There could/should be a way one can turn this feature on or make it work with the eslint-plugin

//edit: The issue was caused due to Headwind heybourn/headwind#127, disabling headwind fixes the smart formatting <3

@Shahaed
Copy link

Shahaed commented May 23, 2021

I found it more readable

@alexander-akait I guess it's a matter of preference then. For me, if I consider the following:

[...]

<div class="absolute z-30 overflow-hidden hidden lg:flex flex-col font-medium justify-center text-white px-8 top-0 left-0 w-full h-full transition-opacity ease-cubic duration-400 opacity-0 lg:group-hover:opacity-100">
  <a href="" class="relative bg-gray-200 group block transform border-2 border-white rounded-lg">
  </a>
</div>

[...]
[...]

<div
  class="
    grid
    grid-cols-2
    sm:grid-cols-3
    gap-2
    sm:gap-4
    md:gap-8
    max-w-screen-xl
    mx-auto
    px-5
    sm:px-10
  "

[...]

I would say the HTML is much easier to read in the first example while the css is much easier to read in the next. I think this a tough problem for many Tailwind users (myself included).

Netlify solution was to go multiline css so I don't think all tailwind users agree this "smart formatting" is "bad". Tough problem however.

My proposed solution would be what Prettier has already implemented on multi lined objects: https://prettier.io/docs/en/rationale.html#multi-line-objects (i.e. if a newline exists, make multiline, else single line up to the line length).

I believe this would keep everyone happy? And best of all no added options :)

And if people still have a gripe, once #5919 gets attention, it would be a simple plugin to reverse this behavior.

@sabberworm
Copy link

sabberworm commented May 27, 2021

I, too, am blocked from upgrading to 2.3.0 because of #7865. We use HTL (formerly Sightly), a templating language based on HTML. Unfortunately we use quite a few expressions in the class attribute, e.g.:

<div class="cmp-accordion__button${item.name in accordion.expandedItems || accordion.extendedItems.size == 1 ? ' cmp-accordion__button--expanded' : ''}"></div>

which prettier 2.3 will reformat as

<div
	class="
		cmp-accordion__button${item.name
		in
		accordion.expandedItems
		||
		accordion.extendedItems.size
		==
		1
		?
		'
		cmp-accordion__button--expanded'
		:
		''}
	"
></div>

@adamwathan
Copy link

adamwathan commented May 30, 2021

Just wanted to share my two cents from the Tailwind team — I think there are definitely interesting things that could be done formatting-wise but I worry it's going to be hard to do within Prettier itself because I think the best solutions require more semantic knowledge of the classes being used.

I can say my personal preference would be that Prettier did nothing with the class attribute, but if it's going to do anything I would really prefer if it doesn't do anything to the order of the classes. Lots of folks in the community use tools like Headwind to sort their classes for them in a Tailwind-aware way, and we really want to build functionality like this into our own editor extension as well in the near future.

Personally I've always been very satisfied with just enabling word-wrap in my editor, but totally get that others like to have things split up.

Is this a big issue for people outside Tailwind projects? If not, maybe our team could prioritize working on a Tailwind plugin for Prettier and make that the solution vs. forcing Prettier to care too much about Tailwind's naming conventions and stuff?

If there are any questions I can answer or input I can provide that would be helpful please let me know! Absolutely love Prettier and really appreciate the work of everyone that contributes to this project. Especially grateful that people are taking it upon themselves to try and come up with solutions to stuff like this long class attribute problem and that people are taking Tailwind into consideration when working on it ❤️

@royeden
Copy link

royeden commented Jun 3, 2021

Hi!

Adding a comment regarding the impact of this prettier feature inside of Vue 2 (using laravel and laravel mix, with "laravel-mix": "^6.0.19", and "vue-loader": "^15.9.7", "vue-template-compiler": "^2.6.12" ):

Vue is processing everything inside of class as plain text and printing it like that straight to production, making our classes occupy much more precious bytes than they should:

{staticClass:"\n          flex\n          items-center\n          font-bold\n          uppercase\n          text-h6\n          focus:outline-none\n        "} //          Yep, that's 10 individual space chars per class :(

This happens regardless of the configuration of whitespace preservation in webpack.mix:

mix.vue({
  options: {
    compilerOptions: {
      whitespace: "condense", // still doesn't condense classes :(
    },
  },
});

Therefore, having the option to disable this feature would solve cases where compilers interpret anything as plain text.
At least having the alternative of flexibility regarding this preference, in a similar fashion of quote styles or semicolons.

Thank you :)

@thorn0
Copy link
Member

thorn0 commented Jun 4, 2021

Thanks for the feedback. For now, the plan to improve this situation is to apply the new formatting only if:

  • there already is a line break in the class attribute OR
  • any of the classes contains -- or __ as separator (Tailwind doesn't use them) AND the parser isn't vue

@adamwathan

If there are any questions I can answer or input I can provide that would be helpful please let me know

How does the plan above sound to you? The idea is to keep this new behavior at least for some developers that don't use Tailwind. I noticed that Tailwind doesn't use -- and __ whereas long class names in code examples provided by those who requested this feature often contained this separator. Any other ideas on how we can detect Tailwind?

but if it's going to do anything I would really prefer if it doesn't do anything to the order of the classes

Prettier never reorders anything. It's one of the project's principles.

Is this a big issue for people outside Tailwind projects?

The answer seemed to be no, but turns out there is also an issue with Vue (not sure how big it is, see the previous comment).

maybe our team could prioritize working on a Tailwind plugin for Prettier

Unfortunately, Prettier currently lacks an API for such a plugin. We have an open issue about that: #10803 If your team could help us with moving that issue forward, it'd be awesome.

I know there already exist multiple Tailwind plugins for Prettier, but they use hacks instead of the official API and thus are fragile. E.g., such plugins conflict with each other. We need a real solution for this.

@thorn0 thorn0 added type:enhancement A potential new feature to be added, or an improvement to how we print something help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! and removed status:needs discussion Issues needing discussion and a decision to be made before action can be taken labels Jun 4, 2021
@royeden
Copy link

royeden commented Jun 4, 2021

@thorn0 Any fix is welcome :D !

I'm not familiar with how prettier works under the hood, so I have to ask: is that approach easier than adding a config option for this feature? Or is it easier to validate it on a case by case relying on the parser and syntax?

I ask this because the issue could be affecting other users with other stacks, for example this comment about htl on the tread from @sabberworm .

Thank you for your response :)

@adamwathan
Copy link

@thorn0 Thanks for the update!

For now, the plan to improve this situation is to apply the new formatting only if:

  • there already is a line break in the class attribute OR
  • any of the classes contains -- or __ as separator (Tailwind doesn't use them) AND the parser isn't vue

What do you think about simplifying this and only applying the formatting if the class attribute already contains a line break? To me that feels a lot simpler than having a very specific rule about double dashes or double underscores, and makes it very easy for people to opt-in to the behavior if they prefer it, and would be very learnable/easy-to-understand what's triggering that formatting without having to read any documentation or anything to learn about the special -- case.

@alexander-akait
Copy link
Member

What do you think about simplifying this and only applying the formatting if the class attribute already contains a line break?

It is not heuristically, and kills the whole point of formatter

@adamwathan
Copy link

That is what was recommended by @thorn0 though, no?

Thanks for the feedback. For now, the plan to improve this situation is to apply the new formatting only if:

  • there already is a line break in the class attribute OR
  • any of the classes contains -- or __ as separator (Tailwind doesn't use them) AND the parser isn't vue

If their suggestion is against the philosophy of Prettier that is okay but it was not my suggestion, I was only suggesting to not base it on the presence of -- or __.

@alexander-akait
Copy link
Member

Maybe #10803 is real good solutions without any hacks...

@thorn0
Copy link
Member

thorn0 commented Jun 4, 2021

@adamwathan

would be very learnable/easy-to-understand what's triggering that formatting without having to read any documentation or anything to learn about the special -- case

The idea is to make it "just work" for everybody without a need to read anything. My hypothesis is that people with these long class names with -- and __ never want long single-line class attributes.

@royeden

is that approach easier than adding a config option

Not adding options is an important principle of Prettier. See https://prettier.io/docs/en/option-philosophy.html
We're always open to discussing heuristics though (e.g., the case with HTL is easily fixable by special-casing {).

@iKlsR
Copy link

iKlsR commented Jun 6, 2021

My hypothesis is that people with these long class names with -- and __ never want long single-line class attributes.

I agree with Adam regarding only considering the linebreak as that should be a good enough indicator of user intent. I personally don't want prettier to mess with my class strings at all. If I want to see everything I'll toggle wrapping in my editor, if you're already dealing with monster html horizontal scrolling is oft inevitable. Thanks for your hard work on this project and hope I don't come off as entitled or rude, cheers.

@thorn0
Copy link
Member

thorn0 commented Jun 7, 2021

@iKlsR One of Prettier's principles is to leave as little as possible up to the user and another one is formatting reversibility. If we can't fully stick to them in this case, we should at least try to minimize the digression. If we can prevent at least some nitpicky PR reviews like "please add a line break here for Prettier to reformat these classes", we should do this. BTW, do you use Tailwind? Do you use -- and __?

@alexander-akait
Copy link
Member

@adamwathan

Keeps classes on one really long line if the class string contains no newlines.

I'm afraid this is not a good idea, we must not rely on user input, we should rely on string length, as you can see some examples are very long and it is not readable...

@adamwathan
Copy link

@alexander-akait Hey Alexander!

I'm afraid this is not a good idea, we must not rely on user input, we should rely on string length, as you can see some examples are very long and it is not readable...

This is how Prettier behaved prior to this recent change though, it never added newlines into classes for you.

It did this:

<!-- Input -->
<div class="mt-8 w-full bg-indigo-600 border border-transparent rounded-md py-3 px-8 flex items-center justify-center text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
  Hello world
</div>

<!-- Output -->
<div
  class="mt-8 w-full bg-indigo-600 border border-transparent rounded-md py-3 px-8 flex items-center justify-center text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
>
  Hello world
</div>

...so the class list stayed as one long string (which I think is good), but it moved the actual attribute to its own line (which I personally don't think is useful).

The major complaint here (and the reason this issue was opened) is that generally people (myself included) seem to prefer the really long class names staying on one line, because breaking it up onto multiple lines makes templates very difficult to work with because every HTML element can take up like 12 lines in your editor.

The comment here about "styles are collapsed by default" is relevant:

#10918 (comment)

For our HTML stuff at Tailwind Labs we are pinned to Prettier 2.2 and actually set printWidth to 10000 to get the behavior we want where the class attribute stays on the same line, haha... Unfortunately this is a bad setting when working in JSX though, so there we are just pinned to 2.2 and deal with class being put on its own line unnecessarily.

@fenilli
Copy link

fenilli commented Nov 17, 2021

@adamwathan

Keeps classes on one really long line if the class string contains no newlines.

I'm afraid this is not a good idea, we must not rely on user input, we should rely on string length, as you can see some examples are very long and it is not readable...

If user input is not a desired behaviour, you could instead break the lines based on print width, so instead of having 20 lines it would be like 4, that is much more manageable, unless there is already a break so we know that the user wants the behaviour of breaking those lines, falling down to @adamwathan ideas.

@alexander-akait
Copy link
Member

@adamwathan So the main problem is a lot of lines inside the class attribute that interfere with readability?

@adamwathan
Copy link

@alexander-akait Yeah correct, I think the community finds the code on the right much more manageable than the code on the left:

image

@alexander-akait
Copy link
Member

@adamwathan Yep, sounds reasonable

@thorn0 @sosukesuzuki @fisker Thoughts?

@fabd
Copy link

fabd commented Nov 17, 2021

(...) is that generally people (myself included) seem to prefer the really long class names staying on one line

I agree and it's worth considering most code editors have "word wrap" feature, so editing a long line of class attributes isn't too bothersome.

Interestingly ; I never even paid attention before ; but both VSCode and Sublime Text even re-indent after wordwrap even through it is a single line:

Screenshot 2021-11-17 at 17 03 19

This is how Prettier behaved prior to this recent change though, it never added newlines into classes for you.

There are several updates if that helps related to the change of behaviour:

@fisker
Copy link
Member

fisker commented Nov 18, 2021

I think we can just revert #7555 and #7865 to make things simple.

@lkj4
Copy link

lkj4 commented Nov 18, 2021

prettier's philosophy is not about respecting deliberately set newlines, this is too much mental drain. just let prettier do the change without being directed by the users or some newlines within the class attribute. I want opinionated defaults.

to the comparisons between one class per line vs all in one line, this comparisons are jarring, there is still some middle ground between these options.

I think the maintainer should decide on its own. prettier is for a reason popular, because this guy made smart design choices in the past.

@lkj4
Copy link

lkj4 commented Nov 18, 2021

@alexander-akait Yeah correct, I think the community finds the code on the right much more manageable than the code on the left:

you should compare to wrapped at print width not all in one line, then people would vote differently

@klodoma
Copy link

klodoma commented Nov 18, 2021

Why not just sort the classes and wrap them at printWidth?
I think most people are bothered by the multiple EOLs that are introduced and not by the fact that the classes are wrapped in 2 or 3 lines.

I think these examples would fit well within 2 lines.

@alexander-akait Yeah correct, I think the community finds the code on the right much more manageable than the code on the left:

image

@leodr
Copy link

leodr commented Nov 20, 2021

Why not just sort the classes and wrap them at printWidth? I think most people are bothered by the multiple EOLs that are introduced and not by the fact that the classes are wrapped in 2 or 3 lines.

I think these examples would fit well within 2 lines.

@alexander-akait Yeah correct, I think the community finds the code on the right much more manageable than the code on the left:
image

I don’t think sorting them in any automated, non-framework-specific way makes sense, especially when using atomic CSS like Tailwind. There you would much rather group related classes like p-4 and m-4 than having them alphabetically ordered.

@lkj4
Copy link

lkj4 commented Nov 24, 2021

Guys, guys, let's make small steps: Talking about reordering and word-wrapping is too much at once. These are two different features with entirely different requirements. I'd suggest to find an agreement, first, on the word-wrapping and once we are there we can think about reordering (if at all since reordering is something not really in the realm of prettier), ok?

For the sake of simplification, we have currently two parties in this thread:

🎄 The Xmas-Tree Hardliners (one class per line)

  • good: nice git diffs [1]
  • con: ultra bloated components looking like xmas all the year with gazillions LOC, but good for your perf review haha

🥞 The Pancake Party (just wrap at print width and intend next line accordingly)

  • good: keeps code nice and compact

Did I miss any party? If not, let's start to find an agreement just on this topic before we move on to reordering, ok?

We could now vote somehow but since everybody will start to give reasons, mark you reply with the respective emoji ONCE, so we can quickly see and search the 'votes'/emojis, if you think we need more option, add them with a new emoji!!

@thorn0 I think you got fed up with this thread, but let's at least try to get closer to some solution. The current state of matters is really hard to work with. Thanks!

[1] i find this pro really negligible, I never really read git diffs of some css classes, just to start the discussion already

@bodograumann
Copy link

The third option is (as a first simple step at least) to revert and go back to leaving class strings alone, like @fisker suggested.
I also think if voting is to be done, it should be using reaction emojis, not replies.
Maybe 😀 for revert, 🎉 for leaving as it is currently (christmas tree) and 🚀 for adding breaks at print width (pancake party).
Though there is no probably not much use in voting because people are really unhappy with the current state 🎉 and breaking at print width 🚀 was rejected by the maintainers.

@adamwathan
Copy link

It's been reverted 👍🏻 just need to wait for a new release.

@nicooprat
Copy link

Cf #11827

@fabd
Copy link

fabd commented Nov 25, 2021

Thanks for the update. Definitely more usable.

I would still like to see a way to leave intentional newli es (in a html attribute).

@hivokas
Copy link

hivokas commented Nov 25, 2021

It has been released: https://github.com/prettier/prettier/releases/tag/2.5.0

@alexander-akait
Copy link
Member

Let's close, feel free to feedback

@lkj4
Copy link

lkj4 commented Nov 26, 2021

Let's close, feel free to feedback

IDK, the latest release is a good baseline which works for all us, nobody will die and it's better than the Xmas tree. But are we there yet?

Closing the issue would be feel a bit like giving up. I mean the future of CSS will be for a significant part about utility CSS. And maybe the solution is that the Tailwind team or new teams need to come up with a more terse API which fits most of the time into one line (Tachyons was better with this btw). Tailwind is in some areas terse but in many parts not much shorter than the og style equivalent.

Or, the Tailwind team just forks prettier and focuses more on IDE tooling than some ui toolkits. Former is way more crucial than another set of random ui components. /cc @adamwathan

Or, there is a solution in better formatting which works for all of us, can be implemented by the og prettier team, without fragmentation of the community. I don't want to get again into the topic and repeat my view like a broken record. We need instead another take how to discuss with a proper moderation. Maybe we start with listing requirements of everyone before we sketch another solution. Some love git diffs, some have huge code blocks within, some need ordering but not alphabetically and so on.

Utility CSS is too important that we just do nothing or play laissez faire. The current solution is ok-ish but far from what I would expect from prettier (It.Just.Works™).

@jamisuomalainen
Copy link

Closing the issue would be feel a bit like giving up.

I don't think anyone's giving up; you can find the follow-up discussion in #7863 as mentioned in the 2.5.0 release notes.

@dillingham
Copy link

Or, the Tailwind team just forks prettier and focuses more on IDE tooling than some ui toolkits. Former is way more crucial than another set of random ui components. /cc @adamwathan

You seem passionate about it, you could fork it also? Those UI components pay for the many full time devs on team tailwind and bring me more value that re ordering css classes. "Crucial" is subjective

@n4ks
Copy link

n4ks commented Dec 2, 2021

I was very upset by this change in version 2.5.0. It is much more convenient for me to work with classes when they are arranged in a column, and not in one row. Maybe you can add a setting for this instead of changing the default behavior? It would be very convenient and would allow everyone to work as it is convenient for him.

@bodograumann
Copy link

@fisker The other ticket #7863 is still marked as "locked as resolved and limited to collaborators."

@Scotchester
Copy link

Continuing the discussion here since the issue referenced in the release notes is still locked.

Here's my personal wishlist for how this would work in a perfect world:

  1. Keeps classes on one really long line if the class string contains no newlines.
  2. Removes unnecessary whitespace between class names.
  3. Adds new lines after class=" and before the closing " if the class string contains any newlines.
  4. Doesn't add extra newlines inside the class string ever, except for the starting and ending ones, which are only added if there is already a newline in the class string.
  5. Keeps class=" on the same line as the opening tag if it's the only attribute, even when the class string is broken across multiple lines.

Is anyone interested in getting a PR started for this maybe? This is the behavior I personally am able to get behind the most, and maybe having a PR to support can help push this forward. Of course if the maintainers don't believe this behavior aligns with the spirit of the project that's okay too, but hoping we can at least start somewhere.
I'm probably missing some hard-to-solve cases here so happy to discuss if helpful.

I think this is a good solution, with this you could also use another tool to agregate similar classes with a line break so it would wrap around in a way that makes sense.

<div class="
  mt-8 p-8
  bg-indigo-600 hover:bg-indigo-700
  border border-transparent
  font-medium text-white
">
  Hello world
</div>

I agree that this would be a really elegant solution that bridges the gap between the two extremes of one giant line and one line per class, neither of which are appealing to me as a Tailwind user.

@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Mar 29, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! lang:html Issues affecting HTML (and SVG but not JSX) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:enhancement A potential new feature to be added, or an improvement to how we print something
Projects
None yet
Development

No branches or pull requests