Skip to content

Commit

Permalink
Merge pull request #38 from editorconfig-checker/feature/27/disableFile
Browse files Browse the repository at this point in the history
feat(disable): whole file
  • Loading branch information
mstruebing authored Aug 20, 2018
2 parents 3bcd9b5 + 06ecb53 commit 58d6f76
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 5 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.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,28 @@ available options:

It is possible to disable single lines with placing a comment - or theoretically
any other string which includes `editorconfig-disable-line` on that line.
It is planned in future releases to also have the possibility to disable single
rules and also blocks of codes.

Example as it is working now:

```
const x = 'this constant is indented false' // editorconfig-disable-line
const x = 'this constant is indented false'; // editorconfig-disable-line
```

### Disabling files

It is possible to disable files with placing a comment - or theoretically
any other string which includes `editorconfig-disable-file` on the *first line*.

Example as it is working now:

```
// editorconfig-disable-file
const x = 'this constant is indented false';
...
const y = 'everything is indented false';
```


## Default ignores:

```
Expand Down
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 58d6f76

Please sign in to comment.