how to do linting using nodemon?

后端 未结 3 962
醉酒成梦
醉酒成梦 2021-02-07 14:49

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.

The output from nodemon can be pi

相关标签:
3条回答
  • 2021-02-07 14:53

    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

    0 讨论(0)
  • 2021-02-07 15:00

    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.

    0 讨论(0)
  • 2021-02-07 15:10

    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.

    0 讨论(0)
提交回复
热议问题