Skip to content

Commit 2b34cf9

Browse files
committed
docs: document formatting for slice definitions
Adds more clarity around when to use what style for using inline slice definitions.
1 parent b0cba7d commit 2b34cf9

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/development_guidelines.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,65 @@ func foo(a, b, c,
448448
}
449449
```
450450
451+
### Inline slice definitions
452+
453+
In Go a list of slices can be initialized with values directly, using curly
454+
braces. Whenever possible, the more verbose/indented style should be used for
455+
better readability and easier git diff handling. Because that results in more
456+
levels of code indentation, the more compact version is allowed in situations
457+
where the remaining space would otherwise be too restricted, resulting in too
458+
long lines (or excessive use of the `// nolint: ll` directive).
459+
460+
**ACCEPTABLE**
461+
```go
462+
testCases := []testCase{{
463+
name: "spend exactly all",
464+
coins: []wallet.Coin{{
465+
TxOut: wire.TxOut{
466+
PkScript: p2wkhScript,
467+
Value: 1 * btcutil.SatoshiPerBitcoin,
468+
},
469+
}},
470+
}, {
471+
name: "spend more",
472+
coins: []wallet.Coin{{
473+
TxOut: wire.TxOut{
474+
PkScript: p2wkhScript,
475+
Value: 1 * btcutil.SatoshiPerBitcoin,
476+
},
477+
}},
478+
}}
479+
```
480+
481+
**PREFERRED**
482+
```go
483+
coin := btcutil.SatoshiPerBitcoin
484+
testCases := []testCase{
485+
{
486+
name: "spend exactly all",
487+
coins: []wallet.Coin{
488+
{
489+
TxOut: wire.TxOut{
490+
PkScript: p2wkhScript,
491+
Value: 1 * coin,
492+
},
493+
},
494+
},
495+
},
496+
{
497+
name: "spend more",
498+
coins: []wallet.Coin{
499+
{
500+
TxOut: wire.TxOut{
501+
PkScript: p2wkhScript,
502+
Value: 1 * coin,
503+
},
504+
},
505+
},
506+
},
507+
}
508+
```
509+
451510
## Recommended settings for your editor
452511

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

0 commit comments

Comments
 (0)