|
| 1 | +# Best Practices |
| 2 | + <sub>(a.k.a "Rules of thumb")</sub> |
| 3 | + |
| 4 | +## Provide motivation for the change |
| 5 | +Try to explain why this change will make the code better. For example, does |
| 6 | +it fix a bug, or is it a new feature, etc. This should be expressed in the |
| 7 | +commit messages as well as in the PR description. |
| 8 | + |
| 9 | +## Don't make _unnecessary_ code changes |
| 10 | +_Unnecessary_ code changes are changes made because of personal preference |
| 11 | +or style. For example, renaming of variables or functions, adding or removing |
| 12 | +white spaces, and reordering lines or whole code blocks. These sort of |
| 13 | +changes should have a good reason since otherwise they cause unnecessary |
| 14 | +[code churn][5] As part of the project's strategy we maintain multiple release |
| 15 | +lines, code churn might hinder back-porting changes to other lines. Also when |
| 16 | +you change a line, your name will come up in `git blame` and shadow the name of |
| 17 | +the previous author of that line. |
| 18 | + |
| 19 | +## Keep the change-set self contained but at a reasonable size |
| 20 | +Use good judgment when making a big change. If a reason does not come to mind |
| 21 | +but a very big change needs to be made, try to break it into smaller |
| 22 | +pieces (still as self-contained as possible), and cross-reference them, |
| 23 | +explicitly stating that they are dependent on each other. |
| 24 | + |
| 25 | +## Be aware of our style rules |
| 26 | +As part of accepting a PR the changes __must__ pass our linters. |
| 27 | +* For C++ we use Google's `cpplint` (with some adjustments) so following their |
| 28 | +[style-guide][1] should make your code |
| 29 | +compliant with our linter. |
| 30 | +* For JS we use this [rule-set][2] |
| 31 | +for ESLint plus some of [our own custom rules][3]. |
| 32 | +* For markdown we have a [style guide][4] |
| 33 | + |
| 34 | + [1]: https://github.com/google/styleguide "Google C++ style guide" |
| 35 | + [2]: https://github.com/nodejs/node/blob/master/.eslintrc.yaml "eslintrc" |
| 36 | + [3]: https://github.com/nodejs/node/tree/master/tools/eslint-rules "Our Rules" |
| 37 | + [4]: https://github.com/nodejs/node/blob/master/doc/STYLE_GUIDE.md "MD Style" |
| 38 | + [5]: https://blog.gitprime.com/why-code-churn-matters "Why churm matters" |
0 commit comments