Skip to content

Commit

Permalink
[[FIX]] Limit "Too many Errors" (E043) to errors only (#3562)
Browse files Browse the repository at this point in the history
* [[FIX]] Ignore warnings when testing for maxerr

Makes the E043 condition trigger only for errors and not warnings

Closes #3444

* [[DOCS]] update maxerr description

This updates maxerr doc to reflect that only errors are considered

* [[TEST]] update tests to reflect maxerr ignoring warnings

Update testRawOnError, insideEval in core and restOperatorWithoutIdentifier in parser tests to reflect maxerr no longer counting in warnings.

* add braces to maintain coding style

* [[TEST]] add test to check maxerr triggering on warnings

This modifies testRawOnError to make sure maxerr constrain is applied on errors.
This adds testRawOnWarning to make sure maxerr constrain does not count warnings.
  • Loading branch information
Ashesh3 committed Aug 19, 2021
1 parent fddcd02 commit 4a681b9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,10 @@ var JSHINT = (function() {

removeIgnoredMessages();

if (JSHINT.errors.length >= state.option.maxerr)
var errors = JSHINT.errors.filter(function(e) { return /E\d{3}/.test(e.code); });
if (errors.length >= state.option.maxerr) {
quit("E043", t);

}
return w;
}

Expand Down
2 changes: 1 addition & 1 deletion src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ exports.val = {
indent : false,

/**
* This options allows you to set the maximum amount of warnings JSHint will
* This options allows you to set the maximum amount of errors JSHint will
* produce before giving up. Default is 50.
*/
maxerr : false,
Expand Down
16 changes: 9 additions & 7 deletions tests/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,17 @@ exports.argsInCatchReused = function (test) {
test.done();
};

exports.testRawOnError = function (test) {
exports.testRawOnWarning = function (test) {
JSHINT(';', { maxerr: 1 });
test.equal(JSHINT.errors[0].raw, 'Unnecessary semicolon.');
test.equal(JSHINT.errors[1], null);

test.done();
};

exports.testRawOnError = function (test) {
JSHINT('@', { maxerr: 1 });
test.equal(JSHINT.errors[0].raw, 'Unexpected \'{a}\'.');
test.equal(JSHINT.errors[1].raw, 'Too many errors.');
test.equal(JSHINT.errors[2], null);

Expand Down Expand Up @@ -472,12 +480,6 @@ exports.insideEval = function (test) {

.test(src, { es3: true, evil: false });

// Regression test for bug GH-714.
JSHINT(src, { evil: false, maxerr: 1 });
var err = JSHINT.data().errors[1];
test.equal(err.raw, "Too many errors.");
test.equal(err.scope, "(main)");

test.done();
};

Expand Down
9 changes: 8 additions & 1 deletion tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9142,7 +9142,14 @@ exports.restOperatorWithoutIdentifier = function (test) {
.addError(8, 24, "Expected an identifier and instead saw ')'.")
.addError(8, 26, "Expected ',' and instead saw '=>'.")
.addError(8, 30, "Expected ',' and instead saw ';'.")
.addError(8, 30, "Too many errors. (44% scanned).")
.addError(9, 1, "Expected an identifier and instead saw 'var' (a reserved word).")
.addError(9, 5, "Expected ',' and instead saw 'arrow3'.")
.addError(9, 12, "Expected an identifier and instead saw '='.")
.addError(9, 14, "Expected ',' and instead saw '('.")
.addError(9, 19, "Expected an identifier and instead saw ']'.")
.addError(9, 20, "Expected ',' and instead saw ')'.")
.addError(9, 22, "Expected an identifier and instead saw '=>'.")
.addError(9, 22, "Too many errors. (50% scanned).")
.test(code, { esnext: true });

test.done();
Expand Down

0 comments on commit 4a681b9

Please sign in to comment.