You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/dev/go-style-guide.md
+7-20Lines changed: 7 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ b := f
50
50
51
51
## Linting
52
52
53
-
- Run `make lint-fix` to fix any linting errors.
53
+
- Run `make lint` to see linting errors and `make lint-fix` to fix many issues (some linters do not support auto-fix).
54
54
55
55
## Various
56
56
@@ -119,7 +119,7 @@ sdkerrors.Wrapf(
119
119
)
120
120
```
121
121
122
-
## Common Mistakes
122
+
## Common mistakes
123
123
124
124
This is a compilation of some of the common mistakes we see in the repo that should be avoided.
125
125
@@ -242,7 +242,7 @@ cases := []struct {
242
242
243
243
**Testing context**
244
244
245
-
Go 1.24 added a (testing.TB).Context() method. In tests, prefer using (testing.TB).Context() over context.Background() to provide the initial context.Context used by the test. Helper functions, environment or test double setup, and other functions called from the test function body that require a context should have one explicitly passed. [Referance](https://google.github.io/styleguide/go/decisions#contexts)
245
+
Go 1.24 added a (testing.TB).Context() method. In tests, prefer using (testing.TB).Context() over context.Background() to provide the initial context.Context used by the test. Helper functions, environment or test double setup, and other functions called from the test function body that require a context should have one explicitly passed. [Reference](https://google.github.io/styleguide/go/decisions#contexts)
246
246
247
247
---
248
248
**Error Logging**
@@ -253,7 +253,7 @@ If you return an error, it’s usually better not to log it yourself but rather
253
253
---
254
254
**Struct defined outside of the package**
255
255
256
-
Must have fields specified. [Referance](https://google.github.io/styleguide/go/decisions#field-names)
256
+
Must have fields specified. [Reference](https://google.github.io/styleguide/go/decisions#field-names)
If tabular test struct has more than two fields, consider explicitly naming them. If the test struct has one name and one error field, then we can allow upto three fields. If test struct has more fields, consider naming them when writing test cases.
276
276
@@ -342,26 +342,13 @@ testCases := []struct {
342
342
343
343
## Known Anti Patterns
344
344
345
-
It's strongly recommended [not to create a custom context](https://google.github.io/styleguide/go/decisions#custom-contexts). The cosmos sdk has it's own context that is passed around, and we should not try to work against that pattern to avoid confusion.
345
+
It's strongly recommended [not to create a custom context](https://google.github.io/styleguide/go/decisions#custom-contexts). The Cosmos SDK has it's own context that is passed around, and we should not try to work against that pattern to avoid confusion.
346
346
347
347
---
348
-
Test outputs should include the actual value that the function returned before printing the value that was expected. A standard format for printing test outputs is YourFunc(%v) = %v, want %v. Where you would write “actual” and “expected”, prefer using the words “got” and “want”, respectively. [Referance](https://google.github.io/styleguide/go/decisions#got-before-want)
348
+
Test outputs should include the actual value that the function returned before printing the value that was expected. A standard format for printing test outputs is YourFunc(%v) = %v, want %v. Where you would write “actual” and “expected”, prefer using the words “got” and “want”, respectively. [Reference](https://google.github.io/styleguide/go/decisions#got-before-want)
349
349
350
350
But testify has it other way around.
351
351
352
352
`Require.Equal(Expected, Actual)`
353
353
354
354
This is a known anti pattern that we allow as the testify package is used heavily in tests.
355
-
356
-
---
357
-
In tests suites we are embedding `testify/require` package for assertions. Since it's embedded and there are no name collision on `require` types methods, when calling, we should "promote" those methods to the suite. But throughout the repo we make explicit calls.
0 commit comments