From 6c52f65b0a130599cc12d499673687f902d171b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy=20Laurans?= Date: Tue, 8 Oct 2024 18:19:06 +0200 Subject: [PATCH 1/3] Fix - Don't check trailing spaces if settings is set to false or unset --- src/Validator.js | 2 +- src/Validator.test.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Validator.js b/src/Validator.js index 5988561..4942e1e 100644 --- a/src/Validator.js +++ b/src/Validator.js @@ -479,7 +479,7 @@ class Validator { * @private */ _validateTrailingspaces(line, index) { - if (this._settings.trailingspaces && typeof line === 'string') { + if (this._settings.trailingspaces === true && typeof line === 'string') { const matchSpaces = line.match(/\s*$/); // Is there a trailing whitespace? diff --git a/src/Validator.test.js b/src/Validator.test.js index 3d22314..6654e37 100644 --- a/src/Validator.test.js +++ b/src/Validator.test.js @@ -939,6 +939,14 @@ describe('The validator', () => { }); }); + it('should pass when unset', () => { + const file = __fromFixtures('trailingspaces.invalid.fixture'); + const validator = new Validator({trailingspaces: 'unset'}); + validator.validate(file); + + const report = validator.getInvalidFiles() + expect(report).toEqual({}); + }); }); // Newline (at the end of file) From a03cab3113576c764fcb67587a81640f48e648ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy=20Laurans?= Date: Tue, 8 Oct 2024 18:19:44 +0200 Subject: [PATCH 2/3] Fix - Don't check new line if settings is set to false or unset --- src/Validator.js | 2 +- src/Validator.test.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Validator.js b/src/Validator.js index 4942e1e..074b98d 100644 --- a/src/Validator.js +++ b/src/Validator.js @@ -457,7 +457,7 @@ class Validator { * @private */ _validateNewlinesEOF() { - if (!this._settings.newline) { + if (this._settings.newline !== true) { return; } diff --git a/src/Validator.test.js b/src/Validator.test.js index 6654e37..56f1536 100644 --- a/src/Validator.test.js +++ b/src/Validator.test.js @@ -1001,6 +1001,14 @@ describe('The validator', () => { }); }); + it('should pass when unset', () => { + const file = __fromFixtures('newlines.endoffile.invalid.less.fixture'); + const validator = new Validator({newline: 'unset'}); + validator.validate(file); + + const report = validator.getInvalidFiles() + expect(report).toEqual({}); + }); }); // Newlines maximum From c0fcc193a104520f882cee3a3dd3ee76bc6afda9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy=20Laurans?= Date: Tue, 8 Oct 2024 18:20:11 +0200 Subject: [PATCH 3/3] Fix - Don't check EOL if settings is set to false or unset --- src/Validator.js | 2 +- src/Validator.test.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Validator.js b/src/Validator.js index 074b98d..b06821d 100644 --- a/src/Validator.js +++ b/src/Validator.js @@ -646,7 +646,7 @@ class Validator { * @private */ _validateEndOfLine() { - if (typeof this._settings.endOfLine === 'string') { + if (typeof this._settings.endOfLine === 'string' && this._settings.endOfLine !== 'unset') { const isEOL = (ch) => ch === '\r' || ch === '\n'; let desiredEOL = '\n'; diff --git a/src/Validator.test.js b/src/Validator.test.js index 56f1536..569f16d 100644 --- a/src/Validator.test.js +++ b/src/Validator.test.js @@ -416,6 +416,13 @@ describe('The validator', () => { }); }); + it('should pass when unset', () => { + const file = __fromFixtures('endofline.mixed.fixture'); + const validator = new Validator({endOfLine: 'unset'}); + validator.validate(file); + + expect(validator.getInvalidFiles()).toEqual({}); + }); }); describe('line feed', () => {