Skip to content

[prettier-plugin-sh] ⬆️ support zsh dialect by upgrading sh-syntax to 0.6.0 #511

Closed

Description

@jjloneman

🤖 Disclaimer: I had Claude help me write this issue.


feat(sh): ✨ support zsh dialect by upgrading sh-syntax to 0.6.0

🐛 Problem

  • prettier-plugin-sh cannot format valid zsh scripts.
  • Zsh parameter modifier chains such as ${0:A:h:h} are rejected with ternary operator missing ? before :.
  • Root cause is upstream: sh-syntax bundled a mvdan/sh build with no zsh LangVariant.

🔁 Reproduction

  • Format a file containing a zsh modifier chain:
    DIR=${0:A:h:h}
  • Result with the current pinned sh-syntax (0.5.8):
    • Throws ternary operator missing ? before :
    • LangVariant.LangZsh is undefined (no zsh variant exists)

📦 Upstream fix (already merged/available)

🛠️ Proposed changes in prettier-plugin-sh

  • Bump dependency: packages/sh/package.json → "sh-syntax": "^0.6.0"
  • Expose the variant: add LangVariant.LangZsh to the variant option choices in packages/sh/src/index.ts
    • Without this, Prettier rejects variant: 16 with Invalid variant value. Expected 1, 2, 4, 8 or 32, but received 16.
  • Update tests for the new upstream error wording (mvdan/sh v3.13 now backtick-quotes tokens):
    • test/error.spec.ts: encountered ) → encountered `)`
    • test/__snapshots__/fixtures.spec.ts.snap (445.sh): closing quote ' → closing quote `'`

✅ Verification

  • After applying all three changes locally against [email protected]:
    • ${0:A:h:h} formats correctly with variant: LangVariant.LangZsh
    • foo(){ echo ${1:t}; } → foo() { echo ${1:t}; } (modifier chains preserved)
    • Full suite green: lint:es ✅, lint:tsc ✅, vitest run ✅ (83/83)

⚠️ Note on installing sh-syntax@^0.6.0

  • Yarn 4's default npmMinimalAgeGate (1d) reports newly published versions as quarantined for the first 24h after publish.
  • [email protected] was published 2026-07-08T05:08:33Z, so a fresh install only resolves cleanly after 2026-07-09T05:08:33Z.
  • Not a blocker for the change itself — just relevant for anyone testing immediately after release.

🙋 Willing to contribute

  • I will open a PR with all three changes (dependency bump + LangZsh choice + test updates) once Yarn's 1-day age-gate moratorium on [email protected] lifts (after 2026-07-09T05:08:33Z), so CI can resolve the dependency cleanly.

Activity

  1. JounQin commented on Jul 9, 2026

    @JounQin
    Member

    Thanks, and feel free to add sh-syntax into yarn's pre-approved config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions