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

Cannot read property 'loc' of undefined when first line in file is blank #3596

Closed
dvdzkwsk opened this issue Aug 30, 2015 · 7 comments
Closed
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon

Comments

@dvdzkwsk
Copy link

It appears as though if the beginning of a file begins with a blank line eslint chokes. Package versions in question:

  • eslint @ 1.3.1
  • eslint-loader @ 1.0.0
  • babel-eslint @ 4.1.0

Relevant rule configuration; turning this off resolves the issue.

  "indent": [2, 2, {
    "SwitchCase": 1
  }]

Example code snippet that produces the issue (key is the leading blank line; this appears to be consistent across all files, in my testing).

import Immutable from 'immutable';
import { createReducer } from 'utils';
import {
  TODO_CREATE,
  TODO_DESTROY,
  TODO_TOGGLE_COMPLETE
} from 'constants/todo';

If I delete that initial empty line or add anything to it (comment, code, whatever), the issue is resolved. The empty line was totally unintentional, but led me to discover the issue. Here's the stack trace:

ERROR in ./src/reducers/todos/index.js
Module build failed: TypeError: Cannot read property 'loc' of undefined
    at getNodeIndent (/Users/zukowskid/projects/react-redux-starter-kit/node_modules/eslint/lib/rules/indent.js:112:49)
    at EventEmitter.Program (/Users/zukowskid/projects/react-redux-starter-kit/node_modules/eslint/lib/rules/indent.js:547:45)
    at emitOne (events.js:82:20)
    at EventEmitter.emit (events.js:169:7)
    at Controller.controller.traverse.enter (/Users/zukowskid/projects/react-redux-starter-kit/node_modules/eslint/lib/eslint.js:815:25)
    at Controller.__execute (/Users/zukowskid/projects/react-redux-starter-kit/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/Users/zukowskid/projects/react-redux-starter-kit/node_modules/eslint/node_modules/estraverse/estraverse.js:495:28)
    at EventEmitter.module.exports.api.verify (/Users/zukowskid/projects/react-redux-starter-kit/node_modules/eslint/lib/eslint.js:808:24)
    at processText (/Users/zukowskid/projects/react-redux-starter-kit/node_modules/eslint/lib/cli-engine.js:199:27)
    at CLIEngine.executeOnText (/Users/zukowskid/projects/react-redux-starter-kit/node_modules/eslint/lib/cli-engine.js:430:26)
    at lint (/Users/zukowskid/projects/react-redux-starter-kit/node_modules/eslint-loader/index.js:26:20)
    at Object.module.exports (/Users/zukowskid/projects/react-redux-starter-kit/node_modules/eslint-loader/index.js:120:7)

Thanks in advance, hopefully that was clear enough!

@eslintbot
Copy link

Thanks for the issue! We get a lot of issues, so this message is automatically posted to each one to help you check that you've included all of the information we need to help you.

Reporting a bug? Please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. The source code that caused the problem
  3. The configuration you're using (for the rule or your entire config file)
  4. The actual ESLint output complete with line numbers

Requesting a new rule? Please be sure to include:

  1. The use case for the rule - what is it trying to prevent or flag?
  2. Whether the rule is trying to prevent an error or is purely stylistic
  3. Why you believe this rule is generic enough to be included

Requesting a feature? Please be sure to include:

  1. The problem you want to solve (don't mention the solution)
  2. Your take on the correct solution to problem

Including this information in your issue helps us to triage it and get you a response as quickly as possible.

Thanks!

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Aug 30, 2015
@gyandeeps
Copy link
Member

Can't reproduce it with 1.3.1 without using babel-eslint.

UPDATE:
With using babel-eslint, its an issue.

@nzakas
Copy link
Member

nzakas commented Aug 31, 2015

If you can't reproduce with Espree, then it's a babel-eslint bug and an issue should be filed there.

@davezuko are you aware that you don't need babel-eslint for ES6 syntax?

@dvdzkwsk
Copy link
Author

I'll file it there then, I should have tested it with stock eslint first.

@nzakas no I guess I didn't... interesting, I'll try it out. Looking at the docs though, the es6 option states:

es6 - enable all ECMAScript 6 features except for modules.

So it looks like I'll have to keep using babel-eslint if I want to run this as as a webpack preloader? Because right now eslint just throws a bunch of "illegal import declaration" errors, and I can't find anything else regarding enabling module support in the docs.

@hzoo
Copy link
Member

hzoo commented Aug 31, 2015

http://eslint.org/docs/user-guide/configuring#specifying-language-options
Did you enable modules: true under ecmaFeatures?

Also I'm fixing this is babel-eslint now. babel/babel-eslint#180

@dvdzkwsk
Copy link
Author

@hzoo no, I must have just skimmed over that option on accident. My mistake, thanks!

hzoo added a commit to babel/babel-eslint that referenced this issue Aug 31, 2015
update eslint, acorn-to-esprima - ref eslint/eslint#3596
@hzoo
Copy link
Member

hzoo commented Aug 31, 2015

Should be fixed in 4.1.1, but it looks like you don't need babel-eslint at the moment

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon
Projects
None yet
Development

No branches or pull requests

5 participants