Shopify / theme-tools

Everything developer experience for Shopify themes
https://shopify.dev/docs/themes
MIT License
73 stars 19 forks source link

Unused files check #518

Open madsenmm opened 2 weeks ago

madsenmm commented 2 weeks ago

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.

karreiro commented 2 weeks ago

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).

madsenmm commented 2 weeks ago

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.

charlespwd commented 3 days ago

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.

madsenmm commented 3 days ago

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

charlespwd commented 2 days ago

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).