Skip to content

Commit

Permalink
refactor: make golangci-lint v1.52.2 happy
Browse files Browse the repository at this point in the history
Except for stupid report about "unused-parameter".

Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
  • Loading branch information
maxatome committed Apr 21, 2023
1 parent bca8640 commit a577f69
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 81 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ jobs:
if: matrix.full-tests
run: |
curl -sL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh |
sh -s -- -b $HOME/go/bin v1.51.0
sh -s -- -b $HOME/go/bin v1.52.2
echo $PATH
$HOME/go/bin/golangci-lint run --max-issues-per-linter 0 \
--max-same-issues 0 \
--exclude="unused-parameter: parameter '[^']+' seems to be unused, consider removing or renaming it as _" \
-E asciicheck \
-E bidichk \
-E durationcheck \
Expand Down
4 changes: 2 additions & 2 deletions helpers/tdsuite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func isTest(name string) bool {
if len(name) == 4 { // "Test" is ok
return true
}
rune, _ := utf8.DecodeRuneInString(name[4:])
return !unicode.IsLower(rune)
r, _ := utf8.DecodeRuneInString(name[4:])
return !unicode.IsLower(r)
}

// shouldContinue returns true if the tests suite should continue
Expand Down
62 changes: 31 additions & 31 deletions internal/ctxerr/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func (c *Context) InitErrors() {
}

