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

Confusing error when linting file with a bunch of empty array elements #495

Closed
pdehaan opened this Issue Jan 8, 2014 · 5 comments

Comments

Projects
None yet
3 participants
@pdehaan
Contributor

pdehaan commented Jan 8, 2014

Steps to reproduce:

  1. Run ESLint (i used v0.2.0) against the following code:
var Xb = [ , ];

console.log(Xb);
console.log(Xb.length);

Actual results:

$ eslint *.js

/usr/local/lib/node_modules/eslint/lib/eslint.js:359
            line: location.line || node.loc.start.line,
                                       ^
TypeError: Cannot read property 'loc' of null
    at EventEmitter.module.exports.api.report (/usr/local/lib/node_modules/eslint/lib/eslint.js:359:40)
    at RuleContext.report (/usr/local/lib/node_modules/eslint/lib/rule-context.js:63:16)
    at EventEmitter.checkForTrailingComma (/usr/local/lib/node_modules/eslint/lib/rules/no-comma-dangle.js:26:21)
    at EventEmitter.emit (events.js:95:17)
    at Controller.controller.traverse.enter (/usr/local/lib/node_modules/eslint/lib/eslint.js:318:25)
    at Controller.__execute (/usr/local/lib/node_modules/eslint/node_modules/estraverse/estraverse.js:313:31)
    at Controller.traverse (/usr/local/lib/node_modules/eslint/node_modules/estraverse/estraverse.js:389:28)
    at EventEmitter.module.exports.api.verify (/usr/local/lib/node_modules/eslint/lib/eslint.js:316:24)
    at processFile (/usr/local/lib/node_modules/eslint/lib/cli.js:117:27)
    at /usr/local/lib/node_modules/eslint/lib/cli.js:168:27

$ eslint --version
v0.2.0

Expected results:
No error (or better error messaging) since the code works in Node.js:

$ node foo.js
[ ,  ]
2
@nzakas

This comment has been minimized.

Show comment
Hide comment
@nzakas

nzakas Jan 8, 2014

Member

Looks like a problem with the no-comma-dangle rule. Likely an edge case we missed.

Member

nzakas commented Jan 8, 2014

Looks like a problem with the no-comma-dangle rule. Likely an edge case we missed.

@michaelficarra

This comment has been minimized.

Show comment
Hide comment
@michaelficarra

michaelficarra Jan 8, 2014

Member

Yep: https://github.com/nzakas/eslint/blob/b7e9855760daf39889cd78b93291ebd09dcefc67/lib/rules/no-comma-dangle.js#L26

items may contain null values. @nzakas: I think the rule should not report when the last element is a hole (since the trailing comma is necessary). If you disagree, what node should be reported when the last element is a hole? What if every element is a hole?

Member

michaelficarra commented Jan 8, 2014

Yep: https://github.com/nzakas/eslint/blob/b7e9855760daf39889cd78b93291ebd09dcefc67/lib/rules/no-comma-dangle.js#L26

items may contain null values. @nzakas: I think the rule should not report when the last element is a hole (since the trailing comma is necessary). If you disagree, what node should be reported when the last element is a hole? What if every element is a hole?

michaelficarra added a commit to michaelficarra/eslint that referenced this issue Jan 8, 2014

@nzakas nzakas closed this in #498 Jan 8, 2014

nzakas added a commit that referenced this issue Jan 8, 2014

Merge pull request #498 from michaelficarra/GH-495
fixes #495: holey arrays cause no-comma-dangle rule to throw
@nzakas

This comment has been minimized.

Show comment
Hide comment
@nzakas

nzakas Jan 8, 2014

Member

I agree. I think this is a bit difficult to work with. Is there a signal
that the dangling comma was intentional? For instance, maybe a comma
preceded and followed by white space is a signal that it was intentional?

Member

nzakas commented Jan 8, 2014

I agree. I think this is a bit difficult to work with. Is there a signal
that the dangling comma was intentional? For instance, maybe a comma
preceded and followed by white space is a signal that it was intentional?

@michaelficarra

This comment has been minimized.

Show comment
Hide comment
@michaelficarra

michaelficarra Jan 8, 2014

Member

The indicator is that no expression precedes it. In that case, it's very likely an intentional hole (and we can't flag that anyway, since that's the only way to create a hole in an array literal). This is the way I've implemented it in #498, which has already been merged.

Member

michaelficarra commented Jan 8, 2014

The indicator is that no expression precedes it. In that case, it's very likely an intentional hole (and we can't flag that anyway, since that's the only way to create a hole in an array literal). This is the way I've implemented it in #498, which has already been merged.

@nzakas

This comment has been minimized.

Show comment
Hide comment
@nzakas

nzakas Jan 8, 2014

Member

Sweet!

Member

nzakas commented Jan 8, 2014

Sweet!

@eslint eslint bot locked and limited conversation to collaborators Feb 7, 2018

@eslint eslint bot added the archived due to age label Feb 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.