hudochenkov / postcss-styled-syntax

PostCSS syntax for CSS-in-JS like styled-components
MIT License
69 stars 4 forks source link

`block-no-empty` false positive #3

Closed vincentducorps closed 1 year ago

vincentducorps commented 1 year ago

When we only have interpolation(s) in a block we have an error: Unexpected empty block block-no-empty

    &:hover {
      ${props => colorHoverMixin(props)}
    }
    &:hover {
      ${props => colorHoverMixin(props)}
      ${props => otherMixin(props)}
    }
    && {
      ${props => doSomething(props)}
    }
hudochenkov commented 1 year ago

It's a problem with the Stylelint rule. Could you report a bug in its repository, please? There we could find what action to take.

I suggest to disable the rule temporary until solution is found.

johnnybenson commented 1 year ago

Here's another exotic example that we may perhaps consider a false positive, because a styled-component has utility despite having an empty block., e.g. extending from a base.

const Base = styled.span.attrs({ children: ['🍕'] })``;

const Extended = styled(Base)` 
    font-size: 100000000px;
`;

Disabling the rule for now, thanks!

hudochenkov commented 1 year ago

@johnnybenson I see some over-engineering :)

Stylelint only concerns about stuff between backticks. Of course, we could change postcss-styled-syntax to provide info to CSS piece if styled component has attrs attribute. And create Stylelint rule specifically for postcss-styled-syntax to read that information and don't report block as empty. However, I think it is too much overhead, and value provided is not worth spent time.

Also I would recommend to create actual React component instead of making styled component like Base, as it would be more performant and easier to understand.

johnnybenson commented 1 year ago

Eh my example was made up / convoluted! Makes sense for the linter to only care about what is between the back ticks. Thanks for sharing your thoughts :)

ghost commented 1 year ago

Not sure if this is better than disabling the rule or not, but adding / a comment / inside the not-really-empty block seems to un-empty it.

hudochenkov commented 1 year ago

The fix will be released in the next Stylelint version.