Skip to content

Commit

Permalink
Merge pull request #33 from ndxbn/develop
Browse files Browse the repository at this point in the history
space-validator and tab-validator reports error at valid empty indented line
  • Loading branch information
mstruebing authored Jun 11, 2018
2 parents 3824852 + 38bd79c commit ee73069
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/validation/space/space-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const validate = (line, lineNumber, editorconfig) => {
}
}

if (!line.match(/^ *[^\s]+/)) {
if (!line.match(/^ *[\S\r\n]+/)) {
return `${lineNumber}: Mixed indentation (only spaces expected)`;
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/validation/space/space-validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,39 @@ test('should return true if line is empty', () => {
expect(validate(line, lineNumber, editorconfig)).toEqual('');
});

test('should return true if line is empty but keep indent with lf', () => {
const line = ' \n';
const lineNumber = 1;
const editorconfig = {
indent_style: 'space', // eslint-disable-line camelcase
indent_size: 4 // eslint-disable-line camelcase
};

expect(validate(line, lineNumber, editorconfig)).toEqual('');
});

test('should return true if line is empty but keep indent with cr', () => {
const line = ' \r';
const lineNumber = 1;
const editorconfig = {
indent_style: 'space', // eslint-disable-line camelcase
indent_size: 4 // eslint-disable-line camelcase
};

expect(validate(line, lineNumber, editorconfig)).toEqual('');
});

test('should return true if line is empty but keep indent with crlf', () => {
const line = ' \r\n';
const lineNumber = 1;
const editorconfig = {
indent_style: 'space', // eslint-disable-line camelcase
indent_size: 4 // eslint-disable-line camelcase
};

expect(validate(line, lineNumber, editorconfig)).toEqual('');
});

test('should return true if text starts directly no matter of indent_style', () => {
const line = 'Hello';
const lineNumber = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/validation/tab/tab-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const validate = (line, lineNumber, editorconfig) => {
if (line.length > 0 && editorconfig.indent_style === 'tab') {
// Starts with tab character * (none, one or more)
// and everything but whitespace or space and * (block comment)
if (!line.match(/^\t*([^\s]+| \*)/)) {
if (!line.match(/^\t*([\S\r\n]+| \*)/)) {
return `${lineNumber}: Mixed indentation (only tabs expected)`;
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/validation/tab/tab-validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ test('should return true if line is empty', () => {
expect(validate(line, lineNumber, editorconfig)).toEqual('');
});

test('should return true if line is empty but keep indent with lf', () => {
const line = '\t\n';
const lineNumber = 1;
const editorconfig = {
indent_style: 'tab' // eslint-disable-line camelcase
};

expect(validate(line, lineNumber, editorconfig)).toEqual('');
});

test('should return true if line is empty but keep indent with cr', () => {
const line = '\t\r';
const lineNumber = 1;
const editorconfig = {
indent_style: 'tab' // eslint-disable-line camelcase
};

expect(validate(line, lineNumber, editorconfig)).toEqual('');
});

test('should return true if line is empty but keep indent with crlf', () => {
const line = '\t\r\n';
const lineNumber = 1;
const editorconfig = {
indent_style: 'tab' // eslint-disable-line camelcase
};

expect(validate(line, lineNumber, editorconfig)).toEqual('');
});
test('should return false if mixed indentation', () => {
const line = ' Hello';
const lineNumber = 1;
Expand Down

0 comments on commit ee73069

Please sign in to comment.