Skip to content

Documented unquoted template syntax causes YAML parsing error #1467

Description

@paduszyk

Description

Using a template at the beginning of an unquoted run value causes Lefthook to fail while parsing the configuration:

Error: yaml: line 8: did not find expected key

The current templates documentation recommends this syntax:

- run: {wrapper} yarn format

However, { begins a flow mapping in YAML. It therefore cannot begin an unquoted plain scalar. Lefthook fails during YAML parsing before template substitution occurs.

Quoting the value or using a block scalar resolves the error:

- run: "{wrapper} yarn format"
- run: |
    {wrapper} yarn format

lefthook.yml

templates:
  wrapper: npm exec --no --

pre-commit:
  jobs:
    - name: Prettier
      run: {wrapper} prettier --check .

Commands to reproduce

export LEFTHOOK_VERBOSE=true
npx lefthook validate

Alternatively:

export LEFTHOOK_VERBOSE=true
npx lefthook run pre-commit --all-files

Observed result:

Error: yaml: line 6: did not find expected key

Expected result: the configuration is parsed and {wrapper} is replaced with its configured value, as shown in the documentation.

Lefthook version

2.1.10 8d9cfec5f52367af6374a5430b4e9568844856e5

Possible solution

Update the documentation examples to quote run values that begin with a template:

- run: "{wrapper} yarn format"
- run: "{wrapper} yarn lint"
- run: "{wrapper} yarn test"

The earlier {dip} example on the same page should be quoted as well:

- run: "{dip} bundle exec rubocop -- {staged_files}"

Alternatively, Lefthook could preprocess leading template placeholders before YAML parsing, though documenting YAML-valid quoted values is likely simpler and less surprising.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions