prettier/prettier

Styled-components template strings formatting

Open

#1,872 建立於 2017年6月2日

在 GitHub 查看
 (21 留言) (41 反應) (0 負責人)JavaScript (51,868 star) (4,716 fork)batch import
area:binary expressionsarea:multiparserhelp wantedlang:css/scss/less

描述

I'm not sure if it's can be fixable and how. But it's very common when using styled-components to write constructions that look like that.

Prettier 1.10.2 Playground link

Input:

const Something = styled.span`
 ${props => props.right && css`
    padding: 10px 134px 10px 20px;
    &:after {
      left: initial;
      right: 30px;
    }
  `}
`

So it looks a bit cleaner, especially for multiple rules. After the latest update, it's broken and looks ugly.

Output:

const Something = styled.span`
  ${props =>
    props.right &&
    css`
      padding: 10px 134px 10px 20px;
      &:after {
        left: initial;
        right: 30px;
      }
    `};
`;

To prove my words, this construction is on the main page first example of styled-components website: https://www.styled-components.com/

貢獻者指南

Styled-components template strings formatting · prettier/prettier#1872 | Good First Issue