Skip to content

Commit

Permalink
Fix incorrect output by all formatters except for json (#6480)
Browse files Browse the repository at this point in the history
- Add missing output by `parseErrors`
- Fix output of warnings without rule and severity
- Fix error `Unknown severity: "undefined"` with `stringFormatter`
- Add missing output with `unixFormatter` summary line
  • Loading branch information
ybiquitous committed Nov 18, 2022
1 parent eb095fd commit 6683e1e
Show file tree
Hide file tree
Showing 14 changed files with 357 additions and 168 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-carpets-yawn.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: incorrect output by all formatters except for `json`
52 changes: 37 additions & 15 deletions lib/formatters/__tests__/compactFormatter.test.js
Expand Up @@ -21,10 +21,7 @@ describe('compactFormatter', () => {
const results = [
{
source: 'path/to/file.css',
errored: false,
warnings: [],
deprecations: [],
invalidOptionWarnings: [],
},
];

Expand All @@ -37,7 +34,6 @@ describe('compactFormatter', () => {
const results = [
{
source: 'path/to/file.css',
errored: true,
warnings: [
{
line: 1,
Expand All @@ -47,8 +43,6 @@ describe('compactFormatter', () => {
text: 'Unexpected foo',
},
],
deprecations: [],
invalidOptionWarnings: [],
},
];

Expand All @@ -63,7 +57,6 @@ describe('compactFormatter', () => {
const results = [
{
source: 'path/to/file.css',
errored: true,
warnings: [
{
line: 1,
Expand All @@ -73,8 +66,6 @@ describe('compactFormatter', () => {
text: 'Unexpected foo',
},
],
deprecations: [],
invalidOptionWarnings: [],
},
];

Expand All @@ -83,15 +74,14 @@ describe('compactFormatter', () => {
expect(output).toBe('path/to/file.css: line 1, col 1, error - Unexpected foo');
});

it('output warnings with more than 80 characters and `process.stdout.columns` equal 90 characters', () => {
it('outputs warnings with more than 80 characters and `process.stdout.columns` equal 90 characters', () => {
// For Windows tests
process.stdout.isTTY = true;
process.stdout.columns = 90;

const results = [
{
source: 'path/to/file.css',
errored: true,
warnings: [
{
line: 1,
Expand All @@ -101,8 +91,6 @@ describe('compactFormatter', () => {
text: 'Unexpected very very very very very very very very very very very very very long foo',
},
],
deprecations: [],
invalidOptionWarnings: [],
},
];

Expand All @@ -118,8 +106,6 @@ describe('compactFormatter', () => {
{
source: 'file.css',
warnings: [],
deprecations: [],
invalidOptionWarnings: [],
ignored: true,
},
];
Expand All @@ -128,4 +114,40 @@ describe('compactFormatter', () => {

expect(output).toBe('');
});

it('outputs parse errors and warnings without rule and severity', () => {
const results = [
{
source: 'path/to/file.css',
parseErrors: [
{
line: 1,
column: 1,
stylelintType: 'foo-error',
text: 'Cannot parse foo',
},
],
warnings: [
{
line: 3,
column: 2,
rule: 'bar',
severity: 'error',
text: 'Unexpected foo',
},
{
line: 2,
column: 1,
text: 'Anonymous error',
},
],
},
];

const output = prepareFormatterOutput(results, compactFormatter);

expect(output).toBe(`path/to/file.css: line 1, col 1, error - Cannot parse foo (foo-error)
path/to/file.css: line 2, col 1, error - Anonymous error
path/to/file.css: line 3, col 2, error - Unexpected foo`);
});
});
17 changes: 16 additions & 1 deletion lib/formatters/__tests__/githubFormatter.test.js
Expand Up @@ -28,6 +28,19 @@ test('githubFormatter', () => {
severity: 'warning',
text: 'Unexpected "bar" (bar)',
},
{
line: 20,
column: 3,
text: 'Anonymous error',
},
],
parseErrors: [
{
line: 20,
column: 1,
stylelintType: 'foo-error',
text: 'Cannot parse foo',
},
],
},
];
Expand All @@ -40,5 +53,7 @@ test('githubFormatter', () => {

expect(githubFormatter(results, returnValue))
.toBe(`::error file=path/to/file.css,line=1,col=2,endLine=1,endColumn=5,title=Stylelint problem::Unexpected "foo" (foo) - https://stylelint.io/rules/foo
::warning file=a.css,line=10,col=20,title=Stylelint problem::Unexpected "bar" (bar) [maybe fixable]`);
::warning file=a.css,line=10,col=20,title=Stylelint problem::Unexpected "bar" (bar) [maybe fixable]
::error file=a.css,line=20,col=1,title=Stylelint problem::Cannot parse foo (foo-error)
::error file=a.css,line=20,col=3,title=Stylelint problem::Anonymous error`);
});
64 changes: 41 additions & 23 deletions lib/formatters/__tests__/stringFormatter.test.js
Expand Up @@ -23,10 +23,7 @@ describe('stringFormatter', () => {
const results = [
{
source: 'path/to/file.css',
errored: false,
warnings: [],
deprecations: [],
invalidOptionWarnings: [],
},
];

Expand All @@ -39,7 +36,6 @@ describe('stringFormatter', () => {
const results = [
{
source: 'path/to/file.css',
errored: true,
warnings: [
{
line: 1,
Expand All @@ -49,8 +45,6 @@ describe('stringFormatter', () => {
text: 'Unexpected foo',
},
],
deprecations: [],
invalidOptionWarnings: [],
},
];

Expand All @@ -67,7 +61,6 @@ path/to/file.css
const results = [
{
source: 'path/to/file.css',
errored: true,
warnings: [
{
line: 1,
Expand All @@ -77,8 +70,6 @@ path/to/file.css
text: 'Unexpected foo (rule-name)',
},
],
deprecations: [],
invalidOptionWarnings: [],
},
];

Expand All @@ -97,7 +88,6 @@ path/to/file.css
const results = [
{
source: 'path/to/file.css',
errored: true,
warnings: [
{
line: 1,
Expand All @@ -107,8 +97,6 @@ path/to/file.css
text: 'Unexpected foo',
},
],
deprecations: [],
invalidOptionWarnings: [],
},
];

Expand All @@ -121,15 +109,14 @@ path/to/file.css
1 problem (1 error, 0 warnings)`);
});

it('output warnings with more than 80 characters and `process.stdout.columns` equal 90 characters', () => {
it('outputs warnings with more than 80 characters and `process.stdout.columns` equal 90 characters', () => {
// For Windows tests
process.stdout.isTTY = true;
process.stdout.columns = 90;

const results = [
{
source: 'path/to/file.css',
errored: true,
warnings: [
{
line: 1,
Expand All @@ -139,8 +126,6 @@ path/to/file.css
text: 'Unexpected very very very very very very very very very very very very very long foo',
},
],
deprecations: [],
invalidOptionWarnings: [],
},
];

Expand Down Expand Up @@ -169,7 +154,6 @@ path/to/file.css
text: 'Unexpected option for baz',
},
],
errored: true,
warnings: [],
},
{
Expand All @@ -185,7 +169,6 @@ path/to/file.css
text: 'Unexpected option for baz',
},
],
errored: true,
warnings: [],
},
];
Expand All @@ -203,8 +186,6 @@ Deprecation Warning: Deprecated foo See: bar`);
{
source: 'file.css',
warnings: [],
deprecations: [],
invalidOptionWarnings: [],
ignored: true,
},
];
Expand All @@ -218,7 +199,6 @@ Deprecation Warning: Deprecated foo See: bar`);
const results = [
{
source: 'path/to/file.css',
errored: true,
warnings: [
{
line: 1,
Expand All @@ -228,8 +208,6 @@ Deprecation Warning: Deprecated foo See: bar`);
text: '',
},
],
deprecations: [],
invalidOptionWarnings: [],
},
];

Expand All @@ -241,4 +219,44 @@ path/to/file.css
1 problem (1 error, 0 warnings)`);
});

it('outputs parse errors and warnings without rule and severity', () => {
const results = [
{
source: 'path/to/file.css',
parseErrors: [
{
line: 1,
column: 1,
stylelintType: 'foo-error',
text: 'Cannot parse foo',
},
],
warnings: [
{
line: 3,
column: 1,
rule: 'no-bar',
severity: 'error',
text: 'Disallow bar',
},
{
line: 2,
column: 1,
text: 'Anonymous error',
},
],
},
];

const output = prepareFormatterOutput(results, stringFormatter);

expect(output).toBe(stripIndent`
path/to/file.css
1:1 × Cannot parse foo foo-error
2:1 × Anonymous error
3:1 × Disallow bar no-bar
3 problems (3 errors, 0 warnings)`);
});
});

0 comments on commit 6683e1e

Please sign in to comment.