Three Keys to Maintaining Code Review Habits in Your Team
We’ve talked about code review before. Maintaining a code review habit in a team is quite difficult. We need proper processes, tools, and institutional support to ensure the efficiency and quality of our code reviews.
Process Support: Gitflow
We’ve introduced the Gitflow workflow before.
It roughly goes like this:
- Developers create a dedicated branch in the local repository to develop features.
- Developers push branch changes to the public Git repository.
- Developers initiate a Merge Request through Git.
- Other team members review the code, discuss, and make changes.
- The project maintainer merges the feature into the official repository and closes the Merge Request.
Tool Support
Enforce ESLint
Use ESLint strictly. Before code is committed, use tools like husky to enforce ESLint checks. Ensure that all submitted code passes ESLint first.
Standardize Commit Types
We internally developed a simple command-line tool that lets us define the type of commit when submitting code.
This makes it easier to understand the changes during code review later.
Commit Types
- Bug fix
- New feature
- Style fix
- Code refactor
- Test code
- Code revert
- Bug fix
- Documentation update
- Temporary commit
CLI Usage
? What do you want to do? Code commit
? Please select Git commit type? (Use arrow keys)
❯ * fixed : bug fix
* feature : new feature
* style : style fix
* refactor : code refactor
* test : test code
* revert : code revert
* doc : documentation update
(Move up and down to reveal more choices)
Code Climate
Code Climate is a code testing tool that helps with code redundancy detection and quality assessment. It supports multiple languages such as PHP, Ruby, JavaScript, CSS, Golang, Python, etc.
You can integrate it into GitLab-CI or Travis CI. When code is submitted, it automatically generates an evaluation report with suggestions for improvement.
GitLab and DingTalk
At my current company, I’ve built customizations on top of GitLab. When there’s a code review task, notifications can be sent via email or DingTalk to the relevant people.
If DingTalk’s task API becomes available in the future, we could even manage our entire code review workflow through DingTalk.
Manual code review should only be performed after all continuous integration tasks have completed. This can greatly reduce our review workload while ensuring a certain level of code quality.
Company Support
From the company level, there should also be measures to encourage code review.
- Encourage employees to help review others’ code, and even include it in performance evaluations.
- Establish unified coding standards and code style, especially in controversial areas, to reduce conflicts caused by programmer preferences.
These are my recent thoughts on code review