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
Option to assume strict mode (for nodejs) #924
Comments
There's |
Cool! I didn't notice that in the docs. My bad. |
@antonkovalyov Actually, that option isn't what I'm talking about. Node can now run Does that make sense? I was also operating under the assumption that |
+1 for |
That's a good point too. It would be generally useful to have all of the linting of use strict without having to type it for every environment since in general more people use jshint than use use strict. |
+1 for this issue. |
I don't quite follow how If I create a file which contains
With
And running with
I think there's something I'm missing about your use case. |
I was under the impression that If But it would make sense to have a separate option that allows strict mode at the file level, to avoid confusion. |
@antonkovalyov Are you okay with changing the behavior of |
@michaelmior I'd rather deprecate strict:
|
+1 sounds like a logical solution to me |
I don't like the idea of JSHint validating this strange non-JavaScript language which has the semantics of strict mode without the pragma. Such code is not ES5 conformant or at all portable, and shouldn't be encouraged. The spec very clear: source files with the pragma are strict, and those without are not. |
@domenic this is a practical option, not an ideal option. The usage here is to have a static tool do what it does best, static analysis without effecting my run time code in production. Mainly because one can't turn on strict mode as it requires removing all arguments.callee code but one does want the static strict mode validation on a file by file basis. Turning strict mode on for a single file and loading that in JS environment means you have to fix all your arguments code. Validating a file as if it is in strict mode means you just have to edit your file to comply with the warnings your static tool gives you. This basically empowers the developer with modular tooling without having to fix his entire codebase. |
I’m not sure that globalstrict is doing what the description implies. I though that globalstrict was to allow a global "use strict" pragma, not to enforce it. In any case, the version I am using seems to complain about missing "use strict" statements from within functions, regardless of whether there is one at the beginning of the script. |
Yeah, I can confirm. |
I'm using Sprockets with a custom processor to add a strict-mode IIFE around each source file script. So a file like this: // a.js
window.console.log('a'); is turned into: (function (window) {
'use strict';
// a.js
window.console.log('a');
})(this); If I want to run JSHint on any of my unprocessed source files, I cannot presently do so while also in strict mode. An option which permits an 'implicit strict mode' would serve this and similar use cases well. EDIT: edited to simplify the example |
Is this feature still considered? Not with the assumestrict, but with a multi value option of globalstrict? I would love to have an implied globalstrict. My build process takes care of concating and wrapping in self executing function with use strict. But during edit time I want the files to validate without having to have each file contain |
Sure, a multi-value option for |
@antonkovalyov I have a question, if I want to disallow usage of Actually, now that I read about it, it's confusing if it's an issue at all or not.
But then actually testing global Is it safe to just put Edit: Found the reason (under With that in mind, my first question still stands. |
You don't need to do anything. Just use |
Oh, you mean a different
And the root Thanks! :-) |
@antonkovalyov Actually, today I found out that having another So to point my issue again, I want to disallow But I wouldn't want to have 2 separate Any other suggestions? |
Seems like the ideal behaviour would be to allow |
What's the status of this? I'm unable to use JSHint with @meteor until this is fixed – what do I need to do to get a patch accepted? |
@christianbundy Write a patch first and then we can discuss it. |
Nearly two years since this was opened, is this actually implemented? |
It's not yet implemented, a patch was refused because it was mixed with other unrelated stuffs. Please, it would be nice to implement what @valueof had in mind: |
Why? 1) Some JavaScript compilers (e.g. Babel) add the "use strict" directive, so it isn't needed that it is present in the code. 2) In node.js you can use the --use_strict flag, which runs the code using strict mode. The `strict` option has now five possible values: - true / func - there must be a `"use strict";` directive at function level - global - there must be a `"use strict";` directive at global level - implied - JSHint checks the code as if there is the `"use strict";` directive - false - disable warnings about strict mode The `globalstrict` option is now deprecated, it should be used `strict: global` Close jshint#924
Why? 1) Some JavaScript compilers (e.g. Babel) add the "use strict" directive, so it isn't needed that it is present in the code. 2) In node.js you can use the --use_strict flag, which runs the code using strict mode. The `strict` option has now five possible values: - true / func - there must be a `"use strict";` directive at function level - global - there must be a `"use strict";` directive at global level - implied - JSHint checks the code as if there is the `"use strict";` directive - false - disable warnings about strict mode The `globalstrict` option is now deprecated, it should be used `strict: global` Close jshint#924
Any word on when we will have a release with this in it? I've been waiting for it for a while, and it looks like it landed in master. |
@jugglinmike can tell you, I think one is due soon. |
This gets very annoying with Babel, as it puts 'use strict'; in front of everything and explicit And the fix actually landed on |
@jugglinmike is working hard to get the next release out. It has alot of
work in it and a few regressions were identified which slowed things down.
we hope it will be soon.
|
Now that nodejs is es5 compliant it can be run in strict mode by default without including
(function () { "use strict"; /* code here */ }());
.Will you add an option
implicitstrict
so that it's not required to have the boilerplate code?The text was updated successfully, but these errors were encountered: