Updated code style
This commit is contained in:
parent
7ced59128f
commit
ae28e40477
@ -4,7 +4,7 @@ This document is only meant to teach you the code style used in this project and
|
||||
|
||||
## Tabs vs Spaces
|
||||
|
||||
Use **tabs to indent** and **spaces for alignment** only:
|
||||
Use tabs for indentation and spaces for alignment:
|
||||
|
||||
```go
|
||||
type AnimeTitle struct {
|
||||
@ -61,7 +61,7 @@ func() {
|
||||
|
||||
Variables are written in `camelCase` and should clearly state what they contain, preferably with no abbreviations. Common short names like `id` and `url` are allowed.
|
||||
|
||||
Iterator variables in loops are an exception to this rule and can be 1-letter, non-significant variable names, usually `i` and `j`.
|
||||
Iterator variables in loops are an exception to this rule and can be 1-letter, non-significant variable names, usually `i` and `j`. `index` is also quite common.
|
||||
|
||||
## Early returns
|
||||
|
||||
@ -89,7 +89,11 @@ func DoSomething(a string, b string) {
|
||||
}
|
||||
```
|
||||
|
||||
## Private fields at the end
|
||||
## Types at the top
|
||||
|
||||
`type` definitions should be placed at the very top of your files. Variables, constants, interface implementation assertions and the `package` statement are the only constructs allowed above `type` definitions.
|
||||
|
||||
## Private fields at the end of a struct
|
||||
|
||||
This is not an absolute rule but try to keep private fields at the end of a struct.
|
||||
|
||||
@ -105,4 +109,12 @@ type MyType struct {
|
||||
|
||||
## Package names
|
||||
|
||||
Package names should be short lowercase identifiers and tests should be written using the black box pattern. Black box testing can be enabled by adding the suffix `_test` to the package names in `*_test.go` files. It will enable you to test your library like it would be used by another developer, without internal access to private variables.
|
||||
Package names should be short lowercase identifiers and tests should be written using the black box pattern. Black box testing can be enabled by adding the suffix `_test` to the package names in `*_test.go` files. It will enable you to test your library like it would be used by another developer, without internal access to private variables.
|
||||
|
||||
## Use gofmt
|
||||
|
||||
Your IDE should automatically call `gofmt` to format your code every time you save the file.
|
||||
|
||||
## Code editor
|
||||
|
||||
It is highly recommended to use [Visual Studio Code](https://code.visualstudio.com/) as it has an excellent Go plugin and the repository includes workspace settings to get you started quickly.
|
Loading…
Reference in New Issue
Block a user