Closed ZedThree closed 2 years ago
That would be great :+1:
Just checking, any bandwidth to add this in?
Probably not for a few weeks I'm afraid
I think I've found an easy-ish way to do this with the --export-fixes
option, which exports to YAML.
So, annoyingly, the export-fixes
yaml file just gives character offsets into the file, and not line numbers. This makes it very easy to apply the fix, but less easy to turn it into a Github suggestion
fixit.
One way to use the existing method would be to look for multi-line warning bodies where the second line is a '^'
by itself. Then the third line is what needs to be inserted. This is quite easy to do.
But there's still a couple of issues to do with fixes spanning multiple lines. For example, a fix might also require including a header. It might not be possible to put a suggestion
comment to fix that if the line is not in the PR diff. There's probably more or less elegant ways of handling that.
The other one being something like wrapping a statement in braces. The output of clang-tidy
(which is what we currently parse), only shows the first brace, whereas the exported fixes file has both.
Sooo, a complete but complicated method might be:
--export-fixes=<file>.yaml
dict
but convert this to be {"file": {<line>: ...}}
-- or better, make a lookup map like we do for the source file <--> diff line numbersmake_review
, when we find a warning, look up the file/line in the structure from step 2suggestion
;suggestion
;Now I've thought this through and worked out how to construct the lookup map in a non-terrible way, I will have a stab at doing it this weekend.
Rather than trying to work out if a comment is really a fixit, maybe try getting clang-tidy to fix everything, and then take the diff of that and add as a suggestion?