Socket
Book a DemoInstallSign in
Socket

handlebars-lint

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

handlebars-lint

Lint for missing variables, helpers, block helpers or partials.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

handlebars-lint NPM version NPM monthly downloads NPM total downloads Linux Build Status

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 :heart: and support.

Install

Install with npm:

$ npm install --save handlebars-lint

Usage

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);

Example

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' ] }

Extended example

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:

  • 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.

About

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:

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.

This file was generated by verb-generate-readme, v0.6.0, on April 27, 2018.

Keywords

find

FAQs

Package last updated on 27 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts