Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid prelude for @media csstree/validator #44

Closed
rgant opened this issue Dec 15, 2021 · 5 comments
Closed

Invalid prelude for @media csstree/validator #44

rgant opened this issue Dec 15, 2021 · 5 comments

Comments

@rgant
Copy link

rgant commented Dec 15, 2021

As far as I know this is valid SCSS/SASS:

/// Custom breakpoints
/// @access public
/// @param {String} $breakpoint - Breakpoint
/// @param {String} $from - Defaults to "min-width" (mobile first)
///        can also take "max-width" to select elements under the provided size.
@mixin breakpoint($breakpoint, $from: 'min-width') {
  @media ($from: $breakpoint) {
    @content;
  }
}

But it results in an error:

src/styles/abstracts/_mixins.scss
25:11 ✖ Invalid prelude for @media csstree/validator

My config:
.stylelintrc.yml:

+  csstree/validator:
+    syntaxExtensions:
+      - sass

I have installed: stylelint-csstree-validator@2.0.0

First referenced in csstree/csstree#118 #issuecomment-993945845

@lahmatiy
Copy link
Member

The plugin is limited in validation of expressions which contain preprocessor's syntax (since it should be evaluated). So it avoid a validation of them. For now the plugin uses stylelint's isStandardSyntax*() helpers to detect non-standard syntax and some additional tricks for declaration values (but not for at-rule's preludes). Looks like isStandardSyntaxAtRule() helper doesn't catch such kind of expressions. So I'm going to add the same workaround for at-rule prelude as for declaration values. I think it should help.

@tleunen
Copy link

tleunen commented Jun 28, 2022

Just got the same with @keyframes with this. Funny enough. This is problematic with v2, but not v1

@mixin keyframes($animationName) {
  @keyframes #{$animationName} {
    @content;
  }
}

@lahmatiy
Copy link
Member

Fixed in 2.1.0

@pinkhominid
Copy link

I'm seeing the same error (with 2.1.0) using the postcss-lit custom syntax for expressions like this

css`
    @media (min-width: 500px) and ${namedMedia.css.mobile} {
        /* ... */
    }
`

whereas this doesn't error

css`
    @media ${namedMedia.css.mobile} {
        /* ... */
    }
`

@pinkhominid
Copy link

Created #52 to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants