You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[3.0] Unexpected line breaks in CSS values with commas #15070
Any css value with commas started being formatted with line breaks in 3.0 no matter its length. This was an unexpected (or undocumented) change in version 3.0. I believe this should respect the the print-width setting.
It doesn't respect the print width setting. It breaks lines after the comma no matter what.
This is an unexpected or undocumented change from 2.0 -> 3.0
CSS directives separated by space are tuples formatted as single line optionally put on multiple lines if print width is shorter.
CSS directives separated by space are typically a list of subdirectives/tuples. Formatting the list items on multiple lines is much more readable and sensual.
Can we just bail out if the line length is smaller than print width?
For these reasons, I do not think this will work for the example above which needs to be put on (at least) 2 lines no matter the print width.
I am the author of the fix. This is how I originally implemented it, but based on #6024 (comment) discussion there was a consensus to force the line break based on the AST structure rather than line break present. And I personally support this final approach.
This is more or less prettier base idea and it makes sense, as prettier is not a fixer, it is an opinionated formatter.
I personally propose to close this issue as won't fix.
If someone wants to pursue this, I think the only option is to enumerate CSS directives that are:
shorthand - like transition
list with single value items - like font-family
list with tuples/multiple value items - like box-shadow
For the first two groups of CSS directives the line breaks does not have to be forced. But the 3rd group can probably contain in many cases single value items only too, and the styling will be inconsistent...
#6024 (comment) already mentioned opting out for certain CSS properties, which I agree is a good starting point for fixing this.
Prettier is an opinionated formatter.
I am aware, but I have never seen anyone consider font-family broken down as 5 lines each consisting of only one word as intended behavior. This is a bug.
I like @alex-kinokon's idea to respect the author's structure, same as how js works.
Another idea: only break if one of the comma separated values is greater than some number (18?) or percentage of the print-width. That would satisfy both parties.
Another inconsistency is this one actually doesn't add breaks, so there needs to be a space in-play as well:
Facing similar issue because it doesn't respect the --print-width config which makes it even worst on my side because after running prettier --write it makes ESLint unhappy because it conflicts because of the print width setting (basically, the plugins are cancelling each other out). So I can't even upgrade to Prettier 3 unless this issue is fixed or if I add prettier-ignore to all my box-shadow (which I don't want to do, so I guess I'll postpone the update until this issue is fixed).
My perspective on the subject is the same as many of you, if it doesn't exceed --print-width then why split in multiple lines?
I was using eslint-config-prettier before and that caused the problem, replacing it with plugin:prettier/recommended worked, so at least now ESLint and Prettier are aligned.
@ghiscoding You definitely can't update to Prettier 3 and keep using an older version of Prettier via ESLint. How did you expect that to work?
@thorn0
How do you know it was using an older version of Prettier? What hint do we have to find that out?
Have to put prettier-ignore for the similar declaration font: 12px Arial, sans-serif; as @andersk mentioned previously. No much sence in line break here.
Activity
MatanelGordon commentedon Jul 10, 2023
Why should that happen?
In box-shadow, for example, I would expect Prettier to break the lines for me in case of multiple shadows.
Have you considered increasing your
--print-widthsetting?gpoitch commentedon Jul 10, 2023
It doesn't respect the print width setting. It breaks lines after the comma no matter what.
This is an unexpected or undocumented change from 2.0 -> 3.0
alex-kinokon commentedon Jul 14, 2023
Likely this is broken by #14208.
Here’s an extreme case from the 3.0 line breaking:
with the print width significantly higher than the actual width.
thorn0 commentedon Jul 14, 2023
I proposed a solution here: #6024 (comment)
alex-kinokon commentedon Jul 14, 2023
Can we just bail out if the line length is smaller than print width?
mvorisek commentedon Jul 14, 2023
See changelog example:
CSS directives separated by space are tuples formatted as single line optionally put on multiple lines if print width is shorter.
CSS directives separated by space are typically a list of subdirectives/tuples. Formatting the list items on multiple lines is much more readable and sensual.
For these reasons, I do not think this will work for the example above which needs to be put on (at least) 2 lines no matter the print width.
alex-kinokon commentedon Jul 14, 2023
That makes sense for
box-shadow, but definitely doesn’t forfont-familywhich is usually a long list of single word items. Take this example:which is the current output. I don’t think anyone wants this version.
I think it makes sense if it behaves like the JavaScript printer that considers existing line break, e.g.
is formatted as
while
is formatted into
so if the user has a line break, we format the rest of the property into multiple lines.
mvorisek commentedon Jul 14, 2023
I am the author of the fix. This is how I originally implemented it, but based on #6024 (comment) discussion there was a consensus to force the line break based on the AST structure rather than line break present. And I personally support this final approach.
This is more or less prettier base idea and it makes sense, as prettier is not a fixer, it is an opinionated formatter.
I personally propose to close this issue as won't fix.
If someone wants to pursue this, I think the only option is to enumerate CSS directives that are:
transitionfont-familybox-shadowFor the first two groups of CSS directives the line breaks does not have to be forced. But the 3rd group can probably contain in many cases single value items only too, and the styling will be inconsistent...
alex-kinokon commentedon Jul 14, 2023
#6024 (comment) already mentioned opting out for certain CSS properties, which I agree is a good starting point for fixing this.
I am aware, but I have never seen anyone consider font-family broken down as 5 lines each consisting of only one word as intended behavior. This is a bug.
[-]CSS comma line breaks in 3.0[/-][+][3.0] Unexpected line breaks in CSS values with commas[/+]gpoitch commentedon Jul 14, 2023
I like @alex-kinokon's idea to respect the author's structure, same as how js works.
Another idea: only break if one of the comma separated values is greater than some number (18?) or percentage of the print-width. That would satisfy both parties.
Another inconsistency is this one actually doesn't add breaks, so there needs to be a space in-play as well:
sosukesuzuki commentedon Jul 16, 2023
I like @thorn0's proposal
andersk commentedon Jul 20, 2023
This makes even less sense with the
fontshorthand, because thefont-sizepart is illogically grouped with the first item offont-family:ghiscoding commentedon Jul 24, 2023
Facing similar issue because it doesn't respect the
--print-widthconfig which makes it even worst on my side because after runningprettier --writeit makes ESLint unhappy because it conflicts because of the print width setting (basically, the plugins are cancelling each other out). So I can't even upgrade to Prettier 3 unless this issue is fixed or if I addprettier-ignoreto all mybox-shadow(which I don't want to do, so I guess I'll postpone the update until this issue is fixed).My perspective on the subject is the same as many of you, if it doesn't exceed
--print-widththen why split in multiple lines?thorn0 commentedon Jul 24, 2023
@ghiscoding You definitely can't update to Prettier 3 and keep using an older version of Prettier via ESLint. How did you expect that to work?
ghiscoding commentedon Jul 24, 2023
I actually managed to make it work by revisiting
eslint-plugin-prettierinstallation docs and followed their recommended setting (also upgraded to"eslint-plugin-prettier": "^5.0.0"which supports Prettier 3)https://github.com/prettier/eslint-plugin-prettier#recommended-configuration
Then you need to add
plugin:prettier/recommendedas the last extension in your .eslintrc.json:I was using
eslint-config-prettierbefore and that caused the problem, replacing it withplugin:prettier/recommendedworked, so at least now ESLint and Prettier are aligned.@thorn0
How do you know it was using an older version of Prettier? What hint do we have to find that out?
Maks9 commentedon Dec 1, 2023
Have to put
prettier-ignorefor the similar declarationfont: 12px Arial, sans-serif;as @andersk mentioned previously. No much sence in line break here.jasonhibbs commentedon Mar 12, 2025
Landed here because of
font-family, it looks wrong.