Skip to content

Commit

Permalink
[[FIX]] Do not duplicate reported warnings/errors
Browse files Browse the repository at this point in the history
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 cd49934 commit 1473f5a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 3 additions & 10 deletions src/jshint.js
Expand Up @@ -1347,13 +1347,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()) {
Expand Down Expand Up @@ -4410,10 +4404,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);
Expand Down
13 changes: 12 additions & 1 deletion tests/helpers/testhelper.js
Expand Up @@ -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) {
Expand All @@ -126,7 +132,8 @@ exports.setup.testRun = function (test, name) {

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

(name === null ? "" : "\n TestRun: [bold]{" + name + "}") +
unthrownErrors.map(function (el, idx) {
Expand All @@ -140,6 +147,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"
);
}
Expand Down

0 comments on commit 1473f5a

Please sign in to comment.