Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy needs a way to prefix paths #370

Open
ImUrX opened this issue Dec 19, 2022 · 7 comments
Open

clippy needs a way to prefix paths #370

ImUrX opened this issue Dec 19, 2022 · 7 comments

Comments

@ImUrX
Copy link

ImUrX commented Dec 19, 2022

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?

@psastras
Copy link
Owner

@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.

@ImUrX
Copy link
Author

ImUrX commented Dec 20, 2022

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
Copy link
Author

ImUrX commented Dec 20, 2022

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

@ImUrX
Copy link
Author

ImUrX commented Jan 7, 2023

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

@TimDiekmann
Copy link
Contributor

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.

@psastras
Copy link
Owner

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

@rursprung
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants