How do I get tslint to watch for changes in a specific folder?

As far as a script you can run from the command line is concerned, you can try using npm-watch: https://www.npmjs.com/package/npm-watch.

I've used it to successfully do what you're talking about. Here's what I did:

Installed npm-watch to my project:

$ npm install npm-watch --save-dev

Added the following to my package.json file:

"watch": {
    "lint": "src/main.ts"
},
"scripts": {
    "lint": "tslint src/**/*.ts -t verbose",
    "watch": "npm-watch"
},

I figure npm-watch is a good tool for giving watch functionality to tools that don't have it, like tslint.

Update:

Also, if you don't want to add a "watch" section to your package.json file, I've actually just discovered a new tool I like even better called chokidar. It allows you to specify the file selectors and command you want to run all on the same line.

Here's my updated package.json:

"scripts": {
    "lint:watch": "chokidar webpack.config.* src/**/*.ts buildScripts/**/*.ts -c \"npm run lint\" --initial --verbose"
},

You basically give it one or more file selectors, and then use the '-c' parameter to specify the command you want run when any of those files are changed.

So now you can just run the command:

$ npm run lint:watch

I like to run it with the --initial flag set, so it doesn't wait for any files to change before executing the command.


If you are using TypeScript, then you can probably use tsc -w to watch the changes.

 "scripts": {
    "start": "tsc -w",
  }