Skip to content

Reverts #7865, keeping class names on the same line #11827

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

Merged
merged 4 commits into from
Nov 18, 2021

Conversation

jlongster
Copy link
Member

@jlongster jlongster commented Nov 17, 2021

Description

This reverts #7865 which introduced automatically breaking class names across multiple lines. This has introduced significant community churn, particularly in CSS frameworks like Tailwind where it's typical to have a lot of class names.

I think this was on overstep on Prettier's part. The consequence of breaking this line is large and there's not a strong enough reason for it. While these decisions are somewhat subjective, I still don't see strong arguments to implement this feature. It's too opinionated. It's a "nice" thing for people that want it, but it wreaks havoc on code for people that don't want it. Given that balance, I think we should remove it.

If we merge this PR and someone really wants class names to be formatted, look into suggestions like here: #10918 (comment). I think it'd be fine to simply break the class names across lines if there is newline in there. It's not fully reversable, but we have the same behavior for objects. I don't 100% love it all the time, but it is a clever technique that balances the tradeoffs between users. I think it'd be fine here even if I don't want that behavior for everything.

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

Sorry, something went wrong.

flex-column flex-lg-row
justify-content-start justify-content-lg-between
align-items-start align-items-lg-center
"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this output as a new test input to make sure that existing code with line breaks in the class attribute continues to be formatted correctly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR does not implement the behavior where it keeps it if there is already a line break. So they will get collapsed.

I just realized why I never noticed this behavior before: In JSX, we just keep the class name as it exactly. It seems like the JSX and HTML behavior should be exactly the same. We should just keep the class name as is, so that means that all existing users won't be effected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In JSX, we just keep the class name as it exactly. It seems like the JSX and HTML behavior should be exactly the same.

Formatting for class names in html was introduced in #7555 https://prettier.io/blog/2020/03/21/2.0.0.html#format-value-of-html-class-attribute-7555httpsgithubcomprettierprettierpull7555-by-fiskerhttpsgithubcomfisker

Copy link
Member

@fisker fisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will reopen #7863

@AndrewBogdanovTSS
Copy link

I can say that this is super weird behavior. Is there any chance to have this available at least behind an option, something similar to proseWrap? Maybe classWrap?

@alicercedigital
Copy link

Someone know how to solve this?
We need an formater to long classNames. There is a way to activate this without downgrade Prettier?

@AndrewBogdanovTSS
Copy link

@alicercedigital I don't think it's possible at the moment, but highly needed in my opinion

medikoo pushed a commit to medikoo/prettier-elastic that referenced this pull request Dec 13, 2023

Verified

This commit was signed with the committer’s verified signature.
medikoo Mariusz Nowak
…#11827)

* Reverts prettier#7865, keeping class names on the same line

* Add changelog

* Fix lint

* Fix

Co-authored-by: fisker Cheung <lionkay@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants