sarif-rs icon indicating copy to clipboard operation
sarif-rs copied to clipboard

clippy needs a way to prefix paths

Open ImUrX opened this issue 2 years ago • 7 comments

I have my rust project inside a folder, the problem is that the paths returned by the SARIF are not taking that into account. Is there a way to prefix them?

ImUrX avatar Dec 19 '22 16:12 ImUrX

@ImUrX can you provide more details or a minimal reproducible example?

ex.

where are you running clippy from? what is the output path you're getting? what is the expected output path?

in general these tools (clippy-sarif) just take whatever's output by clippy directly, so I'm not sure it makes sense to add extra logic to modify those results. but would like to understand more what's going on.

psastras avatar Dec 20 '22 00:12 psastras

I have a workspace but I have a certain folder excluded. I wanted to make an action for that excluded folder, so it's ran inside there. The generated sarif code mentions the relative path without taking into account that I'm in another folder

ImUrX avatar Dec 20 '22 00:12 ImUrX

The alternative would be to just use fs::canonicalize tbh

ImUrX avatar Dec 20 '22 07:12 ImUrX

So, my ideas are:

  • fs::canonicalize, this will make the relative path a full path, it's an okay solution.
  • Get the git's root with something like git rev-parse --show-toplevel, this would also work but be a git-specific solution.

I want this solved, I really like the integration of clippy with GitHub idea but I can't really use it currently :c

ImUrX avatar Jan 07 '23 17:01 ImUrX

I was able to solve this issue by prepending the path to the working directory. I.e. let's assume I run cargo clippy in <REPO_ROOT>/apps/my-crate, I run

cat results.sarif \
    | jq --arg pwd "apps/my-crate" '.runs[].results[].locations[].physicalLocation.artifactLocation.uri |= $pwd + "/" + .' \
    > results.sarif.tmp
mv results.sarif.tmp results.sarif

GitHub then correctly can resolve the paths.

TimDiekmann avatar Mar 19 '23 19:03 TimDiekmann

Thanks -- this is still on my list to resolve, I just haven't had much time to get to things here.

psastras avatar Mar 22 '23 23:03 psastras

thanks for that, @TimDiekmann, that helped a lot and is a good workaround! @psastras: would this maybe be something worth documenting somewhere (until the same functionality has been added as a built-in feature to sarif-rs)? i had been looking for this for a while.

rursprung avatar Dec 13 '23 15:12 rursprung