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 baseIndentLevel: 1 option and vue file in indentation #5677

Closed
caioferrarezi opened this issue Oct 29, 2021 · 1 comment · Fixed by #5657
Closed

Fix TypeError for baseIndentLevel: 1 option and vue file in indentation #5677

caioferrarezi opened this issue Oct 29, 2021 · 1 comment · Fixed by #5657
Labels
status: wip is being worked on by someone syntax: html relates to HTML style tags and attributes type: bug a problem with a feature or rule

Comments

@caioferrarezi
Copy link

caioferrarezi commented Oct 29, 2021

Hey, guys! I'm sorry if it is a repetition of another issue, but I couldn't anything related to the problem I'm facing.

Clearly describe the bug

I got a javascript error when trying to use stylelint and postcss-html to lint .vue files (I believe this might happens on html files too) with the indentation rule configured to have a baseIndentLevel: 1.

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

"indentation": [2, {
  "baseIndentLevel": 1
}]

What code is needed to reproduce the bug?

A simple single file component is enough to see the bug happening.

<template>
  <div id="app">
    hi!
  </div>
</template>

<style lang="scss">
  #app {
    font: var(--type-body1-400);
  }
</style>

What Stylelint configuration is needed to reproduce the bug?

{
  "plugins": [
    "stylelint-scss",
    "stylelint-order"
  ],
  "ignoreFiles": ["**/dist/**/*"],
  "overrides": [{
    "files": ["*.scss", "**/*.scss"],
    "customSyntax": "postcss-scss",
    "ignoreFiles": ["**/_normalize.scss"]
  }, {
    "files": ["*.vue", "**/*.vue"],
    "customSyntax": "postcss-html",
    "rules": {
      "indentation": [2, {
        "baseIndentLevel": 1
      }]
    }
  }],
  "rules": { ... }
}

Which version of Stylelint are you using?

{
  "postcss": "^8.3.11",
  "postcss-html": "^1.2.0",
  "postcss-scss": "^4.0.2",
  "stylelint": "^14.0.1",
  "stylelint-order": "^5.0.0",
  "stylelint-scss": "^4.0.0"
}

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

CLI with ./node_modules/.bin/stylelint **/*.{vue,css,scss}

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

Yes, it's related to CSS/SCSS inside HTML syntax.

What did you expect to happen?

I was expecting the normal validation with a stylelint error when the root css code was in the same indentation level as the style tag.

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

I got this error:

./node_modules/.bin/stylelint **/*.{vue,css,scss}
TypeError: Cannot read property 'match' of undefined
    at /home/enguser/Documents/enjoei/ui/packages/vue-ui/sandbox/app.vue:18:3
    at inferRootIndentLevel (/home/enguser/Documents/enjoei/ui/node_modules/stylelint/lib/rules/indentation/index.js:682:25)
    at getRootBaseIndentLevel (/home/enguser/Documents/enjoei/ui/node_modules/stylelint/lib/rules/indentation/index.js:487:25)
    at indentationLevel (/home/enguser/Documents/enjoei/ui/node_modules/stylelint/lib/rules/indentation/index.js:170:20)
    at /home/enguser/Documents/enjoei/ui/node_modules/stylelint/lib/rules/indentation/index.js:71:22
    at /home/enguser/Documents/enjoei/ui/node_modules/postcss/lib/container.js:55:18
    at Root.each (/home/enguser/Documents/enjoei/ui/node_modules/postcss/lib/container.js:41:16)
    at Root.walk (/home/enguser/Documents/enjoei/ui/node_modules/postcss/lib/container.js:52:17)
    at /home/enguser/Documents/enjoei/ui/node_modules/stylelint/lib/rules/indentation/index.js:65:8
    at /home/enguser/Documents/enjoei/ui/node_modules/stylelint/lib/lintPostcssResult.js:112:8
    at Array.map (<anonymous>)
@jeddy3
Copy link
Member

jeddy3 commented Oct 29, 2021

@caioferrarezi Thanks for the report and for using the template.

I'm sorry if it is a repetition of another issue,

You're all good, it hasn't be raised as an issue yet but the good news is that'll it'll be fixed by #5657.

I'll mark this is a bug and wip.

@jeddy3 jeddy3 changed the title Fix TypeError in indentation when using the postcss-html as a custom syntax to lint vue files. Fix TypeError for baseIndentLevel: 1 optoin and vue file in indentation Oct 29, 2021
@jeddy3 jeddy3 changed the title Fix TypeError for baseIndentLevel: 1 optoin and vue file in indentation Fix TypeError for baseIndentLevel: 1 option and vue file in indentation Oct 29, 2021
@jeddy3 jeddy3 added status: wip is being worked on by someone syntax: html relates to HTML style tags and attributes type: bug a problem with a feature or rule labels Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: wip is being worked on by someone syntax: html relates to HTML style tags and attributes type: bug a problem with a feature or rule
Development

Successfully merging a pull request may close this issue.

2 participants