Skip to content

Commit

Permalink
feat(disable): whole file
Browse files Browse the repository at this point in the history
  • Loading branch information
mstruebing committed Aug 20, 2018
1 parent 3bcd9b5 commit 080fdc9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Build/TestFiles/DisablingRules/disable-file.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- editorconfig-disable-file -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title></title>
</head>
<body>
stuff
</body>
</html>
4 changes: 4 additions & 0 deletions Build/TestFiles/DisablingRules/disable-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// editorconfig-disable-file
const someFunc = () => {
return 'WRONG INDENDATION';
};
File renamed without changes.
File renamed without changes.
27 changes: 25 additions & 2 deletions src/validation/validation-process.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test(`should return an integer greater 0 for an invalid file`, () => {
});

test(`should return 0 if the false line is disabled`, () => {
const filePath = `${process.cwd()}/Build/TestFiles/DisablingRules/disable.js`;
const filePath = `${process.cwd()}/Build/TestFiles/DisablingRules/disable-line.js`;

const editorconfig = {
end_of_line: 'lf', // eslint-disable-line camelcase
Expand All @@ -69,7 +69,30 @@ test(`should return 0 if the false line is disabled`, () => {
});

test(`should return 0 if the false line is disabled and inside a HTML comment`, () => {
const filePath = `${process.cwd()}/Build/TestFiles/DisablingRules/disable.html`;
const filePath = `${process.cwd()}/Build/TestFiles/DisablingRules/disable-line.html`;

const editorconfig = {
end_of_line: 'lf', // eslint-disable-line camelcase
indent_style: 'space', // eslint-disable-line camelcase
indent_size: 4 // eslint-disable-line camelcase
};

expect(validateFile(filePath, editorconfig).length).toEqual(0);
});

test(`should return 0 if the file is disabled`, () => {
const filePath = `${process.cwd()}/Build/TestFiles/DisablingRules/disable-file.js`;

const editorconfig = {
end_of_line: 'lf', // eslint-disable-line camelcase
indent_style: 'tab' // eslint-disable-line camelcase
};

expect(validateFile(filePath, editorconfig).length).toEqual(0);
});

test(`should return 0 if the file is disabled`, () => {
const filePath = `${process.cwd()}/Build/TestFiles/DisablingRules/disable-file.html`;

const editorconfig = {
end_of_line: 'lf', // eslint-disable-line camelcase
Expand Down
8 changes: 8 additions & 0 deletions src/validation/validation-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ const validateFile = (filePath, editorconfig) => {
return /editorconfig-disable-line/.test(line);
};

const isFileDisabled = fileContentArray => {
return /editorconfig-disable-file/.test(fileContentArray[0]);
};

if (editorconfig.end_of_line) {
fileContentArray = fileContent.split(getEndOfLineChar(editorconfig.end_of_line));
} else {
fileContentArray = fileContent.split('\n');
}

if (isFileDisabled(fileContentArray)) {
return [];
}

fileContentArray.forEach((line, lineNumber) => {
lineNumber++;
if (!isLineDisabled(line)) {
Expand Down

0 comments on commit 080fdc9

Please sign in to comment.