Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Misc: set default value of maxErrors option to 50 #1508

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Set the maximum number of errors to report

Type: `Number`

Default: Infinity
Default: 50

#### Example

Expand Down
6 changes: 3 additions & 3 deletions lib/config/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function Configuration() {
* @protected
* @type {Number}
*/
this._maxErrors = Infinity;
this._maxErrors = 50;

/**
* JSCS CWD.
Expand Down Expand Up @@ -567,8 +567,8 @@ Configuration.prototype._loadMaxError = function(maxErrors) {
maxErrors = maxErrors === null ? null : Number(maxErrors);

assert(
maxErrors > 0 || isNaN(maxErrors) || maxErrors === null,
'`maxErrors` option requires number or null value'
maxErrors > 0 || maxErrors === null,
'`maxErrors` option requires positive number or null value'
);
this._maxErrors = maxErrors;
};
Expand Down
6 changes: 1 addition & 5 deletions lib/string-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,6 @@ StringChecker.prototype = {
* @returns {{output: String, errors: Errors}}
*/
fixString: function(source, filename) {
if (this._maxErrorsEnabled()) {
throw new Error('Cannot autofix when `maxError` option is enabled');
}

filename = filename || 'input';

var file = this._createJsFileInstance(filename, source);
Expand Down Expand Up @@ -300,7 +296,7 @@ StringChecker.prototype = {
* @returns {Boolean}
*/
_maxErrorsEnabled: function() {
return !isNaN(this._maxErrors) && this._maxErrors !== Infinity;
return this._maxErrors !== null;
},

/**
Expand Down
2 changes: 1 addition & 1 deletion test/specs/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var sinon = require('sinon');
var Checker = require('../../lib/checker');
var fs = require('fs');

describe('modules/checker', function() {
describe('checker', function() {
var checker;

beforeEach(function() {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/cli-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var rewire = require('rewire');

var configFile = rewire('../../lib/cli-config');

describe('modules/cli-config', function() {
describe('cli-config', function() {
describe('load method', function() {
it('should load a config from a package.json file', function() {
var config = configFile.load('package.json', './test/data/configs/package');
Expand Down
9 changes: 6 additions & 3 deletions test/specs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var startingDir = process.cwd();

var Vow = require('vow');

describe('modules/cli', function() {
describe('cli', function() {
var oldTTY;

before(function() {
Expand Down Expand Up @@ -567,10 +567,12 @@ describe('modules/cli', function() {
describe('maxErrors option', function() {
beforeEach(function() {
sinon.spy(console, 'log');
sinon.spy(console, 'error');
});

afterEach(function() {
console.log.restore();
console.error.restore();
});

it('should limit the number of errors reported to the provided amount', function() {
Expand All @@ -585,14 +587,15 @@ describe('modules/cli', function() {
});
});

it('should not limit the number of errors reported if non numeric value provided', function() {
it('should throw a error when value is incorrect', function() {
return cli({
maxErrors: '1a',
args: ['test/data/cli/error.js'],
config: 'test/data/cli/maxErrors.json'
})
.promise.always(function() {
assert(console.log.getCall(2).args[0].indexOf('2 code style errors found.') !== -1);
assert(console.error.getCall(0).args[0]
.indexOf('`maxErrors` option requires positive number or null value') !== -1);
rAfter();
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/specs/config/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var assert = require('assert');
var sinon = require('sinon');
var Configuration = require('../../../lib/config/configuration');

describe('modules/config/configuration', function() {
describe('config/configuration', function() {

var configuration;
beforeEach(function() {
Expand Down Expand Up @@ -35,8 +35,8 @@ describe('modules/config/configuration', function() {
assert(configuration.getExcludedFileMasks().length === 0);
});

it('should have no default maximal error count', function() {
assert(configuration.getMaxErrors() === Infinity);
it('should have 50 default error count', function() {
assert(configuration.getMaxErrors() === 50);
});

it('should have no default preset', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/errors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var Checker = require('../../lib/checker');
var assert = require('assert');

describe('modules/errors', function() {
describe('errors', function() {
var checker;

beforeEach(function() {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/js-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var sinon = require('sinon');
var fs = require('fs');
var assign = require('lodash.assign');

describe('modules/js-file', function() {
describe('js-file', function() {

function createJsFile(sources, options) {
var params = {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/rules/validate-indentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('rules/validate-indentation', function() {

it('should validate 2 spaces indentation properly', function() {
var fixture = readData('validate-indentation/check.js');
checker.configure({ validateIndentation: 2 });
checker.configure({ validateIndentation: 2, maxErrors: Infinity });
checkErrors(fixture, [
5,
6,
Expand Down
6 changes: 3 additions & 3 deletions test/specs/string-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var assert = require('assert');
var sinon = require('sinon');
var fs = require('fs');

describe('modules/string-checker', function() {
describe('string-checker', function() {
var checker;
beforeEach(function() {
checker = new StringChecker();
Expand Down Expand Up @@ -86,11 +86,11 @@ describe('modules/string-checker', function() {
assert(errors2.length === 0);
});

it('should not be used when not a number', function() {
it('should not be used when it is nullified', function() {
var errors;
checker.configure({
requireSpaceBeforeBinaryOperators: ['='],
maxErrors: NaN
maxErrors: null
});

errors = checker.checkString('var foo=1;\n var bar=2;').getErrorList();
Expand Down
2 changes: 1 addition & 1 deletion test/specs/token-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var esprima = require('esprima');
var JsFile = require('../../lib/js-file');
var TokenAssert = require('../../lib/token-assert');

describe('modules/token-assert', function() {
describe('token-assert', function() {

function createJsFile(sources) {
return new JsFile({
Expand Down
2 changes: 1 addition & 1 deletion test/specs/tree-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var esprima = require('esprima');
var sinon = require('sinon');
var iterate = require('../../lib/tree-iterator').iterate;

describe('modules/tree-iterator', function() {
describe('tree-iterator', function() {

it('should pass parent and parentCollection', function() {
var spy = sinon.spy();
Expand Down
2 changes: 1 addition & 1 deletion test/specs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var JsFile = require('../../lib/js-file');
var esprima = require('esprima');
var path = require('path');

describe('modules/utils', function() {
describe('utils', function() {

function createJsFile(source) {
return new JsFile({
Expand Down