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

Commit

Permalink
Errors: always add to line and column properties
Browse files Browse the repository at this point in the history
Ref #2243
Ref #2219
  • Loading branch information
markelog committed May 13, 2016
1 parent bbb03b5 commit 729db94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
},

Expand Down
20 changes: 15 additions & 5 deletions test/specs/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,29 @@ 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');

var error = errors.getErrorList()[0];

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() {
Expand Down

0 comments on commit 729db94

Please sign in to comment.