Skip to content

Commit

Permalink
Merge pull request #1705 from avorima/add-makezero-linter
Browse files Browse the repository at this point in the history
Add makezero linter
  • Loading branch information
dearchap committed Mar 18, 2023
2 parents d1525cc + 6c4011d commit 825781d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# https://golangci-lint.run/usage/configuration/
linters:
enable:
- misspell
- makezero
- misspell
4 changes: 1 addition & 3 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ func (m *multiError) Error() string {
// Errors returns a copy of the errors slice
func (m *multiError) Errors() []error {
errs := make([]error, len(*m))
for _, err := range *m {
errs = append(errs, err)
}
copy(errs, *m)
return errs
}

Expand Down
10 changes: 10 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,13 @@ func TestHandleExitCoder_MultiErrorWithFormat(t *testing.T) {
expect(t, called, true)
expect(t, ErrWriter.(*bytes.Buffer).String(), "This the format: err1\nThis the format: err2\n")
}

func TestMultiErrorErrorsCopy(t *testing.T) {
errList := []error{
errors.New("foo"),
errors.New("bar"),
errors.New("baz"),
}
me := newMultiError(errList...)
expect(t, errList, me.Errors())
}

0 comments on commit 825781d

Please sign in to comment.