Lint for missing variables, helpers, block helpers or partials.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.
Install with npm:
$ npm install --save handlebars-lint
Pass a context and a string with handlebars templates and lint for missing variables, helpers, block helpers or partials.
Params
str
{String}: The string to lint.options
{Object}: Pass a context onoptions.context
or your own instance of handlebars onoptions.hbs
.returns
{Object}
Example
const lint = require('handlebars-lint');
lint(string, options);
Assuming we lint the following string:
With the following context:
const missing = lint(str, {
context: {
helpers: {
upper: function() {},
proper: function() {},
},
variables: {
name: 'Brian'
}
}
});
console.log(missing);
//=> { variables: [ 'foo' ] }
Assuming we lint the following string:
The following:
var missing = lint(str, {
context: {
helpers: {
upper: function() {}
},
variables: {
name: 'Brian'
}
}
});
console.log(missing);
Results in:
{
helpers: [ 'upper', 'baz', 'zzz', 'abc', 'sub', 'three', 'seven', 'lower' ],
variables: [ 'varname', 'name', 'blah', 'five', 'eight', 'whatever', 'foo' ],
partials: [ 'onetwo', 'four', 'six' ],
blockHelpers: [ 'markdown' ]
}
Heads up!
The linter assumes that an expression is a variable when:
- The expression has no params or hash arguments, as in
{{foo}}
, versus{{foo bar}}
or{{foo bar=baz}}
- There is no variable or helper on the context to distinguish otherwise.
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
- handlebars-helpers: More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate… more | homepage
- template-helpers: Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or… more | homepage
Jon Schlinkert
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on April 27, 2018.