Watching with eslint

If you have your dev environment set up like me, you’re used to having Jest in a terminal window of it’s own continuously running and watching for changes to test files, but what about eslint, there doesn’t appear to be the same option out of the box.

Whilst there are npm packages for adding this capability the easiest way is to simply use watch, although you’ll need to install it using npm install watch -g if not already installed. Our CLI command would then look something like this

yarn watch 'eslint --ext *.ts,*.tsx,*.js,*.jsx src' src

if we ignore the ‘eslint…’ section, basically we’re just telling watch to watch the folder src (the src text at the end of the command). Ofcourse if you’re working on a specific folder, for example src/components/mediaPlayer, you’ll want to watch that specific folder. Just don’t forget we’re running two separate commands, so it’s no good watching one folder but having lint run against a different folder.