habitat icon indicating copy to clipboard operation
habitat copied to clipboard

Add a handlebars linter to check for undefined variables in hooks

Open moretea opened this issue 7 years ago • 9 comments

How to reproduce

  • create a package (or pick an existing one)
  • create or modify hooks/run to contain:
     {{nonense_var_name}}
    

Expected output

error message

Actual output

Silent error; this variable is rendered as an empty string.

moretea avatar Feb 16 '17 13:02 moretea

This behaviour is coming from our handlebars renderer. Undefined variables don't result in rendering errors in handlebars, so they're happily rendered in our configuration and hook files as well. We could fork the handlebars renderer or add our own, but the behaviour of the if block would change. undefined and null are two of the falsey representations to handlebars.

I think I'd rather have the application fail instead of the renderer. @habitat-sh/habitat-core-maintainers what do you guys think?

reset avatar Feb 19 '17 19:02 reset

I'm in agreement with @reset for another reason: TOML doesn't have nil, so if you want something to not be set you either would have to use an empty string, which is not falsy, or false, which would probably require too much explanation ("use a string if present, or false without quotes if not present".)

I would prefer if it worked like the original suggestion, but it seems we would be fighting against the underlying technologies for a small benefit.

smith avatar Feb 21 '17 03:02 smith

As as noted, we're using a handlebars rendering library and having it check for empty references would be a major change to the library.

We could probably address this in a linting tool that could inspect the template, the required pkg_binds, and the default toml and look for any undefined references in the config templates.

smurawski avatar Feb 28 '17 20:02 smurawski

Recently had a conversation with @adamhjk about linting templates. Having a linter would have the nice side effect of catching errors around changing syntax at build time instead of at runtime (which in a recent case at $job would have saved me a few days of frustration).

bixu avatar Jul 20 '17 12:07 bixu

I vote the name of the linter be roomba so I can hab studio roomba

qubitrenegade avatar May 11 '18 16:05 qubitrenegade

There is a strict mode in the handlebars library we're using. However, it was added in version 0.32.0 and we are currently stuck on version 0.28.3 for fun reasons

However, @mwrock is currently doing work to extract the core templating logic from the Supervisor into the core crate. I think that work will begin to allow us to move forward with updating our handlebars dependency, and will also make it easier to provide an external linter.

christophermaier avatar Nov 30 '18 21:11 christophermaier

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

stale[bot] avatar Apr 03 '20 01:04 stale[bot]

any thoughts...? I think this is important...

On Thu, Apr 2, 2020 at 7:11 PM stale[bot] [email protected] wrote:

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/habitat-sh/habitat/issues/1779#issuecomment-608174771, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSBHCP3JJTWSEJWZRKHM73RKUZSTANCNFSM4DAMC2IA .

qubitrenegade avatar Apr 03 '20 07:04 qubitrenegade

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

stale[bot] avatar Sep 20 '22 20:09 stale[bot]

This issue has been automatically closed after being stale for 400 days. We still value your input and contribution. Please re-open the issue if desired and leave a comment with details.

stale[bot] avatar May 22 '23 05:05 stale[bot]