// ResetErrors returns a new [Context] without any Error set.
func (c Context) ResetErrors() (new Context) {
new = c
new.InitErrors()
func (c Context) ResetErrors() (newc Context) {
newc = c
newc.InitErrors()
return
}

Expand Down Expand Up @@ -130,60 +130,60 @@ func (c Context) CannotCompareError() *Error {
}

// AddCustomLevel creates a new [Context] from current one plus pathAdd.
func (c Context) AddCustomLevel(pathAdd string) (new Context) {
new = c
new.Path = new.Path.AddCustomLevel(pathAdd)
new.Depth++
func (c Context) AddCustomLevel(pathAdd string) (newc Context) {
newc = c
newc.Path = newc.Path.AddCustomLevel(pathAdd)
newc.Depth++
return
}

// AddField creates a new [Context] from current one plus "." + field.
func (c Context) AddField(field string) (new Context) {
new = c
new.Path = new.Path.AddField(field)
new.Depth++
func (c Context) AddField(field string) (newc Context) {
newc = c
newc.Path = newc.Path.AddField(field)
newc.Depth++
return
}

// AddArrayIndex creates a new [Context] from current one plus an array
// dereference for index-th item.
func (c Context) AddArrayIndex(index int) (new Context) {
new = c
new.Path = new.Path.AddArrayIndex(index)
new.Depth++
func (c Context) AddArrayIndex(index int) (newc Context) {
newc = c
newc.Path = newc.Path.AddArrayIndex(index)
newc.Depth++
return
}

// AddMapKey creates a new [Context] from current one plus a map
// dereference for key key.
func (c Context) AddMapKey(key any) (new Context) {
new = c
new.Path = new.Path.AddMapKey(key)
new.Depth++
func (c Context) AddMapKey(key any) (newc Context) {
newc = c
newc.Path = newc.Path.AddMapKey(key)
newc.Depth++
return
}

// AddPtr creates a new [Context] from current one plus a pointer dereference.
func (c Context) AddPtr(num int) (new Context) {
new = c
new.Path = new.Path.AddPtr(num)
new.Depth++
func (c Context) AddPtr(num int) (newc Context) {
newc = c
newc.Path = newc.Path.AddPtr(num)
newc.Depth++
return
}

// AddFunctionCall creates a new [Context] from current one inside a
// function call.
func (c Context) AddFunctionCall(fn string) (new Context) {
new = c
new.Path = new.Path.AddFunctionCall(fn)
new.Depth++
func (c Context) AddFunctionCall(fn string) (newc Context) {
newc = c
newc.Path = newc.Path.AddFunctionCall(fn)
newc.Depth++
return
}

// ResetPath creates a new [Context] from current one but reinitializing Path.
func (c Context) ResetPath(newRoot string) (new Context) {
new = c
new.Path = NewPath(newRoot)
new.Depth++
func (c Context) ResetPath(newRoot string) (newc Context) {
newc = c
newc.Path = NewPath(newRoot)
newc.Depth++
return
}
6 changes: 3 additions & 3 deletions internal/ctxerr/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func TestContext(t *testing.T) {

*ctx.Errors = append(*ctx.Errors, &ctxerr.Error{})

new := ctx.ResetErrors()
if new.Errors == nil {
newc := ctx.ResetErrors()
if newc.Errors == nil {
t.Errorf("after ResetErrors, new Errors is nil for MaxErrors %d",
maxErrors)
continue
}
if len(*new.Errors) > 0 {
if len(*newc.Errors) > 0 {
t.Errorf("after ResetErrors, new Errors is not empty for MaxErrors %d",
maxErrors)
}
Expand Down
28 changes: 14 additions & 14 deletions internal/ctxerr/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func (p Path) Equal(o Path) bool {
}

func (p Path) addLevel(level pathLevel) Path {
new := make(Path, len(p), len(p)+1)
copy(new, p)
return append(new, level)
np := make(Path, len(p), len(p)+1)
copy(np, p)
return append(np, level)
}

// Copy returns a new [Path], exact but independent copy of p.
Expand All @@ -73,9 +73,9 @@ func (p Path) Copy() Path {
return nil
}

new := make(Path, len(p))
copy(new, p)
return new
np := make(Path, len(p))
copy(np, p)
return np
}

// AddField adds a level corresponding to a struct field.
Expand All @@ -84,16 +84,16 @@ func (p Path) AddField(field string) Path {
return nil
}

new := p.addLevel(pathLevel{
np := p.addLevel(pathLevel{
Kind: levelStruct,
Content: field,
})

if len(new) > 1 && new[len(new)-2].Pointers > 0 {
new[len(new)-2].Pointers--
if len(np) > 1 && np[len(np)-2].Pointers > 0 {
np[len(np)-2].Pointers--
}

return new
return np
}

// AddArrayIndex adds a level corresponding to an array index.
Expand Down Expand Up @@ -126,10 +126,10 @@ func (p Path) AddPtr(num int) Path {
return nil
}

new := p.Copy()
// Do not check len(new) > 0, as it should
new[len(new)-1].Pointers += num
return new
np := p.Copy()
// Do not check len(np) > 0, as it should
np[len(np)-1].Pointers += num
return np
}

// AddFunctionCall adds a level corresponding to a function call.
Expand Down
6 changes: 3 additions & 3 deletions internal/json/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,10 @@ func (j *json) parseNumber() (float64, bool) {
f, _ = bf.Float64()
}
} else { // numInt and/or numGoExt
var int int64
int, err = strconv.ParseInt(s, 0, 64)
var i64 int64
i64, err = strconv.ParseInt(s, 0, 64)
if err == nil {
f = float64(int)
f = float64(i64)
}
}

Expand Down
48 changes: 24 additions & 24 deletions td/t_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ func AssertRequire(t testing.TB, config ...ContextConfig) (assert, require *T) {
//
// If "" is passed the name is set to "DATA", the default value.
func (t *T) RootName(rootName string) *T {
new := *t
nt := *t
if rootName == "" {
rootName = contextDefaultRootName
}
new.Config.RootName = rootName
return &new
nt.Config.RootName = rootName
return &nt
}

// FailureIsFatal allows to choose whether t.TB.Fatal() or
Expand Down Expand Up @@ -285,9 +285,9 @@ func (t *T) RootName(rootName string) *T {
//
// See also [T.Assert] and [T.Require].
func (t *T) FailureIsFatal(enable ...bool) *T {
new := *t
new.Config.FailureIsFatal = len(enable) == 0 || enable[0]
return &new
nt := *t
nt.Config.FailureIsFatal = len(enable) == 0 || enable[0]
return &nt
}

// Assert returns a new [*T] instance inheriting the t config but with
Expand Down Expand Up @@ -348,17 +348,17 @@ func (t *T) Require() *T {
func (t *T) UseEqual(types ...any) *T {
// special case: UseEqual()
if len(types) == 0 {
new := *t
new.Config.UseEqual = true
return &new
nt := *t
nt.Config.UseEqual = true
return &nt
}

// special cases: UseEqual(true) or UseEqual(false)
if len(types) == 1 {
if ignore, ok := types[0].(bool); ok {
new := *t
new.Config.UseEqual = ignore
return &new
nt := *t
nt.Config.UseEqual = ignore
return &nt
}
}

Expand All @@ -385,9 +385,9 @@ func (t *T) UseEqual(types ...any) *T {
//
// Note that t.BeLax() acts as t.BeLax(true).
func (t *T) BeLax(enable ...bool) *T {
new := *t
new.Config.BeLax = len(enable) == 0 || enable[0]
return &new
nt := *t
nt.Config.BeLax = len(enable) == 0 || enable[0]
return &nt
}

// IgnoreUnexported tells go-testdeep to ignore unexported fields of
Expand All @@ -410,17 +410,17 @@ func (t *T) BeLax(enable ...bool) *T {
func (t *T) IgnoreUnexported(types ...any) *T {
// special case: IgnoreUnexported()
if len(types) == 0 {
new := *t
new.Config.IgnoreUnexported = true
return &new
nt := *t
nt.Config.IgnoreUnexported = true
return &nt
}

// special cases: IgnoreUnexported(true) or IgnoreUnexported(false)
if len(types) == 1 {
if ignore, ok := types[0].(bool); ok {
new := *t
new.Config.IgnoreUnexported = ignore
return &new
nt := *t
nt.Config.IgnoreUnexported = ignore
return &nt
}
}

Expand All @@ -445,9 +445,9 @@ func (t *T) IgnoreUnexported(types ...any) *T {
//
// Note that t.TestDeepInGotOK() acts as t.TestDeepInGotOK(true).
func (t *T) TestDeepInGotOK(enable ...bool) *T {
new := *t
new.Config.TestDeepInGotOK = len(enable) == 0 || enable[0]
return &new
nt := *t
nt.Config.TestDeepInGotOK = len(enable) == 0 || enable[0]
return &nt
}

// Cmp is mostly a shortcut for:
Expand Down
6 changes: 3 additions & 3 deletions td/td_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ func canonStructField(name string) string {

// Overwrite a field
if strings.HasPrefix(name, ">") {
new := strings.TrimSpace(name[1:])
if 1+len(new) == len(name) {
nn := strings.TrimSpace(name[1:])
if 1+len(nn) == len(name) {
return name // already canonicalized
}
return ">" + new
return ">" + nn
}

// Matcher
Expand Down

0 comments on commit a577f69

Please sign in to comment.