Skip to content

Commit

Permalink
finalNewline should ignore empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilsson committed Sep 23, 2015
1 parent 08eaeec commit 306ade2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/linters/final_newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function (options) {

maybeLine = node.content[node.content.length - 1];

if (maybeLine.type !== 'space' && maybeLine.content !== '\n') {
if (maybeLine && (maybeLine.type !== 'space' && maybeLine.content !== '\n')) {
return {
column: null,
line: null,
Expand Down
17 changes: 17 additions & 0 deletions test/specs/linters/final_newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ describe('lesshint', function () {
assert.deepEqual(actual, expected);
});

it('should ignore empty files', function () {
var source = '';
var ast;
var options = {
finalNewline: {
enabled: true
}
};

ast = linter.parseAST(source);

assert.equal(null, finalNewline({
config: options,
node: ast
}));
});

it('should return null when disabled', function () {
var source = '.foo {}';
var ast;
Expand Down

0 comments on commit 306ade2

Please sign in to comment.