Permalink
Browse files

[[Fix]] Abort in the presence of invalid config

When an invalid set of configuration values is encountered, linting
cannot continue because the expectations are ambiguous. In this event,
report the error and cease linting.
  • Loading branch information...
jugglinmike committed Dec 7, 2015
1 parent 98d4d28 commit 767c47d6482a577d7e1a3fbfad664b6a957fe56e
Showing with 45 additions and 13 deletions.
  1. +7 −7 src/jshint.js
  2. +38 −6 tests/unit/options.js
@@ -215,7 +215,7 @@ var JSHINT = (function() {
* `globalstrict` because both `true` and `false` should trigger an error.
*/
if (state.option.strict === "global" && "globalstrict" in state.option) {
error("E059", state.tokens.next, "strict", "globalstrict");
quit("E059", state.tokens.next, "strict", "globalstrict");
}

if (state.option.module) {
@@ -5325,15 +5325,15 @@ var JSHINT = (function() {
}
}

assume();
try {
assume();

// combine the passed globals after we've assumed all our options
combine(predefined, g || {});
// combine the passed globals after we've assumed all our options
combine(predefined, g || {});

//reset values
comma.first = true;
//reset values
comma.first = true;

try {
advance();
switch (state.tokens.next.id) {
case "{":
@@ -1679,13 +1679,45 @@ exports.globalstrict = function (test) {
// Don't enforce "use strict"; if strict has been explicitly set to false
TestRun(test).test(code[1], { es3: true, globalstrict: true, strict: false });

TestRun(test, "co-occurence with 'strict: global'")
.addError(0, "Incompatible values for the 'strict' and 'globalstrict' linting options.")
.test(code, { strict: "global", globalstrict: false });
TestRun(test, "co-occurence with 'strict: global' (via configuration)")
.addError(0, "Incompatible values for the 'strict' and 'globalstrict' linting options. (0% scanned).")
.test("this is not JavaScript", { strict: "global", globalstrict: false });

TestRun(test, "co-occurence with 'strict: global'")
.addError(0, "Incompatible values for the 'strict' and 'globalstrict' linting options.")
.test(code, { strict: "global", globalstrict: true });
TestRun(test, "co-occurence with 'strict: global' (via configuration)")
.addError(0, "Incompatible values for the 'strict' and 'globalstrict' linting options. (0% scanned).")
.test("this is not JavaScript", { strict: "global", globalstrict: true });

TestRun(test, "co-occurence with 'strict: global' (via in-line directive")
.addError(2, "Incompatible values for the 'strict' and 'globalstrict' linting options. (66% scanned).")
.test([
"",
"// jshint globalstrict: true",
"this is not JavaScript"
], { strict: "global" });

TestRun(test, "co-occurence with 'strict: global' (via in-line directive")
.addError(2, "Incompatible values for the 'strict' and 'globalstrict' linting options. (66% scanned).")
.test([
"",
"// jshint globalstrict: false",
"this is not JavaScript"
], { strict: "global" });

TestRun(test, "co-occurence with 'strict: global' (via in-line directive")
.addError(2, "Incompatible values for the 'strict' and 'globalstrict' linting options. (66% scanned).")
.test([
"",
"// jshint strict: global",
"this is not JavaScript"
], { globalstrict: true });

TestRun(test, "co-occurence with 'strict: global' (via in-line directive")
.addError(2, "Incompatible values for the 'strict' and 'globalstrict' linting options. (66% scanned).")
.test([
"",
"// jshint strict: global",
"this is not JavaScript"
], { globalstrict: false });

TestRun(test, "co-occurence with internally-set 'strict: gobal' (module code)")
.test(code, { strict: true, globalstrict: false, esnext: true, module: true });

0 comments on commit 767c47d

Please sign in to comment.