In the ever-evolving world of Flutter app development, maintaining code quality and consistency is paramount. Enter Conventional Commits, Git Hooks, and Lefthook, a trifecta that can transform your development process. Join in this blog post as we explore how these powerful tools can help you standardize your commit messages, automate code quality checks, and supercharge your Flutter projects. Say goodbye to messy commits and hello to a more organized and efficient development experience!”.
Step 1: Installing Lefthook
To get started with Lefthook and enhance your Git workflow, follow simple installation instructions:
Step 2: Check commit message
Now that you have Lefthook installed and ready to go, let's set up a commit message file written in Dart to ensure consistency in your commit messages. This is especially useful when using Conventional Commits.
- In your Flutter project's root directory, create a new file for your Dart commit message script. You can name it something like
- Open the
commit_message.dartfile in your preferred code editor.
- Write your Dart script to generate commit messages. You can customize this script to suit your project's needs and coding conventions. For example:
Step 3: Adding the Commit Message Script to Your Lefthook Configuration
- In your project's root directory, locate or create the
lefthook.yml file. If it doesn't exist, you can initialize Lefthook by running
npx lefthook installin your project directory.
- Open this file using your preferred code editor.
- In the
pre-commitsection of your
lefthook.ymlfile, add a call to your Dart commit message script. For example:
commit-msg: commands: - name: Dart Commit Message Script validate: run: flutter pub run ./commit_message.dart
Step 4: Test it
If everything was done correctly, you should see the following message during the correct commit message:
And if the commit message does not follow the conventional commit standard, you should see the following message:
With this setup, Lefthook will execute your Dart commit message script before each commit, allowing you to generate and validate commit messages automatically.
In case of any problems, take a look at the sample repository with the above configuration:
Thanks for reading ♥️♥️