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

CLI: TypeError: Cannot read property 'type' of undefined #437

Closed
drewbarontini opened this issue Dec 3, 2015 · 13 comments
Closed

CLI: TypeError: Cannot read property 'type' of undefined #437

drewbarontini opened this issue Dec 3, 2015 · 13 comments

Comments

@drewbarontini
Copy link

When running the sass-lint CLI on Node v5.0.0 (also tried v4.2.2), I get the following error:

/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/node/basic-node.js:1
(function (exports, require, module, __filename, __dirname) { 'use strict';var _createClass=(function(){function defineProperties(target, props){for(var i=0; i < props.length; i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if('value' in descriptor)descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function(Constructor, protoProps, staticProps){if(protoProps)defineProperties(Constructor.prototype, protoProps);if(staticProps)defineProperties(Constructor, staticProps);return Constructor;};})();function _classCallCheck(instance, Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function');}}var Node=(function(){function Node(options){_classCallCheck(this, Node);this.type = options.type;this.content = options.content;this.syntax = op

TypeError: Cannot read property 'type' of undefined
    at Node.last (/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/node/basic-node.js:1:2641)
    at Object.module.exports.detect (/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/lib/rules/final-newline.js:19:23)
    at /Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/index.js:44:27
    at Array.forEach (native)
    at Function.sassLint.lintText (/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/index.js:43:11)
    at /Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/index.js:91:21
    at Array.forEach (native)
    at Function.sassLint.lintFiles (/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/index.js:90:9)
    at detectPattern (/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/bin/sass-lint.js:15:18)
    at Object.<anonymous> (/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/bin/sass-lint.js:77:3)
@DanPurdy
Copy link
Member

DanPurdy commented Dec 3, 2015

Hi @drewbarontini

This looks like an error in our final newline rule, could you do me a favour just to be sure though.

Could you post the version of sass-lint you're using and the command you were running. Also I imagine from the line numbers that you're using .sass syntax?

@drewbarontini
Copy link
Author

  • sass-lint v1.3.3
  • Running sass-lint or sass-lint -c .sass-lint.yml triggers the error
  • Yes, using the .sass indented syntax

@DanPurdy
Copy link
Member

DanPurdy commented Dec 3, 2015

Ok great,

Could you try disabling the final newline rule please and see if you still get an error?

Could you also try linting against only one of your source files (specify the file with the CLI) and if if it produces the error, provide the last few lines of your source file.

Thanks

@drewbarontini
Copy link
Author

If I set final-newline: 0, I get a different error:

/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/lib/rules/extends-before-declarations.js:17
          if (item.first('atkeyword').first('ident').content === 'extend') {
                   ^

TypeError: Cannot read property 'first' of undefined
    at /Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/lib/rules/extends-before-declarations.js:17:38
    at Node.forEach (/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/node/basic-node.js:1:2053)
    at /Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/lib/rules/extends-before-declarations.js:15:13
    at RootNode.traverseByType (/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/node_modules/gonzales-pe/lib/node/root-node.js:1:1739)
    at Object.module.exports.detect (/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/lib/rules/extends-before-declarations.js:12:9)
    at /Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/index.js:44:27
    at Array.forEach (native)
    at Function.sassLint.lintText (/Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/index.js:43:11)
    at /Users/USERNAME/.nvm/versions/node/v5.0.0/lib/node_modules/sass-lint/index.js:91:21
    at Array.forEach (native)

@DanPurdy
Copy link
Member

DanPurdy commented Dec 7, 2015

Would you be able to send us a sample of the offending code?

@drewbarontini
Copy link
Author

@DanPurdy As in the .sass-lint.yml file?

@DanPurdy
Copy link
Member

DanPurdy commented Dec 8, 2015

No, if you could possibly narrow down on your sass to find where these issues are occurring or even a file, we'd be able to recreate the issues. It's something to do with the rules themselves actually failing on some of your code.

@drewbarontini
Copy link
Author

The test .sass file just has this:

body
  background: pink

@DanPurdy
Copy link
Member

DanPurdy commented Dec 8, 2015

And that alone causes all of the errors to happen?

@drewbarontini
Copy link
Author

When directly running sass-lint, yes. I have a Gulp task using gulp-sass-lint that works perfectly fine on the same file. This is the output from the Gulp task:

error    Color literals such as 'pink' should only be used in variable declarations
warning  Files must not end with a new line

@DanPurdy
Copy link
Member

DanPurdy commented Dec 8, 2015

There must be something else going on here.. The CLI is working as expected it seems but there's an issue with the rules. If these rules are working through Gulp then there must be some slight subtle difference happening.

I notice you aren't specifying a target when using the CLI, if you don't then it automatically defaults to whatever is in your config file under the files include/exclude if you aren't specifying those and dont have merge-default-rules: false in your config then it'll use the glob in our default config which is files: include: '**/*.s+(a|c)ss' so effectively any and all sass or scss file anywhere in any directory down from where you ran the sass-lint task.

Is there a chance it's actually another file causing your issue. Could you run the CLI specifically against this file explicitly to make sure as I can't recreate the issue at all at the moment..

sass-lint this-file.sass -c path-to-config -vq

@drewbarontini
Copy link
Author

Okay, running the following did indeed work:

sass-lint source/stylesheets/application.sass -c .sass-lint.yml -vq

So do I have to run with all the arguments specified, or do I just need to change the include option in the .sass-lint.yml file?

@DanPurdy
Copy link
Member

DanPurdy commented Dec 9, 2015

it's up to you, you can change it in your .sass-lint.yml file.

if you don't specify a file or a glob pattern with the CLI it will fall back to the other methods. The order of preference being a file/glob pattern passed into the CLI, the result of the include/exclude files or glob patterns in your .sass-lint.yml and if you dont have one of those it will fall back to our included config file which will be a glob of **/*.s+(a|c)ss so essentially and all sass or scss files found in any folder below where you just ran the CLI command.

As you say though if you change the include option in your config file and then run sass-lint from the directory that includes this config file you could just get away with running sass-lint although id normally run it with the -v flag too to make sure you see all your warnings as well as errors.

You can find some useful information to explain this a bit better than I just have in our docs

It's also important to remember that if you do use glob patterns directly with the CLI you need to wrap them in quote or escape each *

e.g.
sass-lint '**/*.sass' -c path-to-config

Will close this issue but it still does mean there's an error in some our rules for sass. Will look into those though.

Thanks!

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

2 participants