New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ejs-lint

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ejs-lint

Linter/Syntax Checker for EJS Templates

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33K
decreased by-17.1%
Maintainers
1
Weekly downloads
 
Created
Source

EJS-Lint

Linter/Syntax Checker for EJS Templates.

This was born out of mde/ejs #119 and the frustration of the unhelpful errors thrown if you make a simple syntax error inside a scriptlet tag.

This project is in development, and has not reached the MVP stage yet. Stay tuned; in the meantime, PR's are welcome!

Features

At this early stage, EJS-Lint only supports parsing scriptlet tags (<%, %>, <%_, _%>, and -%>). It ignores all other tags.

It also is set up to handle old-style includes (<% include filename %>) by ignoring them. It does not lint included files regardless of the method of inclusion.

Note: This linter does not attempt to check for unclosed EJS tags, so if you get an error Unexpected token with a line number that doesn't contain any scriptlets, you most likely forgot to close a tag earlier.

More features coming soon.

Installation

npm install ejs-lint

How it Works

EJS-Lint replaces everything outside a scriptlet tag with whitespace (to retain line & column numbers) and then runs the resulting (hopefully) valid JS through node-syntax-error to check for errors.

Development Notes

Clone the repo; then do npm i to load dependencies.

For development testing, you can place your EJS in try.ejs and run npm run try. If there is an error, it will console.log() the it like this: ErrorMessage(line:col).

There are two lines in the source code that you may want to uncomment during development for verbose output. If you are getting the wrong line or column number, uncomment the second one. This will print the output of parse() so you can see the JS that EJS-Lint is sending to node-syntax-error.

Note: The files in vendor/ are NOT regular versions of mde/ejs! lib/ejs.js has the following line added:

exports.Template = function(t,o){return new Template(t,o)};

This allows us to access Template.parseTemplateText(), a "plumbing" function that parses the string and splits it into an array.

CLI

Usage:
 ejslint <file>

 If no file is specified, reads from stdin

Options:
  -p, --parse  Run parse() instead of lint()                           [boolean]
  --help       Show help                                               [boolean]

API

Require:

var ejsLint=require('./path/to/index.js');

Then do ejsLint.lint(text, options); where text is the EJS template and options are the EJS options. This returns a node-syntax-error object that you can parse.

ejsLint.parse(text, options) is a "plumbing" function that strips away all non-js text and replaces it with whitespace. This may be useful if you wish to use an alternate syntax checker.

License

Copyright (c) 2016 Ryan Zimmerman

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs

Package last updated on 07 May 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc