Skip to content

Hide .snap snapshot files by insta.rs framework#7235

Closed
nyurik wants to merge 1 commit intogithub-linguist:mainfrom
nyurik:hide-snap-files
Closed

Hide .snap snapshot files by insta.rs framework#7235
nyurik wants to merge 1 commit intogithub-linguist:mainfrom
nyurik:hide-snap-files

Conversation

@nyurik
Copy link
Contributor

@nyurik nyurik commented Feb 14, 2025

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:

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

See https://insta.rs/docs/snapshot-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
@nyurik nyurik requested a review from a team as a code owner February 14, 2025 20:10
Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

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.

@nyurik
Copy link
Contributor Author

nyurik commented Feb 15, 2025

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?

@lildude
Copy link
Member

lildude commented Mar 5, 2025

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

def generated_net_docfile?
return false unless extname.downcase == ".xml"
return false unless lines.count > 3
# .NET Docfiles always open with <doc> and their first tag is an
# <assembly> tag
return lines[1].include?("<doc>") &&
lines[2].include?("<assembly>") &&
lines[-2].include?("</doc>")
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants