From 447088fa325ea9d21cceb3ca8845f398ac8dd64e Mon Sep 17 00:00:00 2001 From: "Iskander (Alex) Sharipov" Date: Thu, 28 Feb 2019 14:56:02 +0300 Subject: [PATCH] checkers: suggest buf.Reset() instead of buf.Truncate(0) (#811) Signed-off-by: Iskander Sharipov --- checkers/testdata/wrapperFunc/negative_tests.go | 5 +++++ checkers/testdata/wrapperFunc/positive_tests.go | 4 ++++ checkers/wrapperFunc_checker.go | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/checkers/testdata/wrapperFunc/negative_tests.go b/checkers/testdata/wrapperFunc/negative_tests.go index 314d3265b..7aa3b7e63 100644 --- a/checkers/testdata/wrapperFunc/negative_tests.go +++ b/checkers/testdata/wrapperFunc/negative_tests.go @@ -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") diff --git a/checkers/testdata/wrapperFunc/positive_tests.go b/checkers/testdata/wrapperFunc/positive_tests.go index c6547e02a..8c69fa527 100644 --- a/checkers/testdata/wrapperFunc/positive_tests.go +++ b/checkers/testdata/wrapperFunc/positive_tests.go @@ -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) diff --git a/checkers/wrapperFunc_checker.go b/checkers/wrapperFunc_checker.go index e2308ff4b..43c5aaa29 100644 --- a/checkers/wrapperFunc_checker.go +++ b/checkers/wrapperFunc_checker.go @@ -39,6 +39,10 @@ func init() { "sync.WaitGroup.Add => WaitGroup.Done": { {0, "-1"}, }, + + "bytes.Buffer.Truncate => Buffer.Reset": { + {0, "0"}, + }, } pkgPatterns := map[string][]arg{