Skip to content

Commit 825781d

Browse files
authored
Merge pull request #1705 from avorima/add-makezero-linter
Add makezero linter
2 parents d1525cc + 6c4011d commit 825781d

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

.golangci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# https://golangci-lint.run/usage/configuration/
22
linters:
33
enable:
4-
- misspell
4+
- makezero
5+
- misspell

errors.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ func (m *multiError) Error() string {
4141
// Errors returns a copy of the errors slice
4242
func (m *multiError) Errors() []error {
4343
errs := make([]error, len(*m))
44-
for _, err := range *m {
45-
errs = append(errs, err)
46-
}
44+
copy(errs, *m)
4745
return errs
4846
}
4947

errors_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,13 @@ func TestHandleExitCoder_MultiErrorWithFormat(t *testing.T) {
159159
expect(t, called, true)
160160
expect(t, ErrWriter.(*bytes.Buffer).String(), "This the format: err1\nThis the format: err2\n")
161161
}
162+
163+
func TestMultiErrorErrorsCopy(t *testing.T) {
164+
errList := []error{
165+
errors.New("foo"),
166+
errors.New("bar"),
167+
errors.New("baz"),
168+
}
169+
me := newMultiError(errList...)
170+
expect(t, errList, me.Errors())
171+
}

0 commit comments

Comments
 (0)