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
jshint doesn't expect regexp literals in one-liners following if/while/for conditions, and also else #3635
Comments
Also, be sure that regexp literals are not expected after |
Confirmed; thanks for the report! This looks to be a problem with the tokenizer--JSHint uses a naive (but, to my mind, surprisingly effective) heuristic for disambiguating the solidus. It's getting tripped up on the closing parenthesis, so the consequent bodies of ASI makes it possible to observe the same faulty behavior for "do/while" loops: do {} while (0) /./; Though the real trouble with ASI comes from the closing brace character. JSHint incorrectly rejects each of these lines: switch (0) {} /./;
try {} catch (e) {} /./;
try {} finally {} /./;
{} /./;
function f() {} /./;
class C {} /./; There are many ways to reformat the source code to avoid this problem: -do {} while (0) /./;
+do {} while (0); /./;
-switch (0) {} /./;
+switch (0) {}
+/./;
-try {} catch (e) {} /./;
+try {} catch (e) {} (/./);
-try {} finally {} /./;
+try {} finally {} void /./; To be sure: JSHint should be fixed, but those are some tips for folks that need a workaround in the mean time. This a pretty fundamental problem, but because it's rarely triggered in practice (as evidenced by the novelty of this report and JSHint's age), because there are many ways to avoid it, and because the fix will likely require non-trivial effort, I'm considering the fix low-priority. |
Don't forget you can also use |
Trying this in vscode:
Several error underlines occur, but they shouldn't. Thanks! :)
The text was updated successfully, but these errors were encountered: