theme-tools icon indicating copy to clipboard operation
theme-tools copied to clipboard

Unused files check

Open madsenmm opened this issue 1 year ago • 7 comments

Is your feature request related to a problem? Please describe. Would be a nice feature to allow theme check to find unused references, i.e. snippets, sections (not sure if possible with JSON templates), assets...

Describe the solution you'd like Like the current MissingTemplate check, would be nice to have a check that detects files not used.

madsenmm avatar Oct 02 '24 09:10 madsenmm

Thank you @madsenmm! I've renamed the issue to avoid confusion with JSON templates. My understanding is that you're proposing a check for unused files (however, I don't think we have unused JSON templates).

karreiro avatar Oct 03 '24 11:10 karreiro

Yes, more specifically snippets, just added sections and assets, in case it is possible to check somehow. JSON templates won't be necessary, in the context I was thinking, was the check on sections, which probably going to be difficult, if not impossible when they can be used dynamically in JSON templates.

madsenmm avatar Oct 03 '24 11:10 madsenmm

This is a multifile check and theme check 2 doesn't really support them. #529 might pave to way to make this possible, but it would require a lot of careful planning for this check to run as fast as you are typing code.

Could be a CLI/CI only thing. But we don't have the road paved for those either.

charlespwd avatar Oct 17 '24 20:10 charlespwd

@charlespwd So not possible, or just way too CPU intensive task to do at runtime?

madsenmm avatar Oct 18 '24 05:10 madsenmm

It's possible. But it would be CPU intensive if you wanted to run this check every time a file changes. You need to visit all the files, not just the open files to know if something is used or not. You also need to go across template.json files, sections/*.json files.

In the CLI that's not much of a problem, since you're running theme check on all the files anyway. But in VS Code/language server, we only run theme check on the open files to keep things snappy (and avoid noise in the Problems window).

charlespwd avatar Oct 18 '24 14:10 charlespwd

@charlespwd How would one go about only running via the CLI, and NOT on runtime, but more like only when running the shopify theme check command?

madsenmm avatar Oct 24 '24 12:10 madsenmm

That's feasible. We don't have the mechanism for that just yet. I'll keep the issue open.

charlespwd avatar Oct 24 '24 14:10 charlespwd

We've added lots of support for this!

  • https://github.com/Shopify/theme-tools/pull/1041 just shipped which lets you know if a snippet is unused
  • https://github.com/Shopify/theme-tools/pull/956 which enables the ability to see how files are linked together

graygilmore avatar Sep 19 '25 18:09 graygilmore