I am using EJS as my view engine on a node and express setup. I want to use ejs-lint to help get the line for errors. I haven't use a linter before, but from reading through the documentation here: https://github.com/RyanZim/EJS-Lint I'm assuming you can just check errors on a specified file in command line like this: ejslint
Are my assumptions right and what am I doing wrong? I've already installed using npm install ejs-lint --save-dev
Also, if I plan to add ESlint to my project I'm guessing I can have it work alongside EJSlint?
Run it directly from the terminal:
./node_modules/.bin/ejslint src/templates/some-template.ejs
Or with npm script:
// package.json
{
...
"scripts": {
"lint:ejs": "ejslint src/templates/some-template.ejs"
}
}
// terminal
npm run lint:ejs
ESLint and EJSlint are different, exclusive processes. What is analysed by ESLint should not be analysed by EJSLint and vice versa. Having both installed will not cause any issues.
For what I have tested, you have to use the ejs linter CLI per file. Which is not as useful as eslint
which can process multiple files, exclusions etc.
If you had some src/templates
directory, you could lint all the EJS files by doing something like this:
find src/templates -type f -iname '*.ejs' -exec bash -c "./node_modules/.bin/ejslint '{}'" \;
Which would work for Unix but not for Windows. You could prepare some node script to do it cross system with the ejslint API.
There is also a grunt plugin for it.
If you want to have both ESLint and EJSLint, you should have different npm scripts for them, e.g:
// package.json
{
...
"scripts": {
"lint": "npm run lint:js && npm run lint:ejs",
"lint:js": "eslint src --ignore-path src/templates",
"lint:ejs": "find src/templates -type f -iname '*.ejs' -exec bash -c \"./node_modules/.bin/ejslint '{}'\" \\;"
}
}
If you are using grunt, you can create different tasks for eslint and ejslint and then create a group task:
grunt.registerTask('lint', ['eslint', 'ejslint']);
Actually, the following way is the easiest and by far the fastest execution time. It also has better error logging because it doesn't pass through the find command.
ejslint $(find ./ -type f -iname '*.ejs')
You can run npx ejslint **/*.ejs
from the command-line in your project root to check all the ejs files in your project.
the npx
is needed because you used --save-dev
(or -D
) if you used --global
(or -g
) then you can call ejs lint directly using ejslint **/*.ejs
**/*.ejs
will select any file ending in .ejs
in any folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With