Registry / testing / ejs-lint

ejs-lint

JSON →
library2.0.1jsnpmunverified

Linter and syntax checker for EJS templates. Version 2.0.1 released September 2022. ESM-only since v2, requires Node 14+. Parses scriptlet and expression tags, replacing template output with whitespace to retain line/column numbers, then validates resulting JavaScript with acorn via node-syntax-error. Distinguishes itself from EJS core by providing meaningful syntax error messages with line context, supporting custom delimiters, CLI and API usage. Does not check for unclosed EJS tags but helps detect malformed scriptlets. Alternatives exist (e.g., eslint-plugin-ejs) but ejs-lint is the standalone, lightweight option.

npm install ejs-lint
INSTALL
IMPORT
SIG · EJS-LINT
E
ejs-lint
testingjavascriptv2.0.1
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 ejsLint from 'ejs-lint'
✗ const ejsLint = require('ejs-lint')
ESM-only since v2; use dynamic import or upgrade to Node 14+.
cli
✓ import { execSync } from 'child_process'; execSync('npx ejslint file.ejs', {stdio: 'inherit'})
✗ import { ejslint } from 'ejs-lint'
CLI is invoked via the 'ejslint' command, not as a programmatic export.
types
✓ import type { SyntaxError } from 'node-syntax-error'
✗ import type { EjsLintError } from 'ejs-lint'
ejs-lint does not export its own error type; returns node-syntax-error objects.

Shows how to use the ejsLint API to check an EJS template for syntax errors.

import ejsLint from 'ejs-lint'; const template = `<% if (user) { %> <h1><%= user.name %></h1> <% } else { %> <h1>No user</h1> <% } %>`; const err = ejsLint(template, { delimiter: '%' }); if (err) { console.error(`Syntax error at line ${err.line}, column ${err.column}: ${err.message}`); } else { console.log('Template is valid'); }
ejslint --version
Debug
Known issues
breakingv2.0.0 switched to ESM-only; CommonJS require() will fail
fix
Update code to use import statements or use dynamic import().
affects: >=2.0.0
breakingv2.0.0 dropped Node 12 support; requires Node 14+
fix
Upgrade Node.js to version 14 or higher.
affects: >=2.0.0
breakingv1.0.0 removed deprecated .lint() alias; use ejsLint() instead
fix
Replace .lint(text, options) with ejsLint(text, options).
affects: >=1.0.0
breakingv0.3.0 removed parse() method and --parse CLI option
fix
Use ejsLint() API or ejslint CLI only.
affects: >=0.3.0
gotchaDoes not detect unclosed EJS tags; will show confusing errors on lines without scriptlets
fix
Manually check for unclosed <% or %> before blaming the linter.
affects: >=0.1.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using CommonJS require() on EJS-Lint v2+
fix
Switch to import or use dynamic import: const ejsLint = (await import('ejs-lint')).default;
SyntaxError: Unexpected token (1:5) - line doesn't contain any scriptlets
Forgot to close an EJS tag earlier in the template
fix
Double-check all <% and %> tags are properly closed.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
ejsrequiredParses template text using EJS's internal Template.parseTemplateText()
node-syntax-errorrequiredGenerates syntax error objects with line/column info
acornrequiredJavaScript parser used for syntax validation
rewirerequiredLoads EJS to access private parseTemplateText function
Agent activity
14 hits · last 30 days
node
12
Resources