Skip to content
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

feat: add innertypealias linter #3525

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2047,6 +2047,7 @@ linters:
- ifshort
- importas
- ineffassign
- innertypealias
- interfacebloat
- interfacer
- ireturn
Expand Down Expand Up @@ -2157,6 +2158,7 @@ linters:
- ifshort
- importas
- ineffassign
- innertypealias
- interfacebloat
- interfacer
- ireturn
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ require (
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8
github.com/gostaticanalysis/forcetypeassert v0.1.0
github.com/gostaticanalysis/innertypealias v0.1.1
github.com/gostaticanalysis/nilerr v0.1.1
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-version v1.6.0
Expand Down
5 changes: 5 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pkg/golinters/innertypealias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package golinters

import (
"github.com/gostaticanalysis/innertypealias"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

func NewInnerTypeAlias() *goanalysis.Linter {
a := innertypealias.Analyzer

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
5 changes: 5 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetUnused).
WithURL("https://github.com/gordonklaus/ineffassign"),

linter.NewConfig(golinters.NewInnerTypeAlias()).
WithSince("v1.51.0").
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v1.55.0 at the moment

WithPresets(linter.PresetBugs).
WithURL("https://github.com/gostaticanalysis/innertypealias"),

linter.NewConfig(golinters.NewInterfaceBloat(interfaceBloatCfg)).
WithSince("v1.49.0").
WithPresets(linter.PresetStyle).
Expand Down
26 changes: 26 additions & 0 deletions test/testdata/innertypealias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//golangcitest:args -Einnertypealias
package testdata

type T int
type t int

type A = T // want "A is a alias for T but it is exported type"
type B = t // OK

func _() {
type D = T // OK
}

type E T // OK
type F t // OK
type g = t // OK

type H = T // OK - it is used as an embedded field
type _ struct{ H }

type I = T // OK - it is used as an embedded field
func _() {
type _ struct{ I }
}

type _ = T // OK