Lint Typescript Before pushing with Pre Push Hooks
If you aren't linting your Typescript before pushing your code, you are probably pushing bugs.
USE CASE:
As a developer, you want to make sure you are pushing good code that passes tests and doesn't break any builds. One thing that can be done to assist with this is implementing a git pre-push hook.
This hook will run a script before your code is pushed to your version control remote. All you have to do is put it in the correct location. Easy Peasy.
WIP's:
We also have the need to push WIP (Work In Progress) from time to time. The following hook will look at the beginning of your last commit message for WIP:
If the string is found, it wont run the linter.
ASSUMPTIONS:
You have an existing codebase that is tracking a remote and you have a .git
directory in your project.
You also have eslint
installed in your node_modules
directory.
THE PROCESS:
We are going to create a pre-push-hook
hook that will do all the work for us.
THE CODE:
IMPLEMENT:
By putting the file pre-push-hook
file in the .git/hooks/
directory of your project, you will be good to go.
TROUBLESHOOTING:
You will need to give the pre-push-hook
execute permissions or it wont run.
chmod +x .git/hooks/pre-push-hook