PR/Code Review Best Practices
Tags: pullrequest, bestpractices, peerreview, codereview
Published: 2020-09-05 17:30:14

---
title: PR/Code Review Best Practices
published: true
description: List of PR/Code Review Best Practices
tags: pullrequest, bestpractices, peerreview, codereview
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/tg9r8z8ld0u7dhruqr2s.jpg
---
#### My Other lists
- [JavaScript/Node Best Practices](https://dev.to/nirajkvinit/javascript-node-best-practices-2i4d)
- [Software Development General Best Practices](https://dev.to/nirajkvinit/software-development-general-best-practices-1747)
- [Defensive Programming / Application Security Best Practices](https://dev.to/nirajkvinit/application-security-best-practices-defensive-programming-3o87)

---------------------------

I have collected some points and created this list for PR and Code reviews. I intend to refer to this post frequently to help me become a better reviewer.

**Organization**
1. Organizations with good code reviews ensure that all engineers take part in the code review process
2. Good code reviews use the same quality bar and approach for everyone, regardless of their job title, level, or when they joined the company.
3. Better code reviews pay additional attention to making the first few reviews for new joiners a great experience. Reviewers are empathetic to the fact that the recent joiner might not be aware of all the coding guidelines and might be unfamiliar with parts of the code. Provide relevant documentation (guidelines, style guides, etc) to help engineer improve their code.
4. Ensure no code makes it to production without a code review
5. PR and reviews should be time-bound. Ensure that PRs get reviewed, approved/rejected within a scrum cycle to avoid stale code
6. Foster a good code review culture in which finding defects is viewed positively, Give respectful and constructive feedback

**Reviewers**
1. Prioritize Review Over Coding
2. Integrate code review into your daily routine
3. Review at least part of the code, even if you can't do all of it
4. Review fewer than 400 lines of code at a time
5. Take your time while reviewing someone else's code, do not depend on others to catch errors
6. Do not bunch PRs for review. Instead, scatter reviews tasks throughout the working hours
7. Ensure the PRs comes with tests
8. Build and Test — Before Code Review
9. Ensure external documents if any (API, user manual, etc.) are updated
10. Give Feedback That Helps (Not Hurts)
11. Create and follow a code-review checklist. 
12. While reviewing code, be mindful about the following:
 - Security best practices
 - Manageability (Readability, structure, style) 
 - Architecture
 - Maintainability (Logic, Test Coverage)
 - Correctness (Functionality)
 - Invalid input/states
 - Usability (Performance)
 - Reusability
 - Object-Oriented Analysis and Design (OOAD) Principles
13. Verify that the defects if any -are actually fixed
14. PR Rejections must always include a better explanation for why the PR got rejected

**Author/Reviewee**
1. There are various git workflow, get yourself acquainted with different git workflows: https://www.atlassian.com/git/tutorials/comparing-workflows
2. You should annotate PRs with self-explaining comments before the review
3. Create Small Change Lists, Change Lists Should Be Complete on Their Own
4. Never self-approve a PR, always ask your peers for approval after code review
5. Before opening a PR, make sure you squash all your commits into one single commit using git rebase (squash). Instead of having 50 commits that describe 1 feature implementation, there must be one commit that describes everything that has been done so far.
6. Prior to making PRs always check to see you have merged the most updated code from the master branch.
Update all affected tests and or create new tests for files you changed.
7. Do not push any code with runtime errors thrown by dependencies or source code. When one appears, you should fix that bug ASAP—even if everything else seems to be running ok. There’s a reason that error was thrown, so fix it and don’t leave it for someone else to worry about it.
8. Remove all unnecessary console logs prior to making a PR

**PR Checklist**
&#9744; Unit Test provided
&#9744; Deprecated code removed
&#9744; Syntax & Formatting is correct (Linting should help with this)
&#9744; Is the approach to the problem appropriate?
&#9744; Can anything be simplified?
&#9744; Is the code too specific to the product and needs generalization?
&#9744; Do forms need to sanitized
&#9744; Any obvious security flaws or potential holes
&#9744; Are the naming conventions appropriate?
&#9744; Are there enough comments inline with the code?
&#9744; Is there documentation needed?
&#9744; Is there anything included that should not be?
&#9744; Are all dependencies declared?
&#9744; Are there any code smells? https://blog.codinghorror.com/code-smells/



**NOTE**: If you want to update this list, please comment, I'll incorporate your changes.

**Ref.**
https://www.ibm.com/developerworks/rational/library/11-proven-practices-for-peer-review/index.html
https://www.michaelagreiler.com/code-review-best-practices/
https://ardalis.com/github-pull-request-checklist/
https://gist.github.com/sherakama/0ba17601381e3adbe0cad566ad4d80a5