Skip to content

Commit

Permalink
[[FIX]] Always warn about missing "use strict" directive
Browse files Browse the repository at this point in the history
Fixes gh-2668
  • Loading branch information
nicolo-ribaudo authored and jugglinmike committed Sep 20, 2015
1 parent 5c96bf8 commit e85c2a1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/jshint.js
Expand Up @@ -1671,7 +1671,9 @@ var JSHINT = (function() {

r = expression(0, true);

if (r && (!r.identifier || r.value !== "function") && (r.type !== "(punctuator)")) {
if (r && !(r.identifier && r.value === "function") &&
!(r.type === "(punctuator)" && r.left &&
r.left.identifier && r.left.value === "function")) {
if (!state.isStrict() &&
state.option.strict === "global") {
warning("E007");
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/options.js
Expand Up @@ -1651,6 +1651,10 @@ exports.strict = function (test) {
.addError(1, 'Use the function form of "use strict".')
.test(code3, { strict: "func", node: true });

TestRun(test, "gh-2668")
.addError(1, "Missing \"use strict\" statement.")
.test("a = 2;", { strict: "global" });

test.done();
};

Expand Down Expand Up @@ -1684,6 +1688,7 @@ exports.globalstrict = function (test) {
];
TestRun(test)
.addError(1, 'Missing "use strict" statement.')
.addError(2, 'Missing "use strict" statement.')
.test(code, { globalstrict: true, strict: true });

// globalscript does not prevent you from using only the function-mode
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/parser.js
Expand Up @@ -6960,6 +6960,7 @@ exports.testStrictDirectiveASI = function (test) {
.test("'use strict'\n(function fn() {})();", options);

TestRun(test, 5)
.addError(2, "Missing \"use strict\" statement.")
.test("'use strict'\n[0] = '6';", options);

TestRun(test, 6)
Expand All @@ -6969,6 +6970,7 @@ exports.testStrictDirectiveASI = function (test) {
.test("'use strict',function fn() {}\nfn();", options);

TestRun(test, 7)
.addError(1, "Missing \"use strict\" statement.")
.test("'use strict'.split(' ');", options);

TestRun(test, 8)
Expand Down

0 comments on commit e85c2a1

Please sign in to comment.