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

Commit

Permalink
DisallowMultipleLineBreaks: use assertions
Browse files Browse the repository at this point in the history
Refs #516
  • Loading branch information
mikesherov committed Mar 25, 2015
1 parent 5204662 commit 3aeb3dd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
20 changes: 13 additions & 7 deletions lib/rules/disallow-multiple-line-breaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,20 @@ module.exports.prototype = {
},

check: function(file, errors) {
var lines = file.getLines();
for (var i = 1, l = lines.length; i < l; i++) {
var line = lines[i];
if (line === '' && lines[i - 1] === '') {
while (++i < l && lines[i] === '') {}
errors.add('Multiple line break', i - 1, 0);
// Iterate over all tokens (including comments)
file.getTokens().forEach(function(token, index, tokens) {
// If there are no trailing tokens, exit early
var nextToken = tokens[index + 1];
if (!nextToken) {
return;
}
}

errors.assert.linesBetween({
token: token,
nextToken: nextToken,
atMost: 2,
});
});
}

};
4 changes: 2 additions & 2 deletions test/specs/rules/disallow-multiple-line-breaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('rules/disallow-multiple-line-breaks', function() {

it('should report error in the correct location when first line starts with #!', function() {
var error = checker.checkString('#!/usr/bin/env node\n\n\nx = 1;').getErrorList()[0];
assert.equal(error.line, 2);
assert.equal(error.column, 0);
assert.equal(error.line, 1);
assert.equal(error.column, 19);
});

it('should report only once per each sequence of line breaks', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/specs/string-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ describe('modules/string-checker', function() {
it('should report error in the correct location when first line starts with #!', function() {
checker.configure({ disallowMultipleLineBreaks: true });
var error = checker.checkString('#!/usr/bin/env node\n\n\nx = 1;').getErrorList()[0];
assert.equal(error.line, 2);
assert.equal(error.column, 0);
assert.equal(error.line, 1);
assert.equal(error.column, 19);
});
});

Expand Down

0 comments on commit 3aeb3dd

Please sign in to comment.