Skip to content

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

@albchu

Description

@albchu

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions