From 2a280ff38d32cc0f8a33c2cffe757ade4d6c5dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Wed, 21 Feb 2018 05:40:40 +0100 Subject: [PATCH 1/4] feat(disableLine): disabling a line with a comment // editorconfig-disable-line closes #22 --- Build/Scripts/lint.sh | 2 +- Build/TestFiles/DisablingRules/disable.js | 3 +++ src/validation/validation-process.test.js | 11 +++++++++++ src/validation/validation-processor.js | 8 +++++--- yarn.lock | 6 +++--- 5 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 Build/TestFiles/DisablingRules/disable.js diff --git a/Build/Scripts/lint.sh b/Build/Scripts/lint.sh index 7ba2a61..496637e 100755 --- a/Build/Scripts/lint.sh +++ b/Build/Scripts/lint.sh @@ -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 diff --git a/Build/TestFiles/DisablingRules/disable.js b/Build/TestFiles/DisablingRules/disable.js new file mode 100644 index 0000000..e6eeab4 --- /dev/null +++ b/Build/TestFiles/DisablingRules/disable.js @@ -0,0 +1,3 @@ +const someFunc = () => { + return 'WRONG INDENDATION'; // editorconfig-disable-line +}; diff --git a/src/validation/validation-process.test.js b/src/validation/validation-process.test.js index aaa33c5..698cd6c 100644 --- a/src/validation/validation-process.test.js +++ b/src/validation/validation-process.test.js @@ -56,3 +56,14 @@ 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); +}); diff --git a/src/validation/validation-processor.js b/src/validation/validation-processor.js index d6c4656..943df9d 100644 --- a/src/validation/validation-processor.js +++ b/src/validation/validation-processor.js @@ -21,9 +21,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 (!line.endsWith('editorconfig-disable-line')) { + errors.push(validateTab(line, lineNumber, editorconfig)); + errors.push(validateSpaces(line, lineNumber, editorconfig)); + errors.push(validateTrailingWhitespace(line, lineNumber, editorconfig)); + } }); errors.push(validateEndOfLine(fileContent, editorconfig)); diff --git a/yarn.lock b/yarn.lock index bddf94c..107d47b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" From c7a331f8a174534359dd13b428be80a4c9dde604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Thu, 22 Feb 2018 19:26:52 +0100 Subject: [PATCH 2/4] feat(disableLine): just look for editorconfig-disable-line --- Build/TestFiles/DisablingRules/disable.html | 11 +++++++++++ src/validation/validation-process.test.js | 12 ++++++++++++ src/validation/validation-processor.js | 6 +++++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 Build/TestFiles/DisablingRules/disable.html diff --git a/Build/TestFiles/DisablingRules/disable.html b/Build/TestFiles/DisablingRules/disable.html new file mode 100644 index 0000000..f7b6bf1 --- /dev/null +++ b/Build/TestFiles/DisablingRules/disable.html @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/validation/validation-process.test.js b/src/validation/validation-process.test.js index 698cd6c..bb7feae 100644 --- a/src/validation/validation-process.test.js +++ b/src/validation/validation-process.test.js @@ -67,3 +67,15 @@ test(`should return 0 if the false line is disabled`, () => { 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); +}); diff --git a/src/validation/validation-processor.js b/src/validation/validation-processor.js index 943df9d..411301c 100644 --- a/src/validation/validation-processor.js +++ b/src/validation/validation-processor.js @@ -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 { @@ -21,7 +25,7 @@ const validateFile = (filePath, editorconfig) => { fileContentArray.forEach((line, lineNumber) => { lineNumber++; - if (!line.endsWith('editorconfig-disable-line')) { + if (!isLineDisabled(line)) { errors.push(validateTab(line, lineNumber, editorconfig)); errors.push(validateSpaces(line, lineNumber, editorconfig)); errors.push(validateTrailingWhitespace(line, lineNumber, editorconfig)); From f189ef65825334f6c0987dd8c2c25a1b7c140790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Thu, 22 Feb 2018 19:33:59 +0100 Subject: [PATCH 3/4] docs: document disabling of lines --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index ad589c7..ed29a99 100644 --- a/README.md +++ b/README.md @@ -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: From 3a3edd349f0a3f913e248615b59d9e0a7a95162e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Thu, 22 Feb 2018 19:34:16 +0100 Subject: [PATCH 4/4] chore: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 07ce649..07667c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "editorconfig-checker", - "version": "1.1.5", + "version": "1.2.0", "description": "", "main": "src/index.js", "bin": {