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(ruff): adapt to new json output format #916

Closed

Conversation

lithammer
Copy link
Contributor

The JSON output format for fixes has changed causing parsing error:

Linting with ruff failed:
Cannot read properties of undefined (reading 'row')

The JSON output format for fixes has changed causing parsing error:

> Linting with ruff failed:
> Cannot read properties of undefined (reading 'row')
Comment on lines +73 to +74
// TODO: Support multiple edits.
const edit = fix.edits[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what the best way to support this is. But at least this fixes the immediate parsing error.

Copy link
Contributor Author

@lithammer lithammer Apr 13, 2023

Choose a reason for hiding this comment

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

By the way, here's an example of a fix with multiple edits:

# foo.py
import subprocess
subprocess.run([], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
$ ruff --format json --select UP foo.py
[
  {
    "code": "UP022",
    "message": "Sending stdout and stderr to pipe is deprecated, use `capture_output`",
    "fix": {
      "message": "Replace with `capture_output` keyword argument",
      "edits": [
        {
          "content": "capture_output=True",
          "location": {
            "row": 3,
            "column": 19
          },
          "end_location": {
            "row": 3,
            "column": 41
          }
        },
        {
          "content": "",
          "location": {
            "row": 3,
            "column": 41
          },
          "end_location": {
            "row": 3,
            "column": 65
          }
        }
      ]
    },
    "location": {
      "row": 3,
      "column": 1
    },
    "end_location": {
      "row": 3,
      "column": 67
    },
    "filename": "/tmp/foo.py",
    "noqa_row": 3
  }
]

@fannheyward
Copy link
Owner

fannheyward commented Apr 13, 2023

astral-sh/ruff#3709

Thank you for your PR, the ruff --format=json changed the output, will check your PR later.

fannheyward added a commit that referenced this pull request Apr 18, 2023
support old and new format both

close #916
@fannheyward
Copy link
Owner

@lithammer sorry for the delay, I made fix in #918, support old and new format both, also supports the multiple edits.

# foo.py
import subprocess
subprocess.run([], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

to

import subprocess
subprocess.run([], capture_output=True)

fannheyward added a commit that referenced this pull request Apr 18, 2023
support old and new format both

close #916
@lithammer lithammer deleted the fix-updated-ruff-json-format branch April 18, 2023 08:14
@lithammer
Copy link
Contributor Author

lithammer commented Apr 18, 2023

Thanks! Looking back at this, I don't think my fix was correct either. I was using fix.message instead of fix.edits[*].content which would've resulted in something like this:

import subprocess
subprocess.run([], Sending stdout and stderr to pipe is deprecated, use `capture_output`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants