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 invalid json for max warnings option #5267

Merged
merged 2 commits into from May 1, 2021
Merged

Fix invalid json for max warnings option #5267

merged 2 commits into from May 1, 2021

Conversation

@ybiquitous
Copy link
Member

@ybiquitous ybiquitous commented Apr 30, 2021

I think stylelint should output any error or warning messages to STDERR instead of STDOUT.
Because users should expect that piping is available.

For example, here is an example of using the jq command:

$ stylelint --formatter=json --max-warnings=0 a.css | jq .

Max warnings exceeded: 1 found. 0 allowed

[
  {
    "source": "/tmp/a.css",
    "deprecations": [],
    "invalidOptionWarnings": [],
    "parseErrors": [],
    "errored": false,
    "warnings": [
      {
        "line": 1,
        "column": 2,
        "rule": "block-no-empty",
        "severity": "warning",
        "text": "Unexpected empty block (block-no-empty)"
      }
    ]
  }
]

Which issue, if any, is this issue related to?

Fix #5265

Is there anything in the PR that needs further explanation?

In addition, I have inserted EOL at the beginning of the warning message so that users can easily read the entire output.
But this change may be out of the scope of this PR. I want feedback, if any.
(I can revert the insertion if anyone opposites it.)

Before:

$ stylelint -f json --max-warnings=0 a.css
[{"source":"/Users/masafumi.koba/git/stylelint/stylelint/a.css","deprecations":[],"invalidOptionWarnings":[],"parseErrors":[],"errored":false,"warnings":[{"line":1,"column":2,"rule":"block-no-empty","severity":"warning","text":"Unexpected empty block (block-no-empty)"}]}]Max warnings exceeded: 1 found. 0 allowed

After:

$ stylelint -f json --max-warnings=0 a.css
[{"source":"/Users/masafumi.koba/git/stylelint/stylelint/a.css","deprecations":[],"invalidOptionWarnings":[],"parseErrors":[],"errored":false,"warnings":[{"line":1,"column":2,"rule":"block-no-empty","severity":"warning","text":"Unexpected empty block (block-no-empty)"}]}]
Max warnings exceeded: 1 found. 0 allowed

Note: I will merge the change of #5266 into this PR if approved.

@ybiquitous ybiquitous force-pushed the issue-5265 branch from a99da80 to b017a35 Apr 30, 2021
@ybiquitous ybiquitous marked this pull request as ready for review Apr 30, 2021
@jeddy3
jeddy3 approved these changes Apr 30, 2021
Copy link
Member

@jeddy3 jeddy3 left a comment

Super, thanks.

All looks good to me, including the EOL insertion.

@jeddy3 jeddy3 mentioned this pull request Apr 30, 2021
6 of 6 tasks complete
@ybiquitous
Copy link
Member Author

@ybiquitous ybiquitous commented Apr 30, 2021

@jeddy3 Thanks for the review! I've merged the #5266 change into this branch.

ybiquitous added 2 commits Apr 30, 2021
I think stylelint should output any error or warning messages to STDERR instead of STDOUT.
Because users should expect that *piping* is available.

For example, here is an example of using the `jq` command:

```console
$ stylelint --formatter=json --max-warnings=0 a.css | jq .

Max warnings exceeded: 1 found. 0 allowed

[
  {
    "source": "/tmp/a.css",
    "deprecations": [],
    "invalidOptionWarnings": [],
    "parseErrors": [],
    "errored": false,
    "warnings": [
      {
        "line": 1,
        "column": 2,
        "rule": "block-no-empty",
        "severity": "warning",
        "text": "Unexpected empty block (block-no-empty)"
      }
    ]
  }
]
```
@jeddy3 jeddy3 force-pushed the issue-5265 branch from d776c5d to 258fa1c Apr 30, 2021
Copy link
Member

@mattxwang mattxwang left a comment

LGTM, and good added test!

@jeddy3 jeddy3 changed the title Output max warnings message to STDERR Fix invalid json for max warnings option May 1, 2021
@jeddy3 jeddy3 merged commit 571fde1 into master May 1, 2021
16 checks passed
16 checks passed
@github-actions
Analyze
Details
@github-actions
Lint on Node.js 14 and ubuntu-latest
Details
@github-actions
Test on Node.js 10 and ubuntu-latest
Details
@github-actions
Test on Node.js 10 and windows-latest
Details
@github-actions
Test on Node.js 10 and macos-latest
Details
@github-actions
Test on Node.js 12 and ubuntu-latest
Details
@github-actions
Test on Node.js 12 and windows-latest
Details
@github-actions
Test on Node.js 12 and macos-latest
Details
@github-actions
Test on Node.js 14 and windows-latest
Details
@github-actions
Test on Node.js 14 and macos-latest
Details
@github-actions
Test on Node.js 16 and ubuntu-latest
Details
@github-actions
Test on Node.js 16 and windows-latest
Details
@github-actions
Test on Node.js 16 and macos-latest
Details
@github-actions
Coverage on Node.js 14 and ubuntu-latest
Details
@github-code-scanning
CodeQL No new or fixed alerts
Details
coverage/coveralls Coverage increased (+0.04%) to 96.73%
Details
@jeddy3 jeddy3 deleted the issue-5265 branch May 1, 2021
@jeddy3
Copy link
Member

@jeddy3 jeddy3 commented May 1, 2021

  • Fixed: invalid JSON for max-warnings option (#5267).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants