From eac16e3ab609e99adf45b193c105a872b245041c Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 15 Dec 2020 13:45:45 -0800 Subject: [PATCH 1/4] Properly set the errored property for --report options This sets the `errored` property (and thus the exit code) as long as any warning has severity "error", which includes warnings generated by --report options. --- lib/prepareReturnValue.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/prepareReturnValue.js b/lib/prepareReturnValue.js index a533f5dd7f..891fde871e 100644 --- a/lib/prepareReturnValue.js +++ b/lib/prepareReturnValue.js @@ -34,7 +34,10 @@ function prepareReturnValue(stylelintResults, options, formatter) { if (reportDescriptionlessDisables) descriptionlessDisables(stylelintResults); const errored = stylelintResults.some( - (result) => result.errored || result.parseErrors.length > 0, + (result) => + result.errored || + result.parseErrors.length > 0 || + result.warnings.some((warning) => warning.severity === 'error'), ); /** @type {StylelintStandaloneReturnValue} */ From 29106f2d1fa2429ca4f5adbef747a1000397aa45 Mon Sep 17 00:00:00 2001 From: Ivan Kopeykin Date: Fri, 8 Jan 2021 14:46:15 +0300 Subject: [PATCH 2/4] test: add test case for checking error state --- .../004/__snapshots__/fs.test.js.snap | 69 +++++++++++++++++++ .../004/__snapshots__/no-fs.test.js.snap | 69 +++++++++++++++++++ system-tests/004/config.json | 5 ++ system-tests/004/fs.test.js | 29 ++++++++ system-tests/004/no-fs.test.js | 29 ++++++++ system-tests/004/stylesheet.css | 4 ++ 6 files changed, 205 insertions(+) create mode 100644 system-tests/004/__snapshots__/fs.test.js.snap create mode 100644 system-tests/004/__snapshots__/no-fs.test.js.snap create mode 100755 system-tests/004/config.json create mode 100644 system-tests/004/fs.test.js create mode 100644 system-tests/004/no-fs.test.js create mode 100644 system-tests/004/stylesheet.css diff --git a/system-tests/004/__snapshots__/fs.test.js.snap b/system-tests/004/__snapshots__/fs.test.js.snap new file mode 100644 index 0000000000..5cd171095b --- /dev/null +++ b/system-tests/004/__snapshots__/fs.test.js.snap @@ -0,0 +1,69 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`no-fs - errored state for reportNeedlessDisables 1`] = ` +Object { + "errored": true, + "output": Array [ + Object { + "deprecations": Array [], + "errored": false, + "invalidOptionWarnings": Array [], + "parseErrors": Array [], + "warnings": Array [ + Object { + "column": 1, + "line": 1, + "rule": "--report-needless-disables", + "severity": "error", + "text": "Needless disable for \\"block-no-empty\\"", + }, + ], + }, + ], + "reportedDisables": Array [], + "results": Array [ + Object { + "deprecations": Array [], + "errored": false, + "ignored": undefined, + "invalidOptionWarnings": Array [], + "parseErrors": Array [], + "warnings": Array [ + Object { + "column": 1, + "line": 1, + "rule": "--report-needless-disables", + "severity": "error", + "text": "Needless disable for \\"block-no-empty\\"", + }, + ], + }, + ], +} +`; + +exports[`no-fs - no errored state 1`] = ` +Object { + "errored": false, + "output": Array [ + Object { + "deprecations": Array [], + "errored": false, + "invalidOptionWarnings": Array [], + "parseErrors": Array [], + "warnings": Array [], + }, + ], + "reportedDisables": Array [], + "results": Array [ + Object { + "deprecations": Array [], + "errored": false, + "ignored": undefined, + "invalidOptionWarnings": Array [], + "parseErrors": Array [], + "warnings": Array [], + }, + ], +} +`; diff --git a/system-tests/004/__snapshots__/no-fs.test.js.snap b/system-tests/004/__snapshots__/no-fs.test.js.snap new file mode 100644 index 0000000000..5cd171095b --- /dev/null +++ b/system-tests/004/__snapshots__/no-fs.test.js.snap @@ -0,0 +1,69 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`no-fs - errored state for reportNeedlessDisables 1`] = ` +Object { + "errored": true, + "output": Array [ + Object { + "deprecations": Array [], + "errored": false, + "invalidOptionWarnings": Array [], + "parseErrors": Array [], + "warnings": Array [ + Object { + "column": 1, + "line": 1, + "rule": "--report-needless-disables", + "severity": "error", + "text": "Needless disable for \\"block-no-empty\\"", + }, + ], + }, + ], + "reportedDisables": Array [], + "results": Array [ + Object { + "deprecations": Array [], + "errored": false, + "ignored": undefined, + "invalidOptionWarnings": Array [], + "parseErrors": Array [], + "warnings": Array [ + Object { + "column": 1, + "line": 1, + "rule": "--report-needless-disables", + "severity": "error", + "text": "Needless disable for \\"block-no-empty\\"", + }, + ], + }, + ], +} +`; + +exports[`no-fs - no errored state 1`] = ` +Object { + "errored": false, + "output": Array [ + Object { + "deprecations": Array [], + "errored": false, + "invalidOptionWarnings": Array [], + "parseErrors": Array [], + "warnings": Array [], + }, + ], + "reportedDisables": Array [], + "results": Array [ + Object { + "deprecations": Array [], + "errored": false, + "ignored": undefined, + "invalidOptionWarnings": Array [], + "parseErrors": Array [], + "warnings": Array [], + }, + ], +} +`; diff --git a/system-tests/004/config.json b/system-tests/004/config.json new file mode 100755 index 0000000000..cf5749638f --- /dev/null +++ b/system-tests/004/config.json @@ -0,0 +1,5 @@ +{ + "rules": { + "block-no-empty": true + } +} diff --git a/system-tests/004/fs.test.js b/system-tests/004/fs.test.js new file mode 100644 index 0000000000..3df77f9639 --- /dev/null +++ b/system-tests/004/fs.test.js @@ -0,0 +1,29 @@ +'use strict'; + +const stylelint = require('../../lib'); +const { caseConfigFile, caseFilesForFix, prepForSnapshot } = require('../systemTestUtils'); + +const CASE_NUMBER = '004'; + +it('no-fs - errored state for reportNeedlessDisables', async () => { + expect( + prepForSnapshot( + await stylelint.lint({ + files: await caseFilesForFix(CASE_NUMBER), + configFile: caseConfigFile(CASE_NUMBER), + reportNeedlessDisables: true, + }), + ), + ).toMatchSnapshot(); +}, 10000); + +it('no-fs - no errored state', async () => { + expect( + prepForSnapshot( + await stylelint.lint({ + files: await caseFilesForFix(CASE_NUMBER), + configFile: caseConfigFile(CASE_NUMBER), + }), + ), + ).toMatchSnapshot(); +}, 10000); diff --git a/system-tests/004/no-fs.test.js b/system-tests/004/no-fs.test.js new file mode 100644 index 0000000000..80c8a41dab --- /dev/null +++ b/system-tests/004/no-fs.test.js @@ -0,0 +1,29 @@ +'use strict'; + +const stylelint = require('../../lib'); +const { caseConfig, caseCode, prepForSnapshot } = require('../systemTestUtils'); + +const CASE_NUMBER = '004'; + +it('no-fs - errored state for reportNeedlessDisables', async () => { + expect( + prepForSnapshot( + await stylelint.lint({ + code: await caseCode(CASE_NUMBER), + config: await caseConfig(CASE_NUMBER), + reportNeedlessDisables: true, + }), + ), + ).toMatchSnapshot(); +}, 10000); + +it('no-fs - no errored state', async () => { + expect( + prepForSnapshot( + await stylelint.lint({ + code: await caseCode(CASE_NUMBER), + config: await caseConfig(CASE_NUMBER), + }), + ), + ).toMatchSnapshot(); +}, 10000); diff --git a/system-tests/004/stylesheet.css b/system-tests/004/stylesheet.css new file mode 100644 index 0000000000..972971facc --- /dev/null +++ b/system-tests/004/stylesheet.css @@ -0,0 +1,4 @@ +/* stylelint-disable block-no-empty */ +a { + color: red; +} From b9e8979dc6039e7af601cbe7eaca0f882e4500f5 Mon Sep 17 00:00:00 2001 From: Ivan Kopeykin Date: Sat, 9 Jan 2021 11:51:23 +0300 Subject: [PATCH 3/4] fix: typo --- system-tests/003/fs.test.js | 2 +- system-tests/004/fs.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/system-tests/003/fs.test.js b/system-tests/003/fs.test.js index 726ff70171..a03baea736 100644 --- a/system-tests/003/fs.test.js +++ b/system-tests/003/fs.test.js @@ -5,7 +5,7 @@ const { caseConfigFile, caseFilesForFix, prepForSnapshot } = require('../systemT const CASE_NUMBER = '003'; -it('no-fs - zen garden CSS with standard config', async () => { +it('fs - zen garden CSS with standard config', async () => { expect( prepForSnapshot( await stylelint.lint({ diff --git a/system-tests/004/fs.test.js b/system-tests/004/fs.test.js index 3df77f9639..0d850c71b4 100644 --- a/system-tests/004/fs.test.js +++ b/system-tests/004/fs.test.js @@ -5,7 +5,7 @@ const { caseConfigFile, caseFilesForFix, prepForSnapshot } = require('../systemT const CASE_NUMBER = '004'; -it('no-fs - errored state for reportNeedlessDisables', async () => { +it('fs - errored state for reportNeedlessDisables', async () => { expect( prepForSnapshot( await stylelint.lint({ @@ -17,7 +17,7 @@ it('no-fs - errored state for reportNeedlessDisables', async () => { ).toMatchSnapshot(); }, 10000); -it('no-fs - no errored state', async () => { +it('fs - no errored state', async () => { expect( prepForSnapshot( await stylelint.lint({ From 8596b5dfdb99cee790fd90afb371faa136590c38 Mon Sep 17 00:00:00 2001 From: Ivan Kopeykin Date: Sat, 9 Jan 2021 13:11:50 +0300 Subject: [PATCH 4/4] test: update snapshots --- system-tests/003/__snapshots__/fs.test.js.snap | 2 +- system-tests/004/__snapshots__/fs.test.js.snap | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/system-tests/003/__snapshots__/fs.test.js.snap b/system-tests/003/__snapshots__/fs.test.js.snap index 6e827c1243..ebf70f2485 100644 --- a/system-tests/003/__snapshots__/fs.test.js.snap +++ b/system-tests/003/__snapshots__/fs.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`no-fs - zen garden CSS with standard config 1`] = ` +exports[`fs - zen garden CSS with standard config 1`] = ` Object { "errored": true, "output": Array [ diff --git a/system-tests/004/__snapshots__/fs.test.js.snap b/system-tests/004/__snapshots__/fs.test.js.snap index 5cd171095b..aca4f03c3d 100644 --- a/system-tests/004/__snapshots__/fs.test.js.snap +++ b/system-tests/004/__snapshots__/fs.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`no-fs - errored state for reportNeedlessDisables 1`] = ` +exports[`fs - errored state for reportNeedlessDisables 1`] = ` Object { "errored": true, "output": Array [ @@ -42,7 +42,7 @@ Object { } `; -exports[`no-fs - no errored state 1`] = ` +exports[`fs - no errored state 1`] = ` Object { "errored": false, "output": Array [