shufo / prettier-plugin-blade

Format your blade template using Prettier
https://www.npmjs.com/package/@shufo/prettier-plugin-blade
MIT License
318 stars 8 forks source link

[Bug]: Unknown node type: undefined #230

Closed saade closed 10 months ago

saade commented 10 months ago

Version

1.11.0 (prettier 3.0.2)

Template before formatting

<x-filament-forms::field-wrapper
    class="filament-navigation"
    :id="$getId()"
    :label="$getLabel()"
    :label-sr-only="$isLabelHidden()"
    :helper-text="$getHelperText()"
    :hint="$getHint()"
    :hint-icon="$getHintIcon()"
    :required="$isRequired()"
    :state-path="$getStatePath()"
>
    @php
        $isDisabled = $isDisabled();

        $addAction = $getAction('add');
        $addChildAction = $getAction('add-child');
        $editAction = $getAction('edit');
    @endphp

    <div wire:key="tree-items-wrapper">
        <div
            class="space-y-2"
            data-sortable-container
            ax-load
            ax-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('filament-tree', 'saade/filament-tree') }}"
            ax-load-css="{{ \Filament\Support\Facades\FilamentAsset::getStyleHref('filament-tree-styles', 'saade/filament-tree') }}"
            x-data="tree({
                statePath: @js($getStatePath()),
                disabled: @js($isDisabled)
            })"
        >
            @forelse($getState() as $uuid => $item)
                <x-filament-tree::tree-item
                    :actions="[$addChildAction, $editAction]"
                    :disabled="$isDisabled"
                    :item="$item"
                    :itemStatePath="$getStatePath() . '.' . $uuid"
                    :statePath="$getStatePath()"
                />
            @empty
                <div @class([
                    'w-full bg-white rounded-lg border border-gray-300 px-3 py-2 text-left',
                    'dark:bg-gray-700 dark:border-gray-600',
                ])>
                    {{ __('No items yet') }}
                </div>
            @endforelse
        </div>
    </div>

    <div class="flex justify-end">
        {{ $addAction }}
    </div>
</x-filament-forms::field-wrapper>

Template after formatting

no output

Expected Behaviour

It should be formatting properly.

Relevant log output

["INFO" - 5:56:21 PM] Formatting file:///Users/saade/GovDigital/govdigital/packages/filament-tree/resources/views/components/tree-item.blade.php
["INFO" - 5:56:21 PM] Using config file at '/Users/saade/GovDigital/govdigital/packages/filament-tree/.prettierrc'
["INFO" - 5:56:21 PM] PrettierInstance:
{
  "modulePath": "/Users/saade/GovDigital/govdigital/packages/filament-tree/node_modules/prettier/index.js",
  "version": "2.8.8",
  "prettierModule": {
    "doc": {
      "builders": {
        "line": {
          "type": "line"
        },
        "softline": {
          "type": "line",
          "soft": true
        },
        "hardline": {
          "type": "concat",
          "parts": [
            {
              "type": "line",
              "hard": true
            },
            {
              "type": "break-parent"
            }
          ]
        },
        "literalline": {
          "type": "concat",
          "parts": [
            {
              "type": "line",
              "hard": true,
              "literal": true
            },
            {
              "type": "break-parent"
            }
          ]
        },
        "lineSuffixBoundary": {
          "type": "line-suffix-boundary"
        },
        "cursor": {
          "type": "cursor"
        },
        "breakParent": {
          "type": "break-parent"
        },
        "trim": {
          "type": "trim"
        },
        "hardlineWithoutBreakParent": {
          "type": "line",
          "hard": true
        },
        "literallineWithoutBreakParent": {
          "type": "line",
          "hard": true,
          "literal": true
        }
      },
      "printer": {},
      "utils": {},
      "debug": {}
    },
    "version": "2.8.8",
    "util": {},
    "__internal": {
      "errors": {},
      "coreOptions": {
        "CATEGORY_CONFIG": "Config",
        "CATEGORY_EDITOR": "Editor",
        "CATEGORY_FORMAT": "Format",
        "CATEGORY_OTHER": "Other",
        "CATEGORY_OUTPUT": "Output",
        "CATEGORY_GLOBAL": "Global",
        "CATEGORY_SPECIAL": "Special",
        "options": {
          "cursorOffset": {
            "since": "1.4.0",
            "category": "Special",
            "type": "int",
            "default": -1,
            "range": {
              "start": -1,
              "end": null,
              "step": 1
            },
            "description": "Print (to stderr) where a cursor at the given position would move to after formatting.\nThis option cannot be used with --range-start and --range-end.",
            "cliCategory": "Editor"
          },
          "endOfLine": {
            "since": "1.15.0",
            "category": "Global",
            "type": "choice",
            "default": [
              {
                "since": "1.15.0",
                "value": "auto"
              },
              {
                "since": "2.0.0",
                "value": "lf"
              }
            ],
            "description": "Which end of line characters to apply.",
            "choices": [
              {
                "value": "lf",
                "description": "Line Feed only (\\n), common on Linux and macOS as well as inside git repos"
              },
              {
                "value": "crlf",
                "description": "Carriage Return + Line Feed characters (\\r\\n), common on Windows"
              },
              {
                "value": "cr",
                "description": "Carriage Return character only (\\r), used very rarely"
              },
              {
                "value": "auto",
                "description": "Maintain existing\n(mixed values within one file are normalised by looking at what's used after the first line)"
              }
            ]
          },
          "filepath": {
            "since": "1.4.0",
            "category": "Special",
            "type": "path",
            "description": "Specify the input filepath. This will be used to do parser inference.",
            "cliName": "stdin-filepath",
            "cliCategory": "Other",
            "cliDescription": "Path to the file to pretend that stdin comes from."
          },
          "insertPragma": {
            "since": "1.8.0",
            "category": "Special",
            "type": "boolean",
            "default": false,
            "description": "Insert @format pragma into file's first docblock comment.",
            "cliCategory": "Other"
          },
          "parser": {
            "since": "0.0.10",
            "category": "Global",
            "type": "choice",
            "default": [
              {
                "since": "0.0.10",
                "value": "babylon"
              },
              {
                "since": "1.13.0"
              }
            ],
            "description": "Which parser to use.",
            "choices": [
              {
                "value": "flow",
                "description": "Flow"
              },
              {
                "value": "babel",
                "since": "1.16.0",
                "description": "JavaScript"
              },
              {
                "value": "babel-flow",
                "since": "1.16.0",
                "description": "Flow"
              },
              {
                "value": "babel-ts",
                "since": "2.0.0",
                "description": "TypeScript"
              },
              {
                "value": "typescript",
                "since": "1.4.0",
                "description": "TypeScript"
              },
              {
                "value": "acorn",
                "since": "2.6.0",
                "description": "JavaScript"
              },
              {
                "value": "espree",
                "since": "2.2.0",
                "description": "JavaScript"
              },
              {
                "value": "meriyah",
                "since": "2.2.0",
                "description": "JavaScript"
              },
              {
                "value": "css",
                "since": "1.7.1",
                "description": "CSS"
              },
              {
                "value": "less",
                "since": "1.7.1",
                "description": "Less"
              },
              {
                "value": "scss",
                "since": "1.7.1",
                "description": "SCSS"
              },
              {
                "value": "json",
                "since": "1.5.0",
                "description": "JSON"
              },
              {
                "value": "json5",
                "since": "1.13.0",
                "description": "JSON5"
              },
              {
                "value": "json-stringify",
                "since": "1.13.0",
                "description": "JSON.stringify"
              },
              {
                "value": "graphql",
                "since": "1.5.0",
                "description": "GraphQL"
              },
              {
                "value": "markdown",
                "since": "1.8.0",
                "description": "Markdown"
              },
              {
                "value": "mdx",
                "since": "1.15.0",
                "description": "MDX"
              },
              {
                "value": "vue",
                "since": "1.10.0",
                "description": "Vue"
              },
              {
                "value": "yaml",
                "since": "1.14.0",
                "description": "YAML"
              },
              {
                "value": "glimmer",
                "since": "2.3.0",
                "description": "Ember / Handlebars"
              },
              {
                "value": "html",
                "since": "1.15.0",
                "description": "HTML"
              },
              {
                "value": "angular",
                "since": "1.15.0",
                "description": "Angular"
              },
              {
                "value": "lwc",
                "since": "1.17.0",
                "description": "Lightning Web Components"
              }
            ]
          },
          "plugins": {
            "since": "1.10.0",
            "type": "path",
            "array": true,
            "default": [
              {
                "value": []
              }
            ],
            "category": "Global",
            "description": "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
            "cliName": "plugin",
            "cliCategory": "Config"
          },
          "pluginSearchDirs": {
            "since": "1.13.0",
            "type": "path",
            "array": true,
            "default": [
              {
                "value": []
              }
            ],
            "category": "Global",
            "description": "Custom directory that contains prettier plugins in node_modules subdirectory.\nOverrides default behavior when plugins are searched relatively to the location of Prettier.\nMultiple values are accepted.",
            "cliName": "plugin-search-dir",
            "cliCategory": "Config"
          },
          "printWidth": {
            "since": "0.0.0",
            "category": "Global",
            "type": "int",
            "default": 80,
            "description": "The line length where Prettier will try wrap.",
            "range": {
              "start": 0,
              "end": null,
              "step": 1
            }
          },
          "rangeEnd": {
            "since": "1.4.0",
            "category": "Special",
            "type": "int",
            "default": null,
            "range": {
              "start": 0,
              "end": null,
              "step": 1
            },
            "description": "Format code ending at a given character offset (exclusive).\nThe range will extend forwards to the end of the selected statement.\nThis option cannot be used with --cursor-offset.",
            "cliCategory": "Editor"
          },
          "rangeStart": {
            "since": "1.4.0",
            "category": "Special",
            "type": "int",
            "default": 0,
            "range": {
              "start": 0,
              "end": null,
              "step": 1
            },
            "description": "Format code starting at a given character offset.\nThe range will extend backwards to the start of the first line containing the selected statement.\nThis option cannot be used with --cursor-offset.",
            "cliCategory": "Editor"
          },
          "requirePragma": {
            "since": "1.7.0",
            "category": "Special",
            "type": "boolean",
            "default": false,
            "description": "Require either '@prettier' or '@format' to be present in the file's first docblock comment\nin order for it to be formatted.",
            "cliCategory": "Other"
          },
          "tabWidth": {
            "type": "int",
            "category": "Global",
            "default": 2,
            "description": "Number of spaces per indentation level.",
            "range": {
              "start": 0,
              "end": null,
              "step": 1
            }
          },
          "useTabs": {
            "since": "1.0.0",
            "category": "Global",
            "type": "boolean",
            "default": false,
            "description": "Indent with tabs instead of spaces."
          },
          "embeddedLanguageFormatting": {
            "since": "2.1.0",
            "category": "Global",
            "type": "choice",
            "default": [
              {
                "since": "2.1.0",
                "value": "auto"
              }
            ],
            "description": "Control how Prettier formats quoted code embedded in the file.",
            "choices": [
              {
                "value": "auto",
                "description": "Format embedded code if Prettier can automatically identify it."
              },
              {
                "value": "off",
                "description": "Never automatically format embedded code."
              }
            ]
          }
        }
      },
      "optionsModule": {
        "hiddenDefaults": {
          "astFormat": "estree",
          "printer": {},
          "locStart": null,
          "locEnd": null
        }
      },
      "optionsNormalizer": {},
      "utils": {}
    },
    "__debug": {}
  }
}
["INFO" - 5:56:21 PM] Using ignore file (if present) at /Users/saade/GovDigital/govdigital/packages/filament-tree/.prettierignore
["INFO" - 5:56:21 PM] File Info:
{
  "ignored": false,
  "inferredParser": "blade"
}
["INFO" - 5:56:21 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 5:56:21 PM] Prettier Options:
{
  "filepath": "/Users/saade/GovDigital/govdigital/packages/filament-tree/resources/views/components/tree-item.blade.php",
  "parser": "blade",
  "useTabs": false,
  "tabWidth": 4,
  "endOfLine": "lf",
  "plugins": [
    "/Users/saade/GovDigital/govdigital/packages/filament-tree/node_modules/@shufo/prettier-plugin-blade/dist/index.cjs"
  ],
  "semi": false,
  "singleQuote": true,
  "trailingComma": "all"
}
["ERROR" - 5:56:21 PM] Error formatting document.
["ERROR" - 5:56:21 PM] Unknown node type: undefined
Error: Unknown node type: undefined
    at Object.u [as print] (/Users/saade/GovDigital/govdigital/packages/filament-tree/node_modules/@shufo/prettier-plugin-blade/src/options.ts:3:3)
    at callPluginPrintFunction (/Users/saade/GovDigital/govdigital/packages/filament-tree/node_modules/prettier/index.js:8601:26)
    at mainPrintInternal (/Users/saade/GovDigital/govdigital/packages/filament-tree/node_modules/prettier/index.js:8550:22)
    at mainPrint (/Users/saade/GovDigital/govdigital/packages/filament-tree/node_modules/prettier/index.js:8537:18)
    at printAstToDoc (/Users/saade/GovDigital/govdigital/packages/filament-tree/node_modules/prettier/index.js:8529:18)
    at coreFormat (/Users/saade/GovDigital/govdigital/packages/filament-tree/node_modules/prettier/index.js:8837:20)
    at formatWithCursor2 (/Users/saade/GovDigital/govdigital/packages/filament-tree/node_modules/prettier/index.js:9021:18)
    at /Users/saade/GovDigital/govdigital/packages/filament-tree/node_modules/prettier/index.js:38183:12
    at Object.format (/Users/saade/GovDigital/govdigital/packages/filament-tree/node_modules/prettier/index.js:38197:12)
    at t.PrettierMainThreadInstance.format (/Users/saade/.vscode/extensions/esbenp.prettier-vscode-10.1.0/dist/extension.js:1:18023)
    at t.default.format (/Users/saade/.vscode/extensions/esbenp.prettier-vscode-10.1.0/dist/extension.js:1:16114)
    at t.PrettierEditProvider.provideEdits (/Users/saade/.vscode/extensions/esbenp.prettier-vscode-10.1.0/dist/extension.js:1:12672)
    at U.provideDocumentFormattingEdits (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:104:44948)
["INFO" - 5:56:21 PM] Formatting completed in 8ms.
vlados commented 10 months ago

@saade try to update to latest version. I was using prettier 2.0 with the latest version of the plugin where you need to upgrade to 3.0

saade commented 10 months ago

@saade try to update to latest version. I was using prettier 2.0 with the latest version of the plugin where you need to upgrade to 3.0

1.11.0 (prettier 3.0.2)

vlados commented 10 months ago

my mistake. I had the same problem but the update fixed my problem. so it's something else in that case

saade commented 10 months ago

wait, dafuck? npm shows 3.x but vscode is using 2.x

saade commented 10 months ago

🤦🏼