From d1571badafbfc28e579d29465df78c552fd76d9d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 12 Dec 2018 19:10:04 -0800 Subject: [PATCH] docs: add section in contribution guidelines for unique lnd code style --- docs/code_contribution_guidelines.md | 91 ++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/docs/code_contribution_guidelines.md b/docs/code_contribution_guidelines.md index 445d61e0..90e2bb5e 100644 --- a/docs/code_contribution_guidelines.md +++ b/docs/code_contribution_guidelines.md @@ -10,6 +10,7 @@ 4.5. [Ideal Git Commit Structure](#IdealGitCommitStructure)
4.6. [Code Spacing](#CodeSpacing)
4.7. [Protobuf Compilation](#Protobuf)
+4.8. [Additional Style Constraints On Top of gofmt](ExtraGoFmtStyle)
5. [Code Approval Process](#CodeApproval)
5.1. [Code Review](#CodeReview)
5.2. [Rework Code (if needed)](#CodeRework)
@@ -380,6 +381,64 @@ Functions should _not_ just be laid out as a bare contiguous block of code. return witness ``` +Additionally, we favor spacing between stanzas within syntax like: switch case +statements and select statements. + +**WRONG** +```go + switch { + case a: + + case b: + + case c: + + case d: + + default: + + } +``` +**RIGHT** +```go + switch { + // Brief comment detailing instances of this case (repeat below). + case a: + + + case b: + + + case c: + + + case d: + + + default: + + } +``` + +If one is forced to wrap lines of function arguments that exceed the 80 +character limit, then a new line should be inserted before the first stanza in +the comment body. +**WRONG** +```go + func foo(a, b, c, + d, e) error { + var a int + } +``` +**RIGHT** +```go + func foo(a, b, c, + d, e) error { + + var a int + } +``` + #### 4.7. Protobuf Compilation @@ -415,6 +474,38 @@ Notice how the `json_name` field option corresponds with the name of the field itself, and uses a `snake_case` style of name formatting. All added or modified `proto` fields should adhere to the format above. + + +#### 4.8. Additional Style Constraints On Top of `gofmt` + +Before a PR is submitted, the proposer should ensure that the file passes the +set of linting scripts run by `make lint`. These include `gofmt`. In addition +to `gofmt` we've opted to enforce the following style guidelines. + + * ALL columns (on a best effort basis) should be wrapped to 80 line columns. + Editors should be set to treat a tab as 4 spaces. + * When wrapping a line that contains a function call as the unwrapped line + exceeds the column limit, the close paren should be placed on its own + line. Additionally, all arguments should begin in a new line after the + open paren. + + **WRONG** + ```go + value, err := bar(a, + a, b, c) + ``` + + **RIGHT** + ```go + value, err := bar( + a, a, b, c, + ) + ``` + +Note that the above guidelines don't apply to log messages. For log messages, +committers should attempt to minimize the of number lines utilized, while still +adhering to the 80-character column limit. + ### 5. Code Approval Process