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
No undeclared variable warning with function form of 'use strict' #3620
Comments
Thanks for taking the time to write a report! This behavior surprised me, too. Here's what's going on:
One way to understand the net effect is that JSHint is simulating variable name resolution. JavaScript's global environment record is highly dynamic, so it's not possible to do this correctly just by looking at the source code. We're seeing an edge-case in a best-effort solution. The inconsistency is jarring, though, and it's important to recognize that the behavior isn't directly tied to the interpretation of the language. The semantics of strict-mode code do not influence how bindings are resolved. As far as I can tell, automatically enabling Does that make sense, @elavy-harris? Do you have any opinion here? |
Thank you @jugglinmike . I understand the idea of turning on I'm pretty new to this environment, so that limits the value of my opinion. I would guess, though, that there are a lot of people using global strict mode and that they would be very unhappy if you remove "auto-undef". If you can't turn on |
In regard to the Another way to understand this is that Does that clear things up at all? The takeaway here is in order to enforce this behavior consistently, don't rely on the presence of the "use strict" directive. Instead, explicitly enable the |
I think it does. Thanks. |
... in function-based "use strict": <jshint/jshint#3620>
I have the following JS file in Visual Studio Code with jshint v0.11.0:
I get warnings to use the function form of 'use strict' (W097) and 'b' is not defined (W117). If I move "use strict" inside the function, I get no warnings at all. I believe that I should continue to get W117.
.jshintrc:
jshint.config:
UPDATE
I've found that adding
"undef": true,
to .jshintrc causes the W117 warning to appear, but shouldn't the existence of"use strict"
be enough?The text was updated successfully, but these errors were encountered: