Skip to content

Commit

Permalink
Merge pull request #24 from editorconfig-checker/feature/22/disableRu…
Browse files Browse the repository at this point in the history
…lesInline

WIP feat(disableLine): disabling a line with a comment
  • Loading branch information
mstruebing authored Feb 22, 2018
2 parents 4d2a7bb + 3a3edd3 commit c6a353e
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Build/Scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

xo --ignore=Build/TestFiles/ValidationProcessor/*.js && yarn lint:self
xo --ignore=Build/TestFiles/{ValidationProcessor,DisablingRules}/*.js && yarn lint:self
11 changes: 11 additions & 0 deletions Build/TestFiles/DisablingRules/disable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title></title>
</head>
<body>
<!-- comment editorconfig-disable-line -->
</body>
</html>
3 changes: 3 additions & 0 deletions Build/TestFiles/DisablingRules/disable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const someFunc = () => {
return 'WRONG INDENDATION'; // editorconfig-disable-line
};
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ available options:
will print all files which are checked to stdout
```

### Disabling single lines

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
```

## Default ignores:

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "editorconfig-checker",
"version": "1.1.5",
"version": "1.2.0",
"description": "",
"main": "src/index.js",
"bin": {
Expand Down
23 changes: 23 additions & 0 deletions src/validation/validation-process.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,26 @@ test(`should return an integer greater 0 for an invalid file`, () => {

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

test(`should return 0 if the false line is disabled`, () => {
const filePath = `${process.cwd()}/Build/TestFiles/DisablingRules/disable.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 false line is disabled and inside a HTML comment`, () => {
const filePath = `${process.cwd()}/Build/TestFiles/DisablingRules/disable.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);
});
12 changes: 9 additions & 3 deletions src/validation/validation-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const validateFile = (filePath, editorconfig) => {
const fileContent = fs.readFileSync(filePath).toString();
let fileContentArray = [];

const isLineDisabled = line => {
return /editorconfig-disable-line/.test(line);
};

if (editorconfig.end_of_line) {
fileContentArray = fileContent.split(getEndOfLineChar(editorconfig.end_of_line));
} else {
Expand All @@ -21,9 +25,11 @@ const validateFile = (filePath, editorconfig) => {

fileContentArray.forEach((line, lineNumber) => {
lineNumber++;
errors.push(validateTab(line, lineNumber, editorconfig));
errors.push(validateSpaces(line, lineNumber, editorconfig));
errors.push(validateTrailingWhitespace(line, lineNumber, editorconfig));
if (!isLineDisabled(line)) {
errors.push(validateTab(line, lineNumber, editorconfig));
errors.push(validateSpaces(line, lineNumber, editorconfig));
errors.push(validateTrailingWhitespace(line, lineNumber, editorconfig));
}
});

errors.push(validateEndOfLine(fileContent, editorconfig));
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5395,9 +5395,9 @@ xo-init@^0.7.0:
the-argv "^1.0.0"
write-pkg "^3.1.0"

xo@^0.20.2:
version "0.20.2"
resolved "https://registry.yarnpkg.com/xo/-/xo-0.20.2.tgz#fcc6acdac5a14a6a788d448046a7a2fb01f57f4d"
xo@^0.20.0:
version "0.20.3"
resolved "https://registry.yarnpkg.com/xo/-/xo-0.20.3.tgz#6fb1597b5e361fd561535bbf84cf97eefaac5d80"
dependencies:
arrify "^1.0.1"
debug "^3.1.0"
Expand Down

0 comments on commit c6a353e

Please sign in to comment.