Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent errored properties in stylelint.lint() return value #6983

Merged
merged 1 commit into from Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hot-planets-rest.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: inconsistent `errored` properties in `stylelint.lint()` return value
85 changes: 50 additions & 35 deletions lib/__tests__/descriptionlessDisables.test.mjs
Expand Up @@ -27,19 +27,14 @@ it('descriptionlessDisables', async () => {
/* stylelint-disable-next-line block-no-empty */
a {}`;

const linted = await standalone({
const { results } = await standalone({
config,
code: css,
reportDescriptionlessDisables: true,
});
const results = linted.results;

expect(results).toHaveLength(1);
const warnings = results[0].warnings.filter(
(warning) => warning.rule === '--report-descriptionless-disables',
);

expect(warnings).toEqual([
expect(descriptionlessWarnings(results[0])).toEqual([
{
line: 12,
column: 1,
Expand Down Expand Up @@ -97,18 +92,13 @@ it('descriptionlessDisables from config', async () => {
/* stylelint-disable-next-line block-no-empty */
a {}`;

const linted = await standalone({
const { results } = await standalone({
config,
code: css,
});
const results = linted.results;

expect(results).toHaveLength(1);
const warnings = results[0].warnings.filter(
(warning) => warning.rule === '--report-descriptionless-disables',
);

expect(warnings).toEqual([
expect(descriptionlessWarnings(results[0])).toEqual([
{
line: 12,
column: 1,
Expand Down Expand Up @@ -165,19 +155,14 @@ it('descriptionlessDisables true except', async () => {
/* stylelint-disable-next-line block-no-empty */
a {}`;

const linted = await standalone({
const { results } = await standalone({
config,
code: css,
reportDescriptionlessDisables: [true, { except: ['invalid-hex-case'] }],
});
const results = linted.results;

expect(results).toHaveLength(1);
const warnings = results[0].warnings.filter(
(warning) => warning.rule === '--report-descriptionless-disables',
);

expect(warnings).toEqual([
expect(descriptionlessWarnings(results[0])).toEqual([
{
line: 12,
column: 1,
Expand Down Expand Up @@ -225,19 +210,14 @@ it('descriptionlessDisables false except', async () => {
/* stylelint-disable-next-line block-no-empty */
a {}`;

const linted = await standalone({
const { results } = await standalone({
config,
code: css,
reportDescriptionlessDisables: [false, { except: ['invalid-hex-case'] }],
});
const results = linted.results;

expect(results).toHaveLength(1);
const warnings = results[0].warnings.filter(
(warning) => warning.rule === '--report-descriptionless-disables',
);

expect(warnings).toEqual([
expect(descriptionlessWarnings(results[0])).toEqual([
{
line: 16,
column: 7,
Expand Down Expand Up @@ -276,19 +256,14 @@ it('descriptionlessDisables severity', async () => {
/* stylelint-disable-next-line block-no-empty */
a {}`;

const linted = await standalone({
const { results } = await standalone({
config,
code: css,
reportDescriptionlessDisables: [true, { severity: 'warning' }],
});
const results = linted.results;

expect(results).toHaveLength(1);
const warnings = results[0].warnings.filter(
(warning) => warning.rule === '--report-descriptionless-disables',
);

expect(warnings).toEqual([
expect(descriptionlessWarnings(results[0])).toEqual([
{
line: 12,
column: 1,
Expand Down Expand Up @@ -318,3 +293,43 @@ it('descriptionlessDisables severity', async () => {
},
]);
});

it('descriptionlessDisables only', async () => {
const config = {
rules: {},
};
const css = '/* stylelint-disable */';

const { results } = await standalone({
config,
code: css,
reportDescriptionlessDisables: true,
});

expect(results).toHaveLength(1);
expect(results[0].errored).toBe(true);
expect(results[0].warnings).toHaveLength(1);
expect(descriptionlessWarnings(results[0])).toHaveLength(1);
});

it('descriptionlessDisables only with warning severity', async () => {
const config = {
rules: {},
};
const css = '/* stylelint-disable */';

const { results } = await standalone({
config,
code: css,
reportDescriptionlessDisables: [true, { severity: 'warning' }],
});

expect(results).toHaveLength(1);
expect(results[0].errored).toBe(false);
expect(results[0].warnings).toHaveLength(1);
expect(descriptionlessWarnings(results[0])).toHaveLength(1);
});

function descriptionlessWarnings(result) {
return result.warnings.filter(({ rule }) => rule === '--report-descriptionless-disables');
}
2 changes: 2 additions & 0 deletions lib/__tests__/needlessDisables.test.mjs
Expand Up @@ -58,6 +58,7 @@ it('needlessDisables simple case', async () => {
severity: 'error',
},
]);
expect(results[0].errored).toBe(true);
});

it('needlessDisables with config', async () => {
Expand Down Expand Up @@ -404,6 +405,7 @@ it('needlessDisables severity', async () => {
severity: 'warning',
},
]);
expect(results[0].errored).toBe(false);
});

it('needlessDisables with configurationComment', async () => {
Expand Down
1 change: 1 addition & 0 deletions lib/__tests__/reportDisables.test.mjs
Expand Up @@ -39,6 +39,7 @@ describe('reportDisables', () => {
severity: 'error',
},
]);
expect(results[0].errored).toBe(true);
});

it('reports an ignored disabled comment', async () => {
Expand Down
14 changes: 10 additions & 4 deletions lib/prepareReturnValue.js
Expand Up @@ -24,12 +24,18 @@ module.exports = function prepareReturnValue(stylelintResults, maxWarnings, form
invalidScopeDisables(stylelintResults);
descriptionlessDisables(stylelintResults);

const errored = stylelintResults.some(
(result) =>
let errored = false;

for (const result of stylelintResults) {
if (
result.errored ||
result.parseErrors.length > 0 ||
result.warnings.some((warning) => warning.severity === 'error'),
);
result.warnings.some((warning) => warning.severity === 'error')
) {
errored = true;
result.errored = true;
}
}

/** @type {LinterResult} */
const returnValue = {
Expand Down
4 changes: 2 additions & 2 deletions system-tests/004/__snapshots__/fs.test.mjs.snap
Expand Up @@ -7,7 +7,7 @@ exports[`fs - errored state for reportNeedlessDisables 1`] = `
"output": [
{
"deprecations": [],
"errored": false,
"errored": true,
"invalidOptionWarnings": [],
"parseErrors": [],
"warnings": [
Expand All @@ -27,7 +27,7 @@ exports[`fs - errored state for reportNeedlessDisables 1`] = `
"results": [
{
"deprecations": [],
"errored": false,
"errored": true,
"ignored": undefined,
"invalidOptionWarnings": [],
"parseErrors": [],
Expand Down
4 changes: 2 additions & 2 deletions system-tests/004/__snapshots__/no-fs.test.mjs.snap
Expand Up @@ -7,7 +7,7 @@ exports[`no-fs - errored state for reportNeedlessDisables 1`] = `
"output": [
{
"deprecations": [],
"errored": false,
"errored": true,
"invalidOptionWarnings": [],
"parseErrors": [],
"warnings": [
Expand All @@ -27,7 +27,7 @@ exports[`no-fs - errored state for reportNeedlessDisables 1`] = `
"results": [
{
"deprecations": [],
"errored": false,
"errored": true,
"ignored": undefined,
"invalidOptionWarnings": [],
"parseErrors": [],
Expand Down