palantir/tslint

Add watch option

srghma opened this issue Β· 14 comments

I haven't found issue with such request, so I'm creating one

I want to bump this issue since there was no activity since 24 Aug and I think that is important.

I use nodemon for watching file changes and run tslint in npm script. One example https://github.com/ryancat/create-ts-library/blob/master/package.json#L9

You will need to not exit with error code 2 to avoid nodemon from exiting.

Just want to stress the need for this feature.

I would like this feature to be implemented

I've got a fever. And the only prescript is more --watch.

this is a very hard feature to implement because it likely requires radically rearchitecting to support incremental re-runs so i think the best bet here will be to combine tslint with other existing watcher tools, like nodemon mentioned above or https://www.npmjs.com/package/watch

requires radically rearchitecting to support incremental re-runs

FWIW that does sound very hard, but also more performant than re-running all of tslint on change, as would happen with third-party tools. +1 to this request, along with a healthy side of understanding.

⌚ing this.

My tool actually supports this behaviour, because I understand that it's really hard to implement. https://github.com/guidojo/multipleTypescriptCompilers#readme

The tool currently runs a tsc compiler and after each run, it will lint each file separately. If interrupted by another compilation, it will abort. :)

Did anyone look into this yet?

In the meantime, I've been using the onchange package in my npm scripts: https://github.com/alexburner/chain-of-being/blob/85230a5b0bf06e1e0a729559c340493c93dac008/package.json#L18

After seeing it in the prettier docs: https://prettier.io/docs/en/watching-files.html

favna commented

Using the onchange package works perfectly, many thanks for that suggestion @alexburner. Currently using it for both tslint and stylelint:

{
    "lint": "concurrently \"yarn tslint:once\" \"yarn stylelint:once\" && onchange 'src/**/*.*' -- concurrently \"yarn tslint:once\" \"yarn stylelint:once\"",
    "tslint:once": "tslint -p . -c ./tslint.json --fix './src/**/*.+(ts|tsx)'",
    "stylelint:once": "stylelint --fix **/*.scss",
}

I think the onchange solution is sufficient for CLI use cases. You can use the Node API and implement a watcher on top of that if you want. I'm going to close this because we'd like to focus development efforts elsewhere in TSLint.

I disagree that this should be closed, and should at least stay on the roadmap even if focus is currently elsewhere. Watching seems overly complicated compared to tsc's tsc -w