Skip to content

Commit

Permalink
[[FIX]] Relax restriction on module option
Browse files Browse the repository at this point in the history
While the `module` option is intended to be set before executable code,
this restriction should only be enforced when it is first enabled (and
not with the application of every in-line directive).
  • Loading branch information
jugglinmike authored and lukeapage committed Jul 19, 2015
1 parent 16f5779 commit 56c19a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,6 @@ var JSHINT = (function() {
}

if (state.option.module) {
/**
* TODO: Extend this restriction to *all* "environmental" options.
*/
if (!hasParsedCode(state.funct)) {
error("E055", state.tokens.next, "module");
}

/**
* TODO: Extend this restriction to *all* ES6-specific options.
*/
Expand Down Expand Up @@ -630,6 +623,15 @@ var JSHINT = (function() {
return;
}

if (key === "module") {
/**
* TODO: Extend this restriction to *all* "environmental" options.
*/
if (!hasParsedCode(state.funct)) {
error("E055", state.tokens.next, "module");
}
}

var match = /^([+-])(W\d{3})$/g.exec(key);
if (match) {
// ignore for -W..., unignore for +W...
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2930,5 +2930,13 @@ exports.module.declarationRestrictions = function( test ) {
"/* jshint module: true */"
], { esnext: true });

TestRun(test, "Not re-applied with every directive (gh-2560)")
.test([
"/* jshint module:true */",
"function bar() {",
" /* jshint validthis:true */",
"}"
], { esnext: true });

test.done();
};

0 comments on commit 56c19a5

Please sign in to comment.