[bug] Prettier formats contents of template string
See original GitHub issuePrettier 1.14.3
Input:
export const FlexBox = styled.div`
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
flex-direction: ${p => p.direction};
${p => p.stackOnMobile ? `
${media('<desktop')} {
flex-direction: column;
}
` : ''}
> * {
width: ${p => (p.howManyPerRow ? `${100 / p.howManyPerRow}%` : 'auto')};
}
`
output:
export const FlexBox = styled.div`
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
flex-direction: ${p => p.direction};
${p =>
p.stackOnMobile
? `
${media("<desktop")} {
flex-direction: column;
}
`
: ""} > * {
width: ${p => (p.howManyPerRow ? `${100 / p.howManyPerRow}%` : "auto")};
}
`;
Expected behavior:
Prettier should never format any part of a template string (at least not without some in-code option like some sort of comment).
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Prettier 2.2: new JavaScript parsers, TS 4.1 and ESM ...
This release supports new JavaScript parsers espree and meriyah, supports TypeScript 4.1, ships ESM standalone bundles for modern browsers, ...
Read more >Rationale - Prettier
Prettier is an opinionated code formatter. This document explains some of its choices. What Prettier is concerned about. Correctness.
Read more >Prettier 1.12: Fixes, Features, and Formatting, Oh My!
A bug in Prettier 1.11.1 caused expressions nested in template literals to get moved around when using prettier-ignore comments within the ...
Read more >Prettier 2.3. In which assignments are consistent, short keys ...
This means Prettier won't format Handlebars files that can't be parsed into such a tree, either because the underlying syntax isn't HTML or ......
Read more >Prettier 2.8: improve --cache CLI option and TypeScript 4.9 ...
A new `--cache-location` option has been added, and a bug that saved the ... Fix inconsistent formatting for multiline strings (#13274 by ...
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
There’s a lot of symbols, so my brain quickly zones out and I’m not sure what I’m looking at. Is there a specific part of it you don’t like?
Could you say why you want this? Is it breaking your code? Or is it “just” a bit ugly? Wouldn’t you be more interested in fixing things rather than disabling things?
Arguably Prettier is trying to do too much, and should thus make some things opt-in (or opt-out). The line between formatting code and formatting template strings isn’t fully clear.