Skip to content

Commit

Permalink
checkers: suggest buf.Reset() instead of buf.Truncate(0) (go-critic#811)
Browse files Browse the repository at this point in the history
Signed-off-by: Iskander Sharipov <[email protected]>
  • Loading branch information
quasilyte authored Feb 28, 2019
1 parent 94a6b5c commit 447088f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions checkers/testdata/wrapperFunc/negative_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
func appliedSuggestions(s string, b []byte) {
var wg sync.WaitGroup
wg.Done()
wg.Add(1)

var buf bytes.Buffer
buf.Reset()
buf.Truncate(1)

strings.ToTitle(s)
strings.ReplaceAll(s, "a", "b")
Expand Down
4 changes: 4 additions & 0 deletions checkers/testdata/wrapperFunc/positive_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func f(s string, b []byte) {
/*! use WaitGroup.Done method in `wg.Add(-1)` */
wg.Add(-1)

var buf bytes.Buffer
/*! use Buffer.Reset method in `buf.Truncate(0)` */
buf.Truncate(0)

/*! use strings.ToTitle method in `strings.Map(unicode.ToTitle, s)` */
strings.Map(unicode.ToTitle, s)

Expand Down
4 changes: 4 additions & 0 deletions checkers/wrapperFunc_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func init() {
"sync.WaitGroup.Add => WaitGroup.Done": {
{0, "-1"},
},

"bytes.Buffer.Truncate => Buffer.Reset": {
{0, "0"},
},
}

pkgPatterns := map[string][]arg{
Expand Down

0 comments on commit 447088f

Please sign in to comment.