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

[Feature Request]: LiquidSchema(node) check type for SourceType.LiquidHtml

Open albchu opened this issue 10 months ago • 0 comments

Feature Request

In theme-check-common, this is far too common of a pattern:

  create(context) {
    return {
      async LiquidRawTag(node) {
        if (node.name !== 'schema' || node.body.kind !== 'json') return;

        const schema = await getSchema(context);

        const { validSchema, ast } = schema ?? {};
        if (
          !validSchema ||
          validSchema instanceof Error ||
          !ast ||
          ast instanceof Error
        ) {
          return;
        }

As our library of theme checks grow, this is only becoming a larger bit of duplicated overhead between checks that validate some details within a valid liquid schema.

Describe the solution you'd like Id like to see a new CheckNodeMethod like LiquidSchema that only triggers once these checks are performed. Then we only trigger checks like this once the liquid schema has passed basic json validation.

This can improve readability and performance across all liquid checks that look at the liquid schema. It can look like:


export const SomeSweetNewCheck: LiquidCheckDefinition = {
  meta: { ...meta, type: SourceCodeType.LiquidHtml },

  create(context) {
    return {
      async LiquidSchema(node) {
        const { validSchema, ast } = node.schema;
        ...
        // Insert sweet functionality here

albchu avatar Feb 25 '25 16:02 albchu