Published on

Using Husky with Helm Templates

Authors

In my UI projects I love using Husky as you can use it to enforce things like certain formatting for your .js and .css files. The problem is I often have an infrastructure folder in the root of my UI project which has things like Dockerfiles and helm charts.

An issue I ran into today was when I used a helm-chart template with values from the values.yaml file. After adding these files and trying to commit I received an error similar to the following:

SyntaxError: Document is not valid YAML

Where the error message also included a suggestion about how to try fix this.

Husky does not seem to be able to recognise the handlebar variables in templates e.g. {{ .Values.app.name }}.

After Googling I found that it is not possible to make Husky ignore certain files/directories.

As a work around what I did instead was remove the precommit script in my project's package.json file. Stage and commit all the helm template files I want:

git add path/to/helm-chart
git commit -m "Whatever commit message"

Note in the above how I did not stage the package.json file in the git add.

Once this has completed successfully re-add the precommit line back to the package.json file.