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
Fix TypeError "Cannot read property 'syntax' of undefined" for nested control structures #4865
Comments
Hey @Buszmen, thank you for reporting the issue and following the template! Did a bit of investigation and I think it's a problem with Here is a slightly simpler SASS example of a $sizes: 40px, 50px, 80px
@each $size in $sizes
.icon-#{$size}
font-size: $size
height: $size
width: $size The SASS error block for this message is a little cryptic. However, if we switch to SCSS, with the same snippet (demo here) $sizes: 40px, 50px, 80px;
@each $size in $sizes {
.icon-#{$size} {
font-size: $size;
height: $size;
width: $size;
}
} We can notice that we get the error
If we use a different snippet involving $base-color: #036;
@for $i from 1 through 3 {
ul:nth-child(3n + #{$i}) {
background-color: lighten($base-color, $i * 5%);
}
} We'll get the same error
Now, I'm not too familiar with the internals of stylelint, but my theory is that these SCSS/SASS control flow operators are being interpreted as at rules, which is causing the problem. Looking at if (postcss.vendor.prefix(name) || keywordSets.atRules.has(name.toLowerCase())) {
return;
} We don't do any checks for SASS/SCSS control flow operators. And, if I add Not sure exactly how to solve this problem, since I'm not sure if just using |
My colleague discovered some possible workaround. $sides: 'top' 'bottom' 'left' 'right'
$sizes: 'xxs' 'xs' 'sm' 'md' 'lg' 'xlg'
@each $side in $sides
@each $size in $sizes
.ac-padding-#{$side}-#{$size}
padding-#{$side}: var(--spacing-#{$size})
// Magic comment that makes all problems go away We now have a different error message: $sides: 'top' 'bottom' 'left' 'right'
$sizes: 'xxs' 'xs' 'sm' 'md' 'lg' 'xlg'
div
@each $side in $sides
@each $size in $sizes
.ac-padding-#{$side}-#{$size}
padding-#{$side}: var(--spacing-#{$size})
// Magic comment that makes all problems go away We are no getting proper linter error about |
Hey @Buszmen , I have encountered the same error, the problem is due to a postcss bug that doesn't know how to interpret some sass flow control rules in this case the $sides: 'top' 'bottom' 'left' 'right'
$sizes: 'xxs' 'xs' 'sm' 'md' 'lg' 'xlg'
=mixin-name
@each $side in $sides
@each $size in $sizes
.ac-padding-#{$side}-#{$size}
padding-#{$side}: var(--spacing-#{$size})
+mixin-name As you can see I simply wrap the |
Do you suggest wrap each media query by mixin name too? |
So to summarize, the whole purpose of this project is to validate CSS with support for SCSS, yet it doesn't understand/handle basic loops that have been part of SCSS since before this project was started over 6 years ago, and nobody had any problem with this until now? Or am I misunderstanding the situation here? Was this working at some point, and should this be considered a regression? Can any owners of this project confirm what is the status of this issue? |
stylelint (and the built-in rules and official configs) are geared towards validating CSS. However, stylelint can be extended by each community to support their preferred styling language. This distinction will be made clearer in the next major release (
@thnee I've updated to labels to reflect that this is an issue with the upstream syntax and specific to whitespace SASS syntax. I believe the postcss-sass syntax is maintained by a single contributor. Please consider volunteering your time upstream if you'd like to resolve this issue. |
The Please consider opening an issue upstream and fixing the issue there as the syntax is no longer bundled by Stylelint. |
A SASS code causes an error when linting:
Cannot read property 'syntax' of undefined
I don't think it's related to any specific rule.
Default one?
It's even reproducible here:
Demo
13.6.1
stylelint src/**/*.sass
I checked only SASS syntax
I expected to see linter report instead of an error.
It compiles fine if you put it here: https://www.sassmeister.com
Got error:
Cannot read property 'syntax' of undefined
For me it's somewhere around
node_modules/stylelint/node_modules/postcss-syntax/patch-postcss.js:38:67
The text was updated successfully, but these errors were encountered: