Shopify / theme-tools

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

[Theme Check] Possible to apply the same plugin multiple times #336

Closed davidwarrington closed 3 months ago

davidwarrington commented 3 months ago

Describe the bug Plugins can be applied more than once. This produces duplicate offences in Theme Check and prevents auto fixes from being applied.

This issue is avoidable by removing the require key from the config, but may cause issues if users are extending multiple configs.

Source

require:
  - theme-check-plugin-schema

Schema/RequireImageDimensions/Liquid:
  enabled: true
Schema/RequireImageDimensions/Json:
  enabled: true

Expected behaviour Checks should only be run once

image

Actual behaviour Checks are being run twice (once per time included in the require array, plus once for being auto discovered)

image

With --auto-correct flag

image

Debugging information

I've included the Theme CLI version here because I first discovered the issue when testing Theme Check via the Theme CLI. I've since installed @shopify/theme-check-node and encountered the same issue.

Additional context I discovered this during testing because I was unaware third party checks (for example packages in node modules beginning theme-check-) are auto discovered and was using the require config option.

I may have just missed it, but auto discovery of plugins doesn't seem to be documented. It definitely seems worth shouting about as a handy feature, especially as it encourages people to following the naming convention for their packages.

Replication Steps

  1. Clone https://github.com/davidwarrington/theme-check-plugin-schema
  2. Checkout to feature/build branch
  3. Install dependencies for the above and run pnpm tsup to build so it can be imported into a project
  4. Clone https://github.com/davidwarrington/theme-check-duplicate-plugins
  5. Install the plugin repo you cloned and built in steps 1, 2 and 3 (pnpm install ../path/to/repo if using pnpm)
  6. Run shopify theme check and note duplicate error reports
  7. Run shopify theme check --auto-correct and note an error because of overlapping fix ranges
  8. Run node ./check.js and note duplicate offenses in the output