jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.25k stars 508 forks source link

lint flag to make warnings exit with non-zero #853

Closed georgevarghese185 closed 4 years ago

georgevarghese185 commented 4 years ago

Current Behavior

If you have lint warnings and run yarn lint or tsdx lint, the warnings are printed but the command exits without an error

Desired Behavior

It would be nice to have tsdx lint take a flag to exit with a non-zero code if warnings are found so that a pre-commit hook can prevent a commit from going through and require the user to fix the warnings.

Who does this impact? Who is this for?

This is for people who want to force all lint errors and warnings to be cleared before committing code.

agilgur5 commented 4 years ago

ESLint has the --max-warnings flag, but it seems like there is no config option via eslintrc for this -- that would be optimal.

Without such a change upstream TSDX would need to forward the flag. Would prefer to forward all flags to ESLint as we do with tsdx test and Jest but IIRC there's a limitation; had thought to do so some time ago

agilgur5 commented 4 years ago

Ah, right, we use ESLint's CLIEngine API, which doesn't support all flags or converting all flags 😕

That being said, --max-warnings would be fairly easy to implement in TSDX. Can use report.warningCount and add a small check after this line:

https://github.com/formium/tsdx/blob/116a043a221ef5a8d8dd3db0453c0b864fe3c368/src/index.ts#L597-L599

Would welcome a PR for --max-warnings along with a test and update to API docs