No line break insertions in short CSS selectors
See original GitHub issuePrettier 1.14.2 Playground link
--parser babylon
--no-semi
I suggest reconfiguring the changes made in #1962 so as to only insert line breaks in CSS selectors when they exceed a given length. Otherwise, you end up with unnecessarily long files in cases such as the one below.
Input:
import styled from 'styled-components'
import mediaQuery from '../../utils/mediaQuery'
const Participants = styled.section`
padding: 2rem;
background: ${props => props.theme.mainWhite};
display: grid;
grid-gap: 2rem;
h1, h2, h3, h4 {
width: 100%;
padding: 0.5rem 2rem;
background: ${props => props.theme.lightGreen};
}
${mediaQuery.phone} {
h1, h2, h3, h4 {
font-size: 1rem;
}
}
${mediaQuery.tablet} {
grid-gap: 1rem;
h1, h2, h3, h4 {
grid-column: 1/-1;
}
}
${mediaQuery.minTablet} {
h1, h2, h3, h4 {
white-space: nowrap;
grid-row: 2;
}
}
`
export default Participants
Output:
import styled from "styled-components"
import mediaQuery from "../../utils/mediaQuery"
const Participants = styled.section`
padding: 2rem;
background: ${props => props.theme.mainWhite};
display: grid;
grid-gap: 2rem;
h1,
h2,
h3,
h4 {
width: 100%;
padding: 0.5rem 2rem;
background: ${props => props.theme.lightGreen};
}
${mediaQuery.phone} {
h1,
h2,
h3,
h4 {
font-size: 1rem;
}
}
${mediaQuery.tablet} {
grid-gap: 1rem;
h1,
h2,
h3,
h4 {
grid-column: 1/-1;
}
}
${mediaQuery.minTablet} {
h1,
h2,
h3,
h4 {
white-space: nowrap;
grid-row: 2;
}
}
`
export default Participants
Expected behavior:
No insertion of line breaks in CSS selectors of length less than, say, 80.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:21
- Comments:35 (14 by maintainers)
Top Results From Across the Web
How To Prevent Line Breaks Using CSS - DigitalOcean
In this tutorial prevent line breaks using CSS's white-space property. You will achieve this using three different configurations.
Read more >How to line-break from css, without using <br />?
Consider a list of <a> links on a vertical menu where you want them all on their own line, but can't use <br>...
Read more >line-break | CSS-Tricks
The CSS line-break property defines how strictly to enforce rules for wrapping text wrapping on new lines, particularly when working with ...
Read more >How to Insert Line Break in CSS - YouTube
In this tutorial we will see how to apply CSS line breaks in web pages.Don't forget to check out our site http://howtech.tv/ for...
Read more >6 Selectors
In CSS, pattern matching rules determine which style rules apply to ... the first line of a paragraph, and therefore no simple CSS...
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
@lydell I’m a little surprised that this issue is even debated. I was under the impression that the point of prettier is not to be simple in and of itself but to produce ideally formatted code. I can’t imagine anyone would consider this to be ideally formatted,
especially when compared to this
Breaking code onto multiple lines only once it exceeds a certain length is such a common practice. I don’t see why it would be more difficult or less useful with CSS selectors than anywhere else.
@lydell It’s a shame really. I understand that you’re looking for an overwhelming consensus before taking any action since you probably have more important things to focus on.
But with Preitter being an already opinionated formatter, I was at least hoping that even though this thread lacks popularity, that the change request shares similar values that were already made on other languages for virtually the same scenario in Javascript. I don’t understand why SCSS is being treated differently.
I’d least hope that we can look at this change request objectively and see that implementing it would not only make sense for Preitter, but add consistency across different languages.