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

Include correction in JSON output #504

Open
nobodywasishere opened this issue Nov 19, 2024 · 3 comments
Open

Include correction in JSON output #504

nobodywasishere opened this issue Nov 19, 2024 · 3 comments

Comments

@nobodywasishere
Copy link
Contributor

It would be really useful for the VS Code extension to be able to correct issues within editor directly instead of needing to go to the terminal to invoke ameba. Depending on how much additional time it takes to compute, it may be worth doing. Something like:

❯ ameba --stdin-filename filename.cr --format json /dev/null | jq
a.try { |i| i.odd? }
{
  "sources": [
    {
      "path": "filename.cr",
      "issues": [
        {
          "rule_name": "Style/VerboseBlock",
          "severity": "Convention",
          "message": "Use short block notation instead: `try(&.odd?)`",
          "location": {
            "line": 1,
            "column": 3
          },
          "end_location": {
            "line": 1,
            "column": 20
          },
          "correction": {
            "location": {
              "line": 1,
              "column": 3
            },
            "end_location": {
              "line": 1,
              "column": 20
            },
            "text": "try(&.odd?)"
          }
        }
      ]
    }
  ],
  "metadata": {
    "ameba_version": "1.6.3",
    "crystal_version": "1.14.0"
  },
  "summary": {
    "target_sources_count": 1,
    "issues_count": 1
  }
}

Which would work perfectly to create a WorkspaceEdit with the replace method.

@nobodywasishere nobodywasishere changed the title Include corrected source code in JSON output Include correction in JSON output Nov 19, 2024
@nobodywasishere
Copy link
Contributor Author

nobodywasishere commented Nov 19, 2024

Alternatively if generating the correction takes too long, may be more worth it just to include whether it's correctable via a bool and have a different way of getting / generating the correction after the user has said they want it.

@Sija
Copy link
Member

Sija commented Nov 19, 2024

That's an interesting use-case, I reckon we could think of sth along these lines. Do you know how other tools (in Ruby or JS for instance) are handling this?

@nobodywasishere
Copy link
Contributor Author

Having language servers that implement this functionality, as far as I know (see lsp spec).

The full correction could be excluded by default but put behind a flag --include-corrections. Then when the user clicks "Correct issue" or similar code action on hovering over ameba lint, ameba would be run again (just for this file) with that flag set, and the code action would be executed w/ the results from that.

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

No branches or pull requests

2 participants