Skip to content

Commit

Permalink
[[FIX]] emit I003 more carefully and less annoyingly
Browse files Browse the repository at this point in the history
- Allows toggling es5 mode on/off if anyone needs that
- Only warns if the es5 option is explicitly set

Closes #2251
  • Loading branch information
caitp authored and rwaldron committed Apr 10, 2015
1 parent 1888ee3 commit 757fb73
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ var JSHINT = (function() {
}

function assume() {
if (state.option.es5) {
warning("I003");
}

processenforceall();

if (!state.option.es3) {
Expand Down Expand Up @@ -364,7 +360,7 @@ var JSHINT = (function() {
msg = messages.info[code];
}

t = t || state.tokens.next;
t = t || state.tokens.next || {};
if (t.id === "(end)") { // `~
t = state.tokens.curr;
}
Expand Down Expand Up @@ -505,7 +501,6 @@ var JSHINT = (function() {
var nt = state.tokens.next;
var body = nt.body.split(",").map(function(s) { return s.trim(); });
var predef = {};

if (nt.type === "globals") {
body.forEach(function(g) {
g = g.split(":");
Expand Down Expand Up @@ -593,6 +588,12 @@ var JSHINT = (function() {
return;
}

if (key === "es5") {
if (val === "true" && state.option.es5) {
warning("I003");
}
}

if (key === "validthis") {
// `validthis` is valid only within a function scope.

Expand Down Expand Up @@ -5155,9 +5156,15 @@ var JSHINT = (function() {
if (/^-W\d{3}$/g.test(optionKeys[x])) {
newIgnoredObj[optionKeys[x].slice(1)] = true;
} else {
newOptionObj[optionKeys[x]] = o[optionKeys[x]];
var optionKey = optionKeys[x];
newOptionObj[optionKey] = o[optionKey];
if (optionKey === "es5") {
if (o[optionKey]) {
warning("I003");
}
}

if (optionKeys[x] === "newcap" && o[optionKeys[x]] === false)
if (optionKeys[x] === "newcap" && o[optionKey] === false)
newOptionObj["(explicitNewcap)"] = true;
}
}
Expand Down
63 changes: 63 additions & 0 deletions tests/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2327,3 +2327,66 @@ exports.varstmt = function (test) {

test.done();
};

exports.errorI003 = function(test) {
var code = [
"// jshint browser: true",
"function f() {",
" // jshint browser: false",
"}",
"f();"
];

TestRun(test, "no es5 option with enforceall")
.test(code, { enforceall: true });

TestRun(test, "global overriding es5")
.addError(0, "ES5 option is now set per default")
.test(code, { es5: true });

var code2 = [
"// jshint browser: true",
"function f() {",
" // jshint es5: true",
"}",
"f();"
];

TestRun(test, "nested overriding es5")
.addError(3, "ES5 option is now set per default")
.test(code2, { enforceall: true });

var code3 = [
"// jshint es5: false",
"// jshint es5: true",
"// jshint es5: false",
"// jshint es5: true"
];

TestRun(test, "toggling es5 option")
.test(code3, {});

var code4 = [
"// jshint es5: false",
"function a() {",
" // jshint es5: true",
" function b() {",
" // jshint es5: false",
" function c() {",
" // jshint es5: true",
" function d() {",
" }",
" d();",
" }",
" c();",
" }",
" b();",
"}",
"a();"
];

TestRun(test, "toggling es5 option through nested scopes")
.test(code4, {});

test.done();
};

0 comments on commit 757fb73

Please sign in to comment.