Skip to content

Commit

Permalink
Merge pull request #612 from toddbc/newline-fix
Browse files Browse the repository at this point in the history
Correct indentation checks when using CRLFs
  • Loading branch information
DanPurdy committed Apr 19, 2016
2 parents bf39123 + b35ff4e commit 9656e0a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/rules/indentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = {
prevNode,
space,
spaceLength,
count;
count,
newlineLength;

level = level || 0;

Expand All @@ -35,16 +36,18 @@ module.exports = {
if (n.type === 'space') {
// Test for CRLF first, since it includes LF
space = n.content.lastIndexOf('\r\n');
newlineLength = 2;

if (space === -1) {
space = n.content.lastIndexOf('\n');
newlineLength = 1;
}

if (space >= 0) {
spaceLength = n.content.slice(space + 1).length;
spaceLength = n.content.slice(space + newlineLength).length;

try {
count = n.content.slice(space + 1).match(/ /g).length;
count = n.content.slice(space + newlineLength).match(/ /g).length;
}
catch (e) {
count = 0;
Expand Down

0 comments on commit 9656e0a

Please sign in to comment.