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

Filter total # of checks and filenames in snapshots #867

Merged
merged 2 commits into from
Aug 16, 2024

Conversation

suaviloquence
Copy link
Contributor

Filters, for reproducibility:

  • total number of checks run
  • number of passed checks
  • filenames in spans (not sure about the regex on this one, let me know what you think)

Comment on lines 158 to 159
// Redact filenames in spans when lints are triggered.
settings.add_filter(r"in file [^:]+:", "in file [PATH]:");
Copy link
Owner

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

Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, ship it 🚀

@obi1kenobi obi1kenobi merged commit 8898271 into obi1kenobi:main Aug 16, 2024
33 checks passed
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

Successfully merging this pull request may close these issues.

2 participants