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

[suggestion] Missing commas in array of arrays #3564

Open
Nondv opened this issue Aug 20, 2021 · 3 comments
Open

[suggestion] Missing commas in array of arrays #3564

Nondv opened this issue Aug 20, 2021 · 3 comments
Labels

Comments

@Nondv
Copy link

Nondv commented Aug 20, 2021

Consider this code:

const arr = [
  [1, 2],
  [3, 4],
  [5, 6]
  [7, 8],
  [9, 0],
]

This is a valid piece of code and it will execute properly. However, it's probably not something that was intended. JS allows accessing elements of an array/object via brackets with a newline character in between.

jshint warns about function invocation on the next line:

const arr = [
  1, 
  2,
  3
  (2 + 2),
  5,
]

produces a warning "Unorthodox function invocation". I think it would be great to have a similar warning for an "unorthodox" object/array accessor usage

UPD. I just checked the code, the warning has nothing to do with the fact that the braces are placed weirdly. It just doesn't like that a number is being invoked as a function. So adding this feature may be potentially hard

@Nondv
Copy link
Author

Nondv commented Aug 20, 2021

(I ran into this problem at least twice this year and it was really hard to debug)

@jugglinmike
Copy link
Member

Thanks for the suggestion! This could make for a good linting rule, though I'd suggest a slightly different heuristic. Instead of considering newlines, JSHint could look for cases where the comma operator is used in a member expression. That would catch mistakes like what you've reported regardless of how folks have formatted their code.

@NumNumNum69420
Copy link

h

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

3 participants