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

Fix TypeError for media queries in indentation #5003

Closed
ryprice opened this issue Oct 25, 2020 · 4 comments
Closed

Fix TypeError for media queries in indentation #5003

ryprice opened this issue Oct 25, 2020 · 4 comments
Labels
status: ready to implement is ready to be worked on by someone syntax: sass relates to Sass and Sass-like syntax type: bug a problem with a feature or rule

Comments

@ryprice
Copy link

ryprice commented Oct 25, 2020

Which rule, if any, is the bug related to?

indentation

What code is needed to reproduce the bug?

.fancyButton
  color: red

  @media only screen and (min-width: 600px)
    color: blue

What stylelint configuration is needed to reproduce the bug?

{
  "rules": {
    "indentation": 2,
  }
}

Which version of stylelint are you using?

13.7.2
This worked previously in 9.9.0, and I verified that with this isolated example.

How are you running stylelint: CLI, PostCSS plugin, Node.js API?

npx stylelint src/fancyButton.sass --syntax sass

Does the bug relate to non-standard syntax (e.g. SCSS, Less etc.)?

sass

What did you expect to happen?

I'm using stylelint inside of webpack and this exception was really hard to debug because the only thing webpack was telling me was ERROR in Cannot read property 'type' of undefined without indicating the file or plugin that this exception was coming from. This is not the root issue, but it would have been nice for the stylelint webpack plugin to somehow identify itself as the thrower of the exception, as well as the file it failed to parse.

Anyway, I was able to isolate the issue to the described command line setup, and I would have expected no errors.

What actually happened (e.g. what warnings or errors did you get)?

From npx stylelint: (line number might be slightly off because I was debugging with console.logs. I believe the error comes from this line.)

TypeError: Cannot read property 'type' of undefined
    at indentationLevel (D:\src\listlab-web\node_modules\stylelint\lib\rules\indentation\index.js:157:20)
    at D:\src\listlab-web\node_modules\stylelint\lib\rules\indentation\index.js:62:22
    at D:\src\listlab-web\node_modules\postcss\lib\container.js:135:18
    at Rule.each (D:\src\listlab-web\node_modules\postcss\lib\container.js:101:16)
    at Rule.walk (D:\src\listlab-web\node_modules\postcss\lib\container.js:131:17)
    at D:\src\listlab-web\node_modules\postcss\lib\container.js:148:24
    at Root.each (D:\src\listlab-web\node_modules\postcss\lib\container.js:101:16)
    at Root.walk (D:\src\listlab-web\node_modules\postcss\lib\container.js:131:17)
    at D:\src\listlab-web\node_modules\stylelint\lib\rules\indentation\index.js:56:8
    at D:\src\listlab-web\node_modules\stylelint\lib\lintPostcssResult.js:118:8

From webpack (where I was originally running this):
ERROR in Cannot read property 'type' of undefined

@rovadi
Copy link

rovadi commented Oct 30, 2020

Hey @ryprice this issue it's related with this 4865, I posted a solution there that works for this same case, hope it helps.

@ryprice
Copy link
Author

ryprice commented Oct 30, 2020

@rovadi do you think it would be worth wrapping rule execution in a try catch to avoid complete failure? I made a PR to implement this. #5012

@jeddy3 jeddy3 changed the title Media queries cause the indentation rule to throw Fix TypeError for media queries in indentation Oct 31, 2020
@jeddy3 jeddy3 added status: ready to implement is ready to be worked on by someone syntax: sass relates to Sass and Sass-like syntax type: bug a problem with a feature or rule labels Oct 31, 2020
@jeddy3
Copy link
Member

jeddy3 commented Oct 31, 2020

Thanks for the report and for using the template.

I've labelled the issue as ready to implement. Please consider contributing if you have time.

There are steps on how to fix a bug in a rule in the Developer guide.

From npx stylelint: (line number might be slightly off because I was debugging with console.logs. I believe the error comes from this line.)

I think you're right. We may just need to add a guard before accessingnode.parent.type, or there maybe something bigger amiss.

@jeddy3
Copy link
Member

jeddy3 commented Jan 18, 2022

Closing as stylistic rules are frozen. The community is welcome to migrate the rule to a plugin and fix this bug.

@jeddy3 jeddy3 closed this as completed Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready to implement is ready to be worked on by someone syntax: sass relates to Sass and Sass-like syntax type: bug a problem with a feature or rule
Development

No branches or pull requests

3 participants