how to do linting using nodemon?

不打扰是莪最后的温柔 提交于 2019-12-03 11:11:06

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'

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.

I use Standard.js for linting and I can get it to work with nodemon using the below package.json script.

"scripts": {
  "lint": "standard",
  "dev": "nodemon ./app --exec \"npm run lint && node\""
  "start": "nodemon ./app"
}

When I run npm run dev, any changes I make will be monitored and linted. I tested this in Windows using PowerShell.

Linting is purely a development process. Nodemon is a tool used for running server and not connected with build tools, but with running your application. Therefore answer is "NO". You should use proper tool for development automation like grunt, gulp etc. or just pure NPM scripts (in your package.json file).

I'd recommend using automation tools if your project is complicated, has many stages and a lot of bundling etc. However, for only linting, you could just prepare one-liner in your npm package.json, e.g. like this:

"scripts": {
    "lint": "eslint --fix src test",
}

And then run it with command: 'npm run lint'.

Remember that by using properly configured .eslintrc file, you could lint your code both by console commands, but by editors/IDEs as well (almost every broadly popular IDE has plugin for eslint).

More info about configuring eslint and creating proper eslintrc file could be found here: http://eslint.org/docs/user-guide/configuring

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