Pass a context and a string with handlebars templates and lint for missing variables, helpers, block helpers or partials.
MIT License
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 on options.context
or your own instance of handlebars on options.hbs
.returns
{Object}
Example
const lint = require('handlebars-lint');
lint(string, options);
Assuming we lint the following string:
Title: {{upper foo}}
Hi, my name is {{proper name}}
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:
{{upper "bar"}}
{{upper varname}}
{{baz}}
{{zzz name=name}}
More content.
{{abc (sub blah)}}
{{> onetwo (three blah)}}
{{> four five}}
{{#markdown foo}}
> A markdown blockquote
{{> six (seven eight)}}
{{lower whatever}}
{{/markdown}}
The end.
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:
{{foo}}
, versus {{foo bar}}
or {{foo bar=baz}}
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
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
(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:
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.