如何使用nodemon进行linting? [英] how to do linting using nodemon?
问题描述
我可以使用nodemon来lint我的javascript吗?我没有使用任何构建工具,例如gulp或grunt并希望最大限度地使用node和npm。
Can I use nodemon to lint my javascript? I am not using any build tool e.g. gulp or grunt and want to maximize the use of node and npm.
来自nodemon的输出可以通过管道传输。我想使用它来使用eslint来修改已更改的文件。
The output from nodemon can be piped. I want to use this for linting the changed file using eslint.
这是我的package.json
Here is my package.json
{
"name": "app",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "nodemon server.js",
"lint": "eslint"
},
"dependencies": {
"MD5": "*",
"clean-css": "*",
"express": "~4.9.0",
"express-handlebars": "~2.0.1",
"express-redis-cache": "*",
"foundation-sites": "~5.5.3",
"fs-extra": "~0.8.1",
"node-rest-client": "~1.5.1",
"node-sass": "*",
"path": "*"
},
"devDependencies": {
"babel-eslint": "^4.1.6",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^2.1.1",
"eslint-config-airbnb-es5": "^1.0.8",
"eslint-plugin-react": "^3.13.1",
"nodemon": "~1.8.1",
"parallelshell": "~2.0.0",
"watch": "~0.17.1"
}
}
我试过这个。但它不起作用。它给出错误。
I tried this. But it doesn't work.It gives error.
"scripts": {
"start": "nodemon({ script: 'server.js' }).on('restart', function () {console.log('nodemon started');}).on('crash', function () {console.log('script crashed for some reason');});",
"lint": "eslint"
},
推荐答案
您可以使用 nodemon $ c的
exec
选项$ c>在保存代码时运行测试。这是一个例子:
You can use the exec
option of nodemon
to run your tests as you save code. Here's an example:
nodemon server.js --exec 'npm run test && node'
这将导致nodemon运行 npm run test&& node server.js
,并且在所有测试都成功运行之前它不会启动服务器。
This will cause nodemon to run npm run test && node server.js
, and it won't start the server until all the tests have run successfully.
这篇关于如何使用nodemon进行linting?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!