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

array comprehensions wrongly detected #1413

Closed
clux opened this issue Dec 12, 2013 · 2 comments
Closed

array comprehensions wrongly detected #1413

clux opened this issue Dec 12, 2013 · 2 comments

Comments

@clux
Copy link

clux commented Dec 12, 2013

Using the ES5 keyword 'for' as a property name can cause jshint to become confused:

var r = {
  prop1: 2,
  for: 3,
  prop3: 4
};

[r.prop1, r.for, r.prop3].every(Number.isFinite);

jshint output:

[JSHint: /home/clux/repos/badjshint.js]

    7,2: Expected 'for' and instead saw 'r'.
    7,9: Expected 'for' and instead saw ','.
   7,11: Expected '(' and instead saw 'r'.
   7,12: Expected an identifier and instead saw '.'.
   7,12: Invalid for each loop.
   7,13: Expected an identifier and instead saw 'for'.
   7,16: Expected ')' and instead saw ','.
   7,18: Expected ']' and instead saw 'r'.
   7,20: Expected an assignment or function call and instead saw an expression.
   7,25: Missing semicolon.
   7,25: Expected ']' to have an indentation at 1 instead at 25.
   7,25: Expected an identifier and instead saw ']'.
   7,26: Expected an operator and instead saw '.'.
   7,26: Expected an assignment or function call and instead saw an expression.
   7,27: Missing semicolon.
   7,27: Expected 'every' to have an indentation at 1 instead at 27.
   7,27: 'every' is not defined.

✗ 17 errors, double-click above, [F4] for next, [shift-F4] for previous.
@rwaldron
Copy link
Member

This bug is awesome, nice catch!

nicolo-ribaudo added a commit to nicolo-ribaudo/jshint that referenced this issue Jul 1, 2015
If an array contains the `for` identifier as a property of an object, it was wrongly detected as
array comprehension:
  var x = [ a.for ];

Fixes jshint#1413
@nicolo-ribaudo
Copy link
Contributor

PRed - #2509

jugglinmike pushed a commit to jugglinmike/jshint that referenced this issue Jul 5, 2015
If an array contains the `for` identifier as a property of an object, it was wrongly detected as
array comprehension:
  var x = [ a.for ];

Fixes jshint#1413
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

3 participants