如何在CLI中使用ejs lint [英] how to use ejs lint in cli

查看:171
本文介绍了如何在CLI中使用ejs lint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将EJS用作节点上的视图引擎并进行快速设置。我想使用ejs-lint帮助获取错误行。我以前没有使用过linter,但是从这里阅读了文档: https://github.com / RyanZim / EJS-Lint
我假设您可以像这样在命令行中检查指定文件上的错误:ejslint

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我的假设正确,我在做什么错?我已经使用 npm install ejs-lint --save-dev

Are my assumptions right and what am I doing wrong? I've already installed using npm install ejs-lint --save-dev

安装了,如果我打算将ESlint添加到我的项目中,我想我可以使其与EJSlint一起使用吗?

Also, if I plan to add ESlint to my project I'm guessing I can have it work alongside EJSlint?

推荐答案

简短答案



直接从终端运行它:

Short answer

Run it directly from the terminal:

./node_modules/.bin/ejslint src/templates/some-template.ejs

或使用 npm脚本

// package.json
{
  ...
  "scripts": {
    "lint:ejs": "ejslint src/templates/some-template.ejs"
  }
}

// terminal
npm run lint:ejs

ESLint和EJSlint是不同的互斥过程。 ESLint分析的内容不应由EJSLint分析,反之亦然。

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.

对于我测试过的产品,您必须每个文件使用ejs linter CLI。它不如 eslint 有用,它可以处理多个文件,排除项等。

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.

如果您有一些 src / templates 目录,您可以通过执行以下操作来抹掉所有EJS文件:

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 '{}'" \;

这将适用于Unix,但不适用于Windows。您可以准备一些节点脚本以使用ejslint API跨系统进行操作。

Which would work for Unix but not for Windows. You could prepare some node script to do it cross system with the ejslint API.

还有一个 grunt插件

如果您想同时拥有ESLint和EJSLint,则应该使用不同的插件npm脚本,例如:

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 '{}'\" \\;"
  }
}

如果使用grunt,则可以创建其他任务eslint和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']);

这篇关于如何在CLI中使用ejs lint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