linguist icon indicating copy to clipboard operation
linguist copied to clipboard

Hide .snap snapshot files by insta.rs framework

Open nyurik opened this issue 10 months ago • 2 comments

Description

*.snap are snapshot files stored by the popular Rust Insta framework, and are auto-generated when the test results are accepted. Subsequent test runs just match results against these files.

By default .snap files are stored in the .../snapshots/*.snap, but user may modify the location. For now, I marked all .snap files as internal, but this may need to be revisited if other common extension is also .snap

Examples of /snapshots/*.snap - 103k instances.

Note that it appears .snap is often used by other repositories for similar purpose, so I think it might be OK to hide it for them as well. Code search without /snapshots/ prefix

Checklist:

  • [x] I am adding new or changing current functionality
    • [ ] I have added or updated the tests for the new or changed functionality.

nyurik avatar Feb 14 '25 20:02 nyurik

This is too blunt a weapon. Linguist only associates this extension with the Jest Snapshot language. This change will mark all .snap files as generated too which is not correct else they would have been marked as generated at the time language support was added.

@lildude I was concerned about it too tbh... can you suggest a way to limit these files somehow, e.g. maybe by its content? Or only if this is a "rust language" repo?

nyurik avatar Feb 15 '25 20:02 nyurik

@lildude I was concerned about it too tbh... can you suggest a way to limit these files somehow, e.g. maybe by its content? Or only if this is a "rust language" repo?

There are several things you can do in combination:

  • check the path and extension (you can start with the most common/default path... users can always override if they change it)
  • check the content for something unique to these files (according to the page you linked to, you've got ---, expression and source occurring in the first 3-5 lines of every file you can match on).

You can see examples of all of these in the the generated.rb file and you can combine them. Something like done for .Net Doc files:

https://github.com/github-linguist/linguist/blob/6f9715869791ffc235df50171dcb097af8f292c4/lib/linguist/generated.rb#L252-L261

lildude avatar Mar 05 '25 10:03 lildude