how to use ejs lint in cli

て烟熏妆下的殇ゞ 提交于 2020-05-15 02:58:06

问题


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?


回答1:


Short answer

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.

Extended answer

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



回答2:


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


来源:https://stackoverflow.com/questions/48140310/how-to-use-ejs-lint-in-cli

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!