Skip to content

chore: remove redundant typeparams for Go 1.17 #1331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions internal/typeparams/typeparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ import (
"go/ast"
)

// Enabled reports whether type parameters are enabled in the current build
// environment.
func Enabled() bool {
return enabled
}

// ReceiverType returns the named type of the method receiver, sans "*" and type
// parameters, or "invalid-type" if fn.Recv is ill formed.
func ReceiverType(fn *ast.FuncDecl) string {
e := fn.Recv.List[0].Type
if s, ok := e.(*ast.StarExpr); ok {
e = s.X
}
if enabled {
e = unpackIndexExpr(e)
}
e = unpackIndexExpr(e)
if id, ok := e.(*ast.Ident); ok {
return id.Name
}
return "invalid-type"
}

func unpackIndexExpr(e ast.Expr) ast.Expr {
switch e := e.(type) {
case *ast.IndexExpr:
return e.X
case *ast.IndexListExpr:
return e.X
}
return e
}
12 changes: 0 additions & 12 deletions internal/typeparams/typeparams_go117.go

This file was deleted.

20 changes: 0 additions & 20 deletions internal/typeparams/typeparams_go118.go

This file was deleted.

4 changes: 0 additions & 4 deletions test/receiver_naming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ package test
import (
"testing"

"github.com/mgechev/revive/internal/typeparams"
"github.com/mgechev/revive/lint"
"github.com/mgechev/revive/rule"
)

func TestReceiverNamingTypeParams(t *testing.T) {
if !typeparams.Enabled() {
t.Skip("type parameters are not enabled in the current build environment")
}
testRule(t, "receiver_naming_issue_669", &rule.ReceiverNamingRule{})
}

Expand Down