Skip to content

Commit 4a681b9

Browse files
authored
[[FIX]] Limit "Too many Errors" (E043) to errors only (#3562)
* [[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.
1 parent fddcd02 commit 4a681b9

4 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/jshint.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,10 @@ var JSHINT = (function() {
423423

424424
removeIgnoredMessages();
425425

426-
if (JSHINT.errors.length >= state.option.maxerr)
426+
var errors = JSHINT.errors.filter(function(e) { return /E\d{3}/.test(e.code); });
427+
if (errors.length >= state.option.maxerr) {
427428
quit("E043", t);
428-
429+
}
429430
return w;
430431
}
431432

src/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ exports.val = {
820820
indent : false,
821821

822822
/**
823-
* This options allows you to set the maximum amount of warnings JSHint will
823+
* This options allows you to set the maximum amount of errors JSHint will
824824
* produce before giving up. Default is 50.
825825
*/
826826
maxerr : false,

tests/unit/core.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,17 @@ exports.argsInCatchReused = function (test) {
421421
test.done();
422422
};
423423

424-
exports.testRawOnError = function (test) {
424+
exports.testRawOnWarning = function (test) {
425425
JSHINT(';', { maxerr: 1 });
426426
test.equal(JSHINT.errors[0].raw, 'Unnecessary semicolon.');
427+
test.equal(JSHINT.errors[1], null);
428+
429+
test.done();
430+
};
431+
432+
exports.testRawOnError = function (test) {
433+
JSHINT('@', { maxerr: 1 });
434+
test.equal(JSHINT.errors[0].raw, 'Unexpected \'{a}\'.');
427435
test.equal(JSHINT.errors[1].raw, 'Too many errors.');
428436
test.equal(JSHINT.errors[2], null);
429437

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

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

475-
// Regression test for bug GH-714.
476-
JSHINT(src, { evil: false, maxerr: 1 });
477-
var err = JSHINT.data().errors[1];
478-
test.equal(err.raw, "Too many errors.");
479-
test.equal(err.scope, "(main)");
480-
481483
test.done();
482484
};
483485

tests/unit/parser.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9142,7 +9142,14 @@ exports.restOperatorWithoutIdentifier = function (test) {
91429142
.addError(8, 24, "Expected an identifier and instead saw ')'.")
91439143
.addError(8, 26, "Expected ',' and instead saw '=>'.")
91449144
.addError(8, 30, "Expected ',' and instead saw ';'.")
9145-
.addError(8, 30, "Too many errors. (44% scanned).")
9145+
.addError(9, 1, "Expected an identifier and instead saw 'var' (a reserved word).")
9146+
.addError(9, 5, "Expected ',' and instead saw 'arrow3'.")
9147+
.addError(9, 12, "Expected an identifier and instead saw '='.")
9148+
.addError(9, 14, "Expected ',' and instead saw '('.")
9149+
.addError(9, 19, "Expected an identifier and instead saw ']'.")
9150+
.addError(9, 20, "Expected ',' and instead saw ')'.")
9151+
.addError(9, 22, "Expected an identifier and instead saw '=>'.")
9152+
.addError(9, 22, "Too many errors. (50% scanned).")
91469153
.test(code, { esnext: true });
91479154

91489155
test.done();

0 commit comments

Comments
 (0)