Registry / testing / handlebars-lint

handlebars-lint

JSON →
library1.0.0jsnpmunverified

Lint Handlebars templates for missing variables, helpers, block helpers, or partials. Current stable version is 1.0.0. The package takes a template string and a context object with known helpers and variables, then returns an object categorizing any missing references. It differentiates between variables, helpers, block helpers, and partials. There is no active maintenance; the last release was in 2016 and the GitHub repository has been archived. It requires Node >=4 and depends on the `handlebars` package for parsing.

npm install handlebars-lint
INSTALL
IMPORT
SIG · HANDLEBARS-LINT
H
handlebars-lint
testingjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import lint from 'handlebars-lint';
const lint = require('handlebars-lint');
Package is CommonJS, but ESM import works as default export.
lint
const lint = require('handlebars-lint');
import { lint } from 'handlebars-lint';
The module exports a single function; named import is incorrect.
types
import type { LintResult } from 'handlebars-lint';
import { LintResult } from 'handlebars-lint';
Type imports are available if using TypeScript with the package's bundled types.

This shows how to lint a simple Handlebars template for missing variables using the default import.

import Handlebars from 'handlebars'; import lint from 'handlebars-lint'; const template = '{{greeting}} {{name}}'; const context = { helpers: {}, variables: { greeting: 'Hello' } }; const missing = lint(template, { context }); console.log(missing); // { variables: [ 'name' ], helpers: [], partials: [], blockHelpers: [] }
Debug
Known issues
deprecatedPackage is deprecated and no longer maintained. Last release 2016. Use ESLint plugin for Handlebars or manual validation.
fix
Migrate to eslint-plugin-handlebars or implement custom validation.
affects: >=0.0.0
gotchaThe linter treats expressions without params/hash as variables if not found in helpers or variables. This may misclassify single-word helpers (e.g. {{foo}} where foo is actually a helper without arguments).
fix
Explicitly define all helpers and variables in the context object to avoid misclassification.
affects: >=0.0.0
gotchaRequires passing an optional `Handlebars` instance via `options.hbs`; if not provided, it uses the global `Handlebars` which may not be installed.
fix
Ensure Handlebars is installed and optionally pass `hbs: Handlebars` in options.
affects: >=0.0.0
breakingThe `options.context` property must be an object with `helpers` and `variables` (and optionally `partials` and `blockHelpers`). Providing a flat object will throw or produce incorrect results.
fix
Use `{ context: { helpers: {}, variables: {} } }` as shown in examples.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Handlebars.compile is not a function
Handlebars is not installed or not passed correctly in options.
fix
Install handlebars (`npm install handlebars`) and pass `options.hbs: require('handlebars')`.
Cannot read property 'helpers' of undefined
The `context` option is missing or not an object with `helpers` property.
fix
Provide a context object like `{ context: { helpers: {}, variables: {} } }`.
The expression '{{foo}}' is ambiguous; assumed variable. If 'foo' is a helper, add it to the context.helpers.
A single word like `{{foo}}` is not found in helpers or variables; defaults to variable.
fix
Add `foo` to `context.helpers` if it is a helper, or to `context.variables` if it is a variable.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
handlebarsoptionalUsed internally to parse and compile templates for linting. Must be installed separately as a peer dependency.
Agent activity
11 hits · last 30 days
node
10
Bingbot
1
Resources
handlebars-lint — npm install handlebars-lint · libregistry