question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Brackets same line Issue/template literals issue

See original GitHub issue

Prettier 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:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
brodybitscommented, Feb 20, 2019

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.

0reactions
jyoung295commented, Feb 20, 2019

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 😅

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found