Add Suggested Changes to the Checks API

Nowadays compilers/interpreters/transpilers/linters become smart enough to suggest code fixes.

For example, Rust compiler can output the specific information needed for an automatic code replacement.

With this very simple example

return false;

it can output all the data required to make the suggested change:

{
    "byte_end": 507,
    "byte_start": 494,
    "column_end": 22,
    "column_start": 9,
    "expansion": null,
    "file_name": "example/src/lib.rs",
    "is_primary": true,
    "label": null,
    "line_end": 25,
    "line_start": 25,
    "suggested_replacement": "false",
    "suggestion_applicability": "MachineApplicable",
    "text": [
        {
            "highlight_end": 22,
            "highlight_start": 9,
            "text": " return false;"
        }
    ]
}

Right now, the only way to use “Suggested Changes” is to post review comments directly to the PRs, which is not very convinient for automatic processes:

  1. Review comments are operating with the line numbers based on the first diff hunk. While there might be some reasons to do that (unclear to me, to be honest :slight_smile: ), lint tools usually know nothing about VCS, and therefore, it is up to developers to re-calculate line positions in order to post review comments.
  2. There is no easy way to guarantee that there will be only one review comment for one specific suggested change: consequent linter executions will lead to a multiple comments on the same incorrect code part. There are few possible options to solve this problem:
  3. you could store the already posted review comments in some storage and check later if you had posted a comment for that specific problem. This solution is not applicable for GH Actions, for example.
  4. fetch already existing review comments and compare them to what you are going to post now. There is no any reasonable way to do that comparison, except maybe storing some kind of marker directly in the comment text (?).

Checks API allows to add annotations to the commit diffs, which is very useful for linters, for example, there are eslint and rust clippy linters exist:

It seems reasonable and very useful to add “Apply suggested fix” button to the annotation block if there is a code change attached to that annotation. Probably it should work in the same flow as “Suggested Changes” feature works now, except it will be provided by machines to humans.

1 Like

Hi @svartalf,

Thank you for being here! We’ve noted your idea for the team to review and take into consideration. We can’t promise if or when any changes will be implemented, but we really appreciate you taking the time to let us know how we can make GitHub work better for you!