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

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 marked this pull request as ready for review April 30, 2021 07:29
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super, thanks.

All looks good to me, including the EOL insertion.

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

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

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)"
      }
    ]
  }
]
```
Copy link
Member

@mattxwang mattxwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@jeddy3 jeddy3 deleted the issue-5265 branch May 1, 2021 09:51
@jeddy3
Copy link
Member

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
Development

Successfully merging this pull request may close these issues.

Fix invalid json for max warnings option
3 participants