Skip to content

Commit

Permalink
[[Fix]] Abort in the presence of invalid config
Browse files Browse the repository at this point in the history
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 9, 2015
1 parent 98d4d28 commit 767c47d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 "{":
Expand Down
44 changes: 38 additions & 6 deletions tests/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 767c47d

Please sign in to comment.