Brackets same line Issue/template literals issue
See original GitHub issuePrettier 1.16.1 Playground link
# Options (if any):
# using prettier-standard package
Input:
docRef.update({[`schedule.${this.state.currDbLoc}.submission`]: selectedSubmission})
// -- or --
docRef.update({
[`schedule.${this.state.currDbLoc}.submission`]: selectedSubmission
})
Output:
docRef
.update({
[`schedule.${
this.state.currDbLoc
}.submission`]: selectedSubmission
})
Expected behavior: Should produce (or stay as):
docRef.update({
[`schedule.${this.state.currDbLoc}.submission`]: selectedSubmission
})
I’m using the prettier-standard
package which uses this package to format and I’m getting this really weird formatting using a template literal inside an object key.
This seems partially like an issue with brackets on the same line rule of standard not being followed, and something else to do with the template literal.
Apart from this issue I do also have issues happening just with the brackets on same line rule not being followed, I just thought this one would showcase more.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Template literal with curly brace and newline triggers a 'semi ...
I'm using multiple embedded strings in a template literal for the transition property, and the plugin has no problem when everything is on...
Read more >Template literals (Template strings) - JavaScript | MDN
Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded ...
Read more >507518 – Nested brackets in template literals breaks ... - Bugs
I think that the problem is not the brackets, but the "grave accent" (`)-character used to surround the value of variable instead of...
Read more >Understanding Template Literals in JavaScript - DigitalOcean
This section will review how to declare strings with single quotes and double quotes, and will then show you how to do the...
Read more >template-curly-spacing - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @jyoung295 for the response. The issue with printWidth definitely makes sense to me. I hope we will converge on a more consistent solution, someday in the future.
Closing now. Please don’t hesitate to ask if you encounter any more issues or have any more questions in the future.
I tried with the latest prettierx and it didn’t fix it. However, when I manually fixed it then ran the formatter, it didn’t break it either. This led me to think that it could be a printWidth issue, so I set a large printWidth in a
.prettierrc
file and went back to using the prettier-standard package (which uses prettierx 0.3.0) and it worked totally fine.In that last part I just meant I was seeing other places in my code where brackets were being separated to multiple lines, but those are all fixed aswell now.
Thanks for your help! I’m only a little embarrassed that it was such a simple issue 😅