sarif-rs
sarif-rs copied to clipboard
clippy needs a way to prefix paths
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 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.
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
The alternative would be to just use fs::canonicalize tbh
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
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.
Thanks -- this is still on my list to resolve, I just haven't had much time to get to things here.
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.