-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Filter total # of checks and filenames in snapshots #867
Conversation
f8c0941
to
60aa9c9
Compare
src/snapshot_tests.rs
Outdated
// Redact filenames in spans when lints are triggered. | ||
settings.add_filter(r"in file [^:]+:", "in file [PATH]:"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this filter 🤔 Could you walk me through it?
Right now it seems like it'll redact the name, but will leave:
- the line number
- the name of the type or function
- the number of instances of that lint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my intention is to just redact the path of the file, as e.g., this was different in CI and locally for me. With the same input, the line number, type name, etc. will all be deterministic and will be the same regardless of the execution environment, right? When that's the case, I think it makes sense to keep them in the snapshot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. In that case, let's redact just the changed prefix. Here's one way to do it:
let this_file = std::path::Path::new(file!()).canonicalize().expect("canonicalization failed");
will give us a canonical file path for the file where that line runs. We can then use .parent()
calls to get to the repo root. Let's call this functionality get_root_path()
.
We can then use regex::escape(&get_root_path()).as_str()
to define a regex matcher and replace the root path with [ROOT]
or something similarly obvious.
I haven't looked that closely into insta, so maybe there's an even better way. In the worst case, I think the above should work okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, ship it 🚀
Filters, for reproducibility: