What is pre-commit?
Pre-commit is a tool that checks your code before you commit it to your repository. Think of it as a friendly assistant that reviews your code and helps catch common mistakes before they become part of your project. Why should I use it?- Catches mistakes early (before they get into your codebase)
- Keeps code style consistent across your team
- Only checks files you’ve changed, saving time
- Works with many programming languages
- Easy to set up and share with your team
- Blocks pull requests if it finds problems, helping maintain quality
Key concept
Checks (Hooks)Pre-commit runs checks on your code before each commit. Common checks include:
- Fixing code formatting
- Finding potential errors
- Checking for security issues
- Making sure files aren’t too large
- Looking for common mistakes
Setup
All the checks are listed in a simple configuration file.pre-commit-config.yaml at the root of your project. You can choose which checks you want to run and how they should work.
Running
In Paradime, the hooks run in your CI pipeline: a Turbo CI schedule checks the files changed in each pull request with the Run pre-commit command. You can also run the checks on demand from the Code IDE terminal. Each run will:- Look at the files that changed
- Run your chosen checks
- Either pass (allowing the pull request to proceed) or show you what needs to be fixed