Permalink
Browse files

[[FIX]] Do not duplicate reported warnings/errors

Extend the testing infrastructure to recognize cases where identical
warnings/errors are being reported, and address the areas of the code
base that previously suffered from this problem.
  • Loading branch information...
jugglinmike committed Oct 18, 2016
1 parent 3b06d01 commit dc4a4fe1928a9e0ed715554d49add84d0bf22423
Showing with 17 additions and 12 deletions.
  1. +3 −10 src/jshint.js
  2. +14 −2 tests/helpers/testhelper.js
@@ -1346,13 +1346,7 @@ var JSHINT = (function() {
state.nameStack.set(state.tokens.prev);
return true;
} else if (left.id === "{" || left.id === "[") {
if (allowDestructuring && left.destructAssign) {
left.destructAssign.forEach(function(t) {
if (t.id) {
state.funct["(scope)"].block.modify(t.id, t.token);
}
});
} else {
if (!allowDestructuring || !left.destructAssign) {
if (left.id === "{" || !left.left) {
warning("E031", assignToken);
} else if (left.left.value === "arguments" && !state.isStrict()) {
@@ -4425,10 +4419,9 @@ var JSHINT = (function() {
stmt("continue", function() {
var v = state.tokens.next.value;

if (state.funct["(breakage)"] === 0)
warning("W052", state.tokens.next, this.value);
if (!state.funct["(loopage)"])
if (state.funct["(breakage)"] === 0 || !state.funct["(loopage)"]) {
warning("W052", state.tokens.next, this.value);
}

if (!state.option.asi)
nolinebreak(this);
@@ -111,6 +111,12 @@ exports.setup.testRun = function (test, name) {
}).filter(function (er) {
return !!er;
});
var duplicateErrors = errors.filter(function (er) {
return errors.filter(function (other) {
return er.line === other.line && er.character === other.character &&
er.reason === other.reason;
}).length > 1;
});

// remove undefined errors, if there is a definition with wrong line number
undefinedErrors = undefinedErrors.filter(function (er) {
@@ -125,8 +131,10 @@ exports.setup.testRun = function (test, name) {
});

test.ok(
undefinedErrors.length === 0
&& unthrownErrors.length === 0 && wrongLineNumbers.length === 0,
undefinedErrors.length === 0 &&
unthrownErrors.length === 0 &&
wrongLineNumbers.length === 0 &&
duplicateErrors.length === 0,

(name === null ? "" : "\n TestRun: [bold]{" + name + "}") +
unthrownErrors.map(function (el, idx) {
@@ -140,6 +148,10 @@ exports.setup.testRun = function (test, name) {
wrongLineNumbers.map(function (el, idx) {
return (idx === 0 ? "\n [yellow]{Errors with wrong line number}\n" : "") +
" [bold]{Line " + el.line + "} " + el.message + " [red]{not in line(s)} [bold]{" + el.definedIn.join(", ") + "}";
}).join("\n") +
duplicateErrors.map(function (el, idx) {
return (idx === 0 ? "\n [yellow]{Duplicated errors}\n": "") +
" [bold]{Line " + el.line + ", Char " + el.character + "} " + el.reason;
}).join("\n") + "\n"
);
}

0 comments on commit dc4a4fe

Please sign in to comment.