clang-format-action icon indicating copy to clipboard operation
clang-format-action copied to clipboard

Add problem matcher config for pull request annotations

Open nschonni opened this issue 2 years ago • 2 comments

See https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md for the basic JSON schema for the matcher and about the registration of the matcher

nschonni avatar Feb 26 '23 19:02 nschonni

This is a cool feature idea! On first glance, I'm thinking this would be useful to annotate each incorrectly formatted file in a PR diff - is this what you had in mind?

For a use-case, I'm trying to think through what scenarios would lead a user to this feature being useful - could you elaborate on that a bit more?

Here are my initial thoughts on such scenarios:

clang-format is notoriously hard to configure to ignore specific files (ignores can be set up for all files in a directory) without some wrapper scripting, so (to my knowledge) most projects would take the dive of just formatting their project all at once and/or configuring format-on-save for their editor's project settings, coupled with some per-directory .clang-format settings files if some parts of the project need to remain unformatted or formatted differently. So, annotations in a PR marking which files are unformatted aren't much use when the least error-prone flow is to run clang-format on the entire project (if you don't format on save) to fix a CI failure from my Action.

jidicula avatar Feb 26 '23 21:02 jidicula

The annotations are usually more useful in quickly surfacing what the issues are directly in the Files tab, instead of having to drill through to the CI log. I think the assumption of it being clean normally on a repo is true, but this is helpful for PRs.

Since clang-format does emit the position information, I think the config would look something like

{
  "problemMatcher": [
    {
      "owner": "eslint-compact",
      "pattern": [
        {
          "regexp": "^(.+):(\\d+):(\\d+):\\s(error)\\s:\\s(.+)\\s\\[(.+)\\]$",
          "file": 1,
          "line": 2,
          "column": 3,
          "severity": 4,
          "message": 5,
          "code": 6
        }
      ]
    }
  ]
}

nschonni avatar Feb 26 '23 21:02 nschonni