WebStorm 4.0.3 auto adding "use strict" pragma in JavaScript


WebStorm seems to be auto adding the "use strict"; pragma everytime I create a new function in JavaScript. I wouldn't mind if it was doing it in a smart way, but its adding it to every single function as soon as I declare it whether its needed it or not.

I've looked through the settings and can't find any way to adjust this behaviour. Can anyone help?




Hi Jed,
You should uncheck "Prefer Strict mode" in Settings | JavaScript. When this setting is on, editor inserts "use strict" statements unless there is one in parents scopes(i.e. in file).
When do you expect it not to insert such statements? I couldn't think up a better solution:)



Thanks for the info, that worked.

When I was searching on the settings for word "strict" that option didn't appear, which is why I missed it ...

As far as I understand it "use strict" only has to be declared once, somewhere up the function scope hierarachy in order to be valid everywhere, so generally its defined very early on. Seems like the approach at the moment is going to have a lot of false positives for insertions of "use strict". If we can't reliably assertain when to insert it perhaps the auto-insertion option is not all that useful? At the very least I wouldn't expect it to appear in module or class methods ...




How about modifying the "Prefer strict mode" option to only add the line at the top of a new js file?


"use strict" pragmas are not added into functions if there's already one at the top of the file. They are added to empty functions on pressing enter inside them, it's hard to decide when to add it to a file. You may use predefined live template us<tab> to insert "use strict" manually.


I am merely suggesting that if Prefer strict mode is smart enough to know the difference between a js file that has "use strict"; at the top of a file, thereby preventing the insertion of the code into every new function I create (which is a real nuisance), that it should be possible to make it even smarter by adding the line as the first line of creating a new js file and not adding it upon the creation of a new function within the file (which it does not currently do). Then I only have to decide once if I want to keep it or discard it.

In the present situation I either have to turn it off altogether (thereby never getting the benefit of the insertion) or I leave it on and continue to get it every time I create a new function until I take the time to manually insert it at the top, at which point I have to remove it from every place I have not already done so.

I'm just telling you what I'd like to see. It is not a hill I am willing to die on though.


Please sign in to leave a comment.