Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR]: Warn instead of quitting when invalid options specified #3290

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,12 @@ var JSHINT = (function() {
* Apply all linting options according to the status of the `state` object.
*/
function applyOptions() {
var badESOpt = null;
processenforceall();

/**
* TODO: Remove in JSHint 3
*/
badESOpt = state.inferEsVersion();
if (badESOpt) {
quit("E059", state.tokens.next, "esversion", badESOpt);
}
state.inferEsVersion();

if (state.inES5()) {
combine(predefined, vars.ecmaIdentifiers[5]);
Expand Down Expand Up @@ -683,6 +679,7 @@ var JSHINT = (function() {

var tn;
if (val === "true" || val === "false") {
warnIfDeprecated(key, val);
if (directiveToken.type === "jslint") {
tn = options.renamed[key] || key;
state.option[tn] = (val === "true");
Expand All @@ -693,7 +690,6 @@ var JSHINT = (function() {
} else {
state.option[key] = (val === "true");
}

return;
}

Expand Down Expand Up @@ -2653,7 +2649,7 @@ var JSHINT = (function() {
prefix("[", function() {
var blocktype = lookupBlockType();
if (blocktype.isCompArray) {
if (!state.option.esnext && !state.inMoz()) {
if (state.esVersion < 6 && !state.inMoz()) {
warning("W118", state.tokens.curr, "array comprehension");
}
return comprehensiveArrayExpression();
Expand Down Expand Up @@ -5279,6 +5275,14 @@ var JSHINT = (function() {
return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
};

function warnIfDeprecated(option, value, optionIndex) {
var m;
if ((m = /^es(next|3|5)$/.exec(option)) && value && value !== "false") {
var t = _.assign({ line: "(option " + (optionIndex + 1) + ")", from: 0 }, state.tokens.curr);
warning("W143", t, m[0], "Use 'esversion: " + (m[1].length > 1 ? "6" : m[1]) + "' instead");
}
}

// The actual JSHINT function itself.
var itself = function(s, o, g) {
var x, reIgnoreStr, reIgnore;
Expand Down Expand Up @@ -5345,7 +5349,9 @@ var JSHINT = (function() {
newIgnoredObj[optionKeys[x].slice(1)] = true;
} else {
var optionKey = optionKeys[x];
newOptionObj[optionKey] = o[optionKey];
var optionValue = o[optionKey];
warnIfDeprecated(optionKey, optionValue, x);
newOptionObj[optionKey] = optionValue;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ var warnings = {
W139: "Function expressions should not be used as the second operand to instanceof.",
W140: "Missing comma.",
W141: "Empty {a}: this is unnecessary and can be removed.",
W142: "Empty {a}: consider replacing with `import '{b}';`."
W142: "Empty {a}: consider replacing with `import '{b}';`.",
W143: "Option '{a}' is deprecated. {b}.",
};

var info = {
Expand Down