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

sass-lint crashes when using !important with an if guarding #1099

Closed
nyon opened this issue Jul 27, 2017 · 0 comments
Closed

sass-lint crashes when using !important with an if guarding #1099

nyon opened this issue Jul 27, 2017 · 0 comments
Labels

Comments

@nyon
Copy link

nyon commented Jul 27, 2017

What version of Sass Lint are you using?

1.10.2

Please include any relevant parts of your configuration

No configuration used. I used the CLI tool without configuration.

What did you do? Please include the actual source code causing the issue.

I created a test file named test.scss:

@mixin testcase($important: null) {
  @if ($important == true) {$important: !important;}
  width: auto $important;
}

body {
  @include testcase(true);
}

I ran scss test.scss test.css which produced no errors and a valid css file.
But if i run sass-lint test.scss the linter crashes.

What did you expect to happen?

That sass-lint does not crash. I would propose, that sass-lint ignores bangs like these.

What actually happened? Please include any error messages given to you by Sass Lint.

sass-lint crashes with the following error message:

/home/nyon/.nvm/versions/node/v7.7.4/lib/node_modules/sass-lint/lib/rules/space-before-bang.js:16
      if (!previous.is('space')) {
                  ^

TypeError: Cannot read property 'is' of undefined
    at Node.<anonymous> (/home/nyon/.nvm/versions/node/v7.7.4/lib/node_modules/sass-lint/lib/rules/space-before-bang.js:16:20)
    at /home/nyon/.nvm/versions/node/v7.7.4/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/gonzales.js:305:54
    at Node.traverse (/home/nyon/.nvm/versions/node/v7.7.4/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/gonzales.js:279:6)
    at Node.traverse (/home/nyon/.nvm/versions/node/v7.7.4/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/gonzales.js:284:36)
    at Node.traverse (/home/nyon/.nvm/versions/node/v7.7.4/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/gonzales.js:284:36)
    at Node.traverse (/home/nyon/.nvm/versions/node/v7.7.4/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/gonzales.js:284:36)
    at Node.traverse (/home/nyon/.nvm/versions/node/v7.7.4/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/gonzales.js:284:36)
    at Node.traverse (/home/nyon/.nvm/versions/node/v7.7.4/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/gonzales.js:284:36)
    at Node.traverse (/home/nyon/.nvm/versions/node/v7.7.4/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/gonzales.js:284:36)
    at Node.traverse (/home/nyon/.nvm/versions/node/v7.7.4/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/gonzales.js:284:36)

If you're using a IDE plugin have you tried the CLI too?

I've only used the CLI tool.

Possible Fix

I fixed it by inserting guarding code into the space-before-bang linting rule. I'm not sure whether this has side effects. I doubt it would:

// file: lib/rules/space-before-bang.js
    // ...
    ast.traverseByTypes(['important', 'default'], function (block, i, parent) {
      var previous = parent.content[i - 1];
      
      if(previous === undefined) {
        return null;
      }

      if (!previous.is('space')) {
        if (parser.options.include) {
    // ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants