template string bad formatting example
See original GitHub issue const formatted_display = `${display.substring(0,1)}h ${display.substring(1,3)}m ${display.substring(3,5)}s`
(Edit by vjeux: this issue has been fixed)
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Python String Formatting Best Practices
Learn the four main approaches to string formatting in Python, as well as their strengths and weaknesses. You'll also get a simple rule...
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 >advanced string formatting vs template strings - Stack Overflow
Normal format strings will raise an error if a placeholder is not passed a value. For example: "Hello, {first} {last}".format(first='Joe').
Read more >Out-of-context string template is an anti-pattern | Hackle's blog
Format and the string template turns out to be a pretty poor idea. string templates are not magic strings. String templates do carry...
Read more >Comprehensive Guide to Java String Format in 2021 - DZone
For example, we can write a formatted String to standard error using the System.err.format method. Note that the PrintStream class also provides ...
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 Free
Top 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
Interesting, yeah we can play with that! Note that this is the output with this PR:
The thing that’s hard about this is that it’s by definition taking the original user’s formatting into account because they are in a string. So the number of spaces to indent the line starting with
${selector}
is just going to be blindy copied. Hopefully #749 helps with this because it won’t break things up for you anymore, and users just sometimes have to readjust things. But it makes getting this right automatically almost impossible.For me it would be enough. But would that mean that any template string use in other context than styled-component would have the current formatting ?
Looks like the formatting rules applied otherwhere should not be the same as inside template string variable. so for exemple “&&” does not trigger line.
For the indent it is true that it is not the same as the text out of js should keep the indent.
For @gaelduplessix example it is funny to see how it act when you take
outputs
https://jlongster.github.io/prettier/#{"content"%3A"const Test %3D styled.div`\n%24{(customCss) %3D> customCss.map(\n ({ selector%2C key%2C value }) %3D> `\n %24{selector} {\n %24{key}%3A %24{value}%3B\n }`\n)%7D%5Cn%60%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3Afalse%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Afalse%2C%22doc%22%3Atrue%7D%7D
and just adding the tab on the string template bloc so vs:
outputs
https://jlongster.github.io/prettier/#{"content"%3A"const Test %3D styled.div`\n %24{(customCss) %3D> customCss.map(\n ({ selector%2C key%2C value }) %3D> `\n %24{selector} {\n %24{key}%3A %24{value}%3B\n }`\n )%7D%5Cn%60%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3Afalse%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Afalse%2C%22doc%22%3Atrue%7D%7D