Skip to content

Commit 04760a0

Browse files
Merge pull request #894 from lightninglabs/docs-lnd
Update lnd documentation
2 parents eaa5782 + 18f258f commit 04760a0

File tree

1 file changed

+73
-3
lines changed

1 file changed

+73
-3
lines changed

docs/lnd/development_guidelines.md

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,13 @@ value, err := bar(
230230
)
231231
```
232232
233-
As long as the visual symmetry of the opening and closing parentheses is
234-
preserved, arguments that would otherwise introduce a new level of indentation
235-
are allowed to be written in a more compact form.
233+
As long as the visual symmetry of the opening and closing parentheses (or curly
234+
braces) is preserved, arguments that would otherwise introduce a new level of
235+
indentation are allowed to be written in a more compact form.
236+
Visual symmetry here means that when two or more opening parentheses or curly
237+
braces are on the same line, then they must also be closed on the same line.
238+
And the closing line needs to have the same indentation level as the opening
239+
line.
236240
237241
Example with inline struct creation:
238242
@@ -254,6 +258,13 @@ Example with inline struct creation:
254258
})
255259
```
256260
261+
**WRONG**
262+
```go
263+
response, err := node.AddInvoice(ctx, &lnrpc.Invoice{
264+
Memo: "invoice",
265+
ValueMsat: int64(oneUnitMilliSat - 1)})
266+
```
267+
257268
Example with nested function call:
258269
259270
**ACCEPTABLE**:
@@ -448,6 +459,65 @@ func foo(a, b, c,
448459
}
449460
```
450461
462+
### Inline slice definitions
463+
464+
In Go a list of slices can be initialized with values directly, using curly
465+
braces. Whenever possible, the more verbose/indented style should be used for
466+
better readability and easier git diff handling. Because that results in more
467+
levels of code indentation, the more compact version is allowed in situations
468+
where the remaining space would otherwise be too restricted, resulting in too
469+
long lines (or excessive use of the `// nolint: ll` directive).
470+
471+
**ACCEPTABLE**
472+
```go
473+
testCases := []testCase{{
474+
name: "spend exactly all",
475+
coins: []wallet.Coin{{
476+
TxOut: wire.TxOut{
477+
PkScript: p2wkhScript,
478+
Value: 1 * btcutil.SatoshiPerBitcoin,
479+
},
480+
}},
481+
}, {
482+
name: "spend more",
483+
coins: []wallet.Coin{{
484+
TxOut: wire.TxOut{
485+
PkScript: p2wkhScript,
486+
Value: 1 * btcutil.SatoshiPerBitcoin,
487+
},
488+
}},
489+
}}
490+
```
491+
492+
**PREFERRED**
493+
```go
494+
coin := btcutil.SatoshiPerBitcoin
495+
testCases := []testCase{
496+
{
497+
name: "spend exactly all",
498+
coins: []wallet.Coin{
499+
{
500+
TxOut: wire.TxOut{
501+
PkScript: p2wkhScript,
502+
Value: 1 * coin,
503+
},
504+
},
505+
},
506+
},
507+
{
508+
name: "spend more",
509+
coins: []wallet.Coin{
510+
{
511+
TxOut: wire.TxOut{
512+
PkScript: p2wkhScript,
513+
Value: 1 * coin,
514+
},
515+
},
516+
},
517+
},
518+
}
519+
```
520+
451521
## Recommended settings for your editor
452522

453523
To make it easier to follow the rules outlined above, we recommend setting up

0 commit comments

Comments
 (0)