Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kevindiu authored and actions-user committed Aug 11, 2020
1 parent 7fa246b commit 5666305
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions docs/contributing/coding-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand All @@ -311,7 +312,7 @@ if err := fn(); err != nil {

Instead of this style.

```golang
```go
// bad
err := fn()
if err != nil {
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
Expand All @@ -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{
Expand All @@ -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) {
Expand All @@ -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...)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5666305

Please sign in to comment.