Turn your code review comments on GitLab into linter rules

Turn your code review comments on GitLab into linter rules

Developers who practice code review sometimes feel lassitude and frustration when they repeat the same concepts and best practices in their comments.

Code review is also about educating developers, so this observation is quite natural and part of the process.

Still, there's a gap to fill to optimize the overall code review and knowledge sharing process within Tech teams. In this post, we suggest the following approach:

  • If you write a code review comment regarding a best practice for the project, turn it into a shared knowledge for your team
  • If your team agrees with your suggestion, try to make it recognizable using a regular expression

Let's see how Promyze can be used for that purpose.

1. Create a best practice from a code review comment

Promyze comes with Web browsers plugins available from the Marketplace of extensions. Once you've set up your account on Promyze, get your API Key and paste it into the plugin settings.

The plugin will enrich your experience on Pull/Merge requests page on GitLab, GitHub, Azure DevOps, and Bitbucket.

In this example below, we're on GitLab and formulate a comment about using moment framework directly in an Angular controller. Assume that in the context of this project, we should rather use a module DateFormatter designed for that purpose.

As you can see, a button "Identify a Promyze practice" is available on the right-bottom of the comment section. Click on it to create a best practice in Promyze.

Create a best practice from code review comment

2. Collective validation and configuration for automatic detection

Promyze comes with the concept of Craft Workshop, which are technical retrospectives dedicated to the continuous improvement of our best coding practices. The idea is to review each contribution (like the one we made in the first step) from all developers in the team. The session will last between 30 minutes and 1 hour and will happen regularly (once per sprint, for instance).

Thanks to the screen below, I'll explain to my team why I think this code could be improved if it rather calls the DateFormatter service. I want to make it a best practice for our knowledge base. Assume that after a few minutes of talking, we agree and decide to validate the practice. After that, we can write a regular expression to detect when this practice is not applied.

Set regular expressions for rule

Here, if we detect "moment(" in a file ending with ".controller.js", this is likely a bad smell.

Quite simple right?

3. Get suggestions in VS Code

Once it's configured, every developer in your team will get a notification in their favorite IDE. Promyze is compatible with VS Code, Visual Studio, the JetBrains suite, and Eclipse.

You can see the orange rockets displayed on the source code using the moment framework.

VS Code - Linter rule

What are the benefits?

  • Save time during your next code reviews
  • Ensure everyone in the team understood the practice
  • Get early feedback while coding to make sure best practices are followed

Want to give it a try? Get started on Promyze!