Skip to content

Using jq and Prettier in a Hook for Windows users - lessons 19 | 20 #4

@develad

Description

@develad

There is an error in the course videos for windows users in the PowerShell terminal in VScode.

THE FIX CODE IS:

"hooks": { "PostToolUse": [ { "matcher": "Write|Edit", "hooks": [ { "type": "command", "command": "jq -r '.tool_input.file_path' | tr -d '\\r' | { read -r fp; [[ \"$fp\" =~ \\.tsx?$ ]] && npx prettier --write \"$fp\"; } 2>/dev/null || true" } ] } ] }

What changed from the original version:

  • tr -d '\r' → -replace '\r','' — strips carriage return characters natively in PowerShell
  • read -r fp → direct variable assignment
  • 2>/dev/null || true → PowerShell silently ignores errors by default; you can add -ErrorAction SilentlyContinue if needed

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