From 5666305d6fe6a62eec2f0f91253057c49df08ab1 Mon Sep 17 00:00:00 2001 From: kevindiu Date: Tue, 11 Aug 2020 14:46:12 +0900 Subject: [PATCH] fix comments --- docs/contributing/coding-style.md | 33 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/docs/contributing/coding-style.md b/docs/contributing/coding-style.md index 5b6d1e9797..fd54e2d35d 100644 --- a/docs/contributing/coding-style.md +++ b/docs/contributing/coding-style.md @@ -221,7 +221,7 @@ ErrInvalidCacherType = New("invalid cacher type") ### Methods -The method name should be named as: +In this section, rules also apply to the `function` (without receiver). The method name should be named as: - Use MixedCaps. @@ -236,6 +236,7 @@ func (s *something) some_method() {} func (s *something) someMethod() {} ``` +- Avoid using long function name. - Do not use short form unless the function name is too long. ```go @@ -272,7 +273,7 @@ So please delete the unused variable. Generally, the unused variable should be reported during compilation, but in some cases, the compiler may not report an error. This is an example of the unused variable declaration that does not cause a compilation error. -```golang +```go // In this case, this example are not using `port` field, but dose not cause a compilation error. // So please delete `port` field of `server`. @@ -302,7 +303,7 @@ Please use [internal/errgroup](https://github.com/vdaas/vald/blob/master/interna All functions return `error` if the function can fail. It is very important to ensure the error checking is performed. To reduce human mistake that missing the error checking, please check the error using the following style: -```golang +```go // good if err := fn(); err != nil { // handle error @@ -311,7 +312,7 @@ if err := fn(); err != nil { Instead of this style. -```golang +```go // bad err := fn() if err != nil { @@ -321,7 +322,7 @@ if err != nil { If you need the value outside the if statement, please use the following style: -```golang +```go // good conn, err := net.Dial("tcp", "localhost:80") if err != nil { @@ -333,7 +334,7 @@ if err != nil { Instead of this style. -```golang +```go // bad if conn, err := net.Dial("tcp", "localhost:80"); err != nil { // handle error @@ -612,7 +613,7 @@ We do not suggest to modify the generated code other than the `tests` variable, For example, Vald uses [glg](https://github.com/kpango/glg) library for logging by default, if the logger is not initialized before the test, the nil pointer error may be thrown during the test is running. You may need to implement `init()` function like: - ```golang + ```go func init() { log.Init() } @@ -626,7 +627,7 @@ We do not suggest to modify the generated code other than the `tests` variable, Sometimes you may want to skip the detection, for example, Vald uses [fastime](https://github.com/kpango/fastime) library but the internal Goroutine is not closed due to the needs of the library. To skip the goleak detection we need to create the following variable to store the ignore function. - ```golang + ```go var ( // Goroutine leak is detected by `fastime`, but it should be ignored in the test because it is an external package. goleakIgnoreOptions = []goleak.Option{ @@ -637,7 +638,7 @@ We do not suggest to modify the generated code other than the `tests` variable, And modify the generated test code. - ```golang + ```go // before for _, test := range tests { t.Run(test.name, func(tt *testing.T) { @@ -657,7 +658,7 @@ We do not suggest to modify the generated code other than the `tests` variable, For example: - ```golang + ```go for _, test := range tests { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) @@ -678,11 +679,11 @@ We do not suggest to modify the generated code other than the `tests` variable, 1. Unused fields - By default, the template provides `fields` structure to initialize object of the test target. + By default, the template provides `fields` structure to initialize object of the test target. But in some cases, not all `fields` are needed, so please delete the unnecessary fields. For example, the following struct and the corresponding function: - - ```golang + + ```go type server struct { addr string port int @@ -693,7 +694,8 @@ We do not suggest to modify the generated code other than the `tests` variable, ``` And the generated test code is: - ```golang + + ```go func Test_server_Addr(t *testing.T) { type fields struct { addr string @@ -704,7 +706,8 @@ We do not suggest to modify the generated code other than the `tests` variable, ``` Since the `port` variable is not used in this test case, you can delete the `port` definition in the test case. - ```golang + + ```go func Test_server_Addr(t *testing.T) { type fields struct { addr string