Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bug: templ fmt fails in nushell #1266

@shadr

Description

@shadr

Currently templ fmt fails when SHELL is set to nushell

(✗) hello.templ [ error=failed to format file "hello.templ": prettier error: unable to format with command ["/run/current-system/sw/bin/nu" "-c" "prettier --use-tabs --stdin-filepath $TEMPL_PRETTIER_FILENAME"], output: "Error: nu::parser::env_var_not_var\n\n  x Use $env.TEMPL_PRETTIER_FILENAME instead of $TEMPL_PRETTIER_FILENAME.\n   ,-[source:1:38]\n 1 | prettier --use-tabs --stdin-filepath $TEMPL_PRETTIER_FILENAME\n   :                                      ^^^^^^^^^^^^|^^^^^^^^^^^\n   :                                                  `-- use $env.TEMPL_PRETTIER_FILENAME instead of $TEMPL_PRETTIER_FILENAME\n   `----\n\n", error: exit status 1 ]
(✓) Format Complete [ count=1 errors=1 changed=0 duration=18.599347ms ]

This happens because DEFAULT_COMMAND uses $TEMPL_PRETTIER_FILENAME, but nushell is not POSIX compliant and uses $env.VAR instead of $VAR.
While you can specify prettier command manually or set SHELL variable to POSIX compliant shell

SHELL=sh templ fmt hello.templ
# or
templ fmt -prettier-command "prettier --use-tabs --stdin-filepath $env.TEMPL_PRETTIER_FILENAME" hello.templ

it would be nice to support it by default.
I'm new to Go, but I can try to make a PR if maintainers are fine with that change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions