Skip to content

Commit

Permalink
Merge pull request #5079 from nex3/exit-code
Browse files Browse the repository at this point in the history
Properly set the errored property for --report options
  • Loading branch information
nex3 committed Jan 12, 2021
2 parents 9b71734 + 8596b5d commit 7f788e8
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/prepareReturnValue.js
Expand Up @@ -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} */
Expand Down
2 changes: 1 addition & 1 deletion 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 [
Expand Down
2 changes: 1 addition & 1 deletion system-tests/003/fs.test.js
Expand Up @@ -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({
Expand Down
69 changes: 69 additions & 0 deletions system-tests/004/__snapshots__/fs.test.js.snap
@@ -0,0 +1,69 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`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[`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 [],
},
],
}
`;
69 changes: 69 additions & 0 deletions 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 [],
},
],
}
`;
5 changes: 5 additions & 0 deletions system-tests/004/config.json
@@ -0,0 +1,5 @@
{
"rules": {
"block-no-empty": true
}
}
29 changes: 29 additions & 0 deletions 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('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('fs - no errored state', async () => {
expect(
prepForSnapshot(
await stylelint.lint({
files: await caseFilesForFix(CASE_NUMBER),
configFile: caseConfigFile(CASE_NUMBER),
}),
),
).toMatchSnapshot();
}, 10000);
29 changes: 29 additions & 0 deletions 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);
4 changes: 4 additions & 0 deletions system-tests/004/stylesheet.css
@@ -0,0 +1,4 @@
/* stylelint-disable block-no-empty */
a {
color: red;
}

0 comments on commit 7f788e8

Please sign in to comment.