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
locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:needs discussionIssues needing discussion and a decision to be made before action can be taken
The formatting of the last two lines seems odd to me. I'm not sure why a comma is added or why the line with the closing bracket is on the same indentation as the closing parenthesis.
Reacted by Ron ChanOu, Stephen Bradshaw, Nic Young and R.G.
Template literals are tricky because the indentation is part of the string itself. If we change the indentation, this means that the string itself will change and this may (or may not, like in this case) change the program behavior, which we don't want to.
In this case, in the original version, } was indented by 0 spaces so we respect that. As for the comma, this is because you've got the trailing comma option enabled.
That code should not be breaking in the first place though... it doesn't reach 80 chars so not sure why it breaks the function call. In cases where it does break though, yes, this is expected behavior and you'll have to tweak the literal to make it align correctly.
I thought the formatting for an optional styled-component rule was a little odd (although not terrible), but thought I'd throw another template literal example here to consider. This one has nested template literals.
I have a similar case and , which is triggered by tabWidth. Notice how the second argument to the this.query call in loadEntity is indented incorrectly in the tabWidth 4 case.
@hundsim This issue should be fixed. If you’re having formatting issues, please open a new issue and fill out the template so we can more easily track them.
locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:needs discussionIssues needing discussion and a decision to be made before action can be taken
Activity
vjeux commentedon Feb 23, 2017
Template literals are tricky because the indentation is part of the string itself. If we change the indentation, this means that the string itself will change and this may (or may not, like in this case) change the program behavior, which we don't want to.
In this case, in the original version,
}was indented by 0 spaces so we respect that. As for the comma, this is because you've got the trailing comma option enabled.jlongster commentedon Feb 23, 2017
That code should not be breaking in the first place though... it doesn't reach 80 chars so not sure why it breaks the function call. In cases where it does break though, yes, this is expected behavior and you'll have to tweak the literal to make it align correctly.
vjeux commentedon Mar 1, 2017
Looks like template literal \n force the parent to break.
vjeux commentedon Mar 1, 2017
But even if I remove
breakParentfromtemplateline, it still triggers the parent to break.vjeux commentedon Mar 1, 2017
Another similar issue reported by @jonikorpi
styled-jsx causes similar issues. No errors, but the resulting formatting is undesirable/ugly.
->
https://prettier.github.io/prettier/#%7B%22content%22%3A%22export%20default%20()%20%3D%3E%20(%5Cn%20%20%3Cdiv%3E%5Cn%20%20%20%20%3Cp%3Eonly%20this%20paragraph%20will%20get%20the%20style%20%3A)%3C%2Fp%3E%5Cn%20%20%20%20%7B%20%2F*%20you%20can%20include%20%3CComponent%20%2F%3Es%20here%20that%20include%5Cn%20%20%20%20%20%20%20%20%20other%20%3Cp%3Es%20that%20don't%20get%20unexpected%20styles!%20*%2F%20%7D%5Cn%20%20%20%20%3Cstyle%20jsx%3E%7B%60%5Cn%20%20%20%20%20%20p%20%7B%5Cn%20%20%20%20%20%20%20%20color%3A%20red%3B%5Cn%20%20%20%20%20%20%7D%5Cn%20%20%20%20%60%7D%3C%2Fstyle%3E%5Cn%20%20%3C%2Fdiv%3E%5Cn)%22%2C%22options%22%3A%7B%22printWidth%22%3A120%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3A%22all%22%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Atrue%2C%22parser%22%3A%22babylon%22%2C%22doc%22%3Afalse%7D%7D
vjeux commentedon Mar 3, 2017
For the first example, I found out that if you write it without parenthesis, then it prints the same way as the original.
https://prettier.github.io/prettier/#%7B%22content%22%3A%22insertRule%60*%2C%20*%3Abefore%2C%20*%3Aafter%20%7B%5Cn%20%20box-sizing%3A%20inherit%3B%5Cn%7D%60%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3A%22%22%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Afalse%2C%22parser%22%3A%22%22%2C%22doc%22%3Afalse%7D%7D
vjeux commentedon Mar 3, 2017
I wonder if many people write it as
if not, then we could special case single-argument calls that are templates to not indent.
[RFC] Do not indent calls with a single template literal argument
vjeux commentedon Mar 3, 2017
I just sent #873 which fixes the original issue but I'm not sure this is the right thing to do.
techniq commentedon Mar 4, 2017
I thought the formatting for an optional
styled-componentrule was a little odd (although not terrible), but thought I'd throw another template literal example here to consider. This one has nested template literals.formats to
knowbody commentedon Mar 9, 2017
I've also seen that
styled-componentsget weird formatting, probably all related to this issue:formatted to:
gustavnikolaj commentedon Mar 20, 2017
I have a similar case and , which is triggered by tabWidth. Notice how the second argument to the
this.querycall inloadEntityis indented incorrectly in the tabWidth 4 case.[RFC] Do not indent calls with a single template literal argument
[RFC] Do not indent calls with a single template literal argument (#873)
axhamre commentedon Apr 8, 2018
As this was closed - was there eventually any solution to this or are we out of luck if we for example use
styled-components?j-f1 commentedon Apr 8, 2018
@hundsim This issue should be fixed. If you’re having formatting issues, please open a new issue and fill out the template so we can more easily track them.