Reputation: 13842
I currently have a npm script for running a linter. Obviously there will be some errors being outputted, but the npm script fails rather than just show me errors and move on.
This is terrible especially when I have something else calling the script as it marvellously breaks everything. I can always run npm run lint --force
to avoid errors but I don't have that --force
luxury all the time (for example, with a git-hook).
How can I setup my script to output errors without causing a mess?
Upvotes: 23
Views: 37005
Reputation: 8176
There are a few other options which are cross platform too:
eslint || true
For this to work on Windows, you'll need to npm install cash-true
first
exitzero eslint
You'll need to npm install exitzero
first
Upvotes: 18
Reputation: 31
I guess solving that in npm scripts
will always be a bit limited. There is a micro module runjs which is a kind of small enhancement for scripts. Thing is that you can run cli commands and handle errors in JS. So you could do something like this (runfile.js
):
import { run } from 'runjs'
export function lint () {
try {
run('eslint .')
} catch (e) {
// handle error how you want, you can silently just do nothing or re-throw it by: throw e.stack
}
}
then in the console:
$ run lint
Upvotes: 2
Reputation: 13842
Found the answer:
Simply adding: exit 0
to the end of the command did it!
Upvotes: 28