diff --git a/lib/errors.js b/lib/errors.js index 0be031f07..03d9ec2b3 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -68,8 +68,8 @@ Errors.prototype = { filename: this._file.getFilename(), rule: 'parseError', message: errorInfo.message, - line: errorInfo.loc && errorInfo.loc.line, - column: errorInfo.loc && errorInfo.loc.column + line: errorInfo.loc ? errorInfo.loc.line : 1, + column: errorInfo.loc ? errorInfo.loc.column : 0 }); }, diff --git a/test/specs/errors.js b/test/specs/errors.js index 219eee18b..672f8cc5c 100644 --- a/test/specs/errors.js +++ b/test/specs/errors.js @@ -124,12 +124,9 @@ describe('errors', function() { }); describe('add', function() { - var errors; - beforeEach(function() { - errors = checker.checkString('yay'); - }); - it('should not throw with good parameters', function() { + var errors = checker.checkString('yay'); + errors.setCurrentRule('anyRule'); errors.add('msg'); @@ -137,6 +134,19 @@ describe('errors', function() { expect(error.rule).to.equal('anyRule'); }); + + it('adds parser error without `line` & `column` propertys even there is none', + function() { + var errors = checker.checkString(''); + + errors.add(new Error('test')); + + var error = errors.getErrorList()[0]; + + expect(error.line).to.equal(1); + expect(error.column).to.equal(0); + } + ); }); describe('cast', function() {