-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
linters: add makezero and fix a related bug
Makezero is a linter to ensure that slices are not initialized with non-zero length. Since in Go, we most of the time use append on the slice, initializing it with non-zero length can tend to create a slice full of zero that will clobber the beginning of the slice. In the bug fixed here, we created a list with 300+ zeros and then append after them, only to skip the zero in the calling method. Usually we want to prealloc the slice with a capacity of len but a length of 0, i.e. replace make([]int, len(nums)) with make([]int, 0, len(nums)). See more info here https://github.com/ashanbrown/makezero. Signed-off-by: Mahe Tardy <[email protected]>
- Loading branch information
Showing
4 changed files
with
12 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ linters: | |
- staticcheck | ||
- unused | ||
- gosimple | ||
- makezero | ||
|
||
linters-settings: | ||
goheader: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters