You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
constarr=[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
The text was updated successfully, but these errors were encountered:
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.
Consider this code:
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:
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
The text was updated successfully, but these errors were encountered: