Skip to content

Commit 14418ec

Browse files
committed
feat: add innertypealias linter
Implements golangci#3490.
1 parent abe878d commit 14418ec

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed

.golangci.reference.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,7 @@ linters:
20472047
- ifshort
20482048
- importas
20492049
- ineffassign
2050+
- innertypealias
20502051
- interfacebloat
20512052
- interfacer
20522053
- ireturn
@@ -2157,6 +2158,7 @@ linters:
21572158
- ifshort
21582159
- importas
21592160
- ineffassign
2161+
- innertypealias
21602162
- interfacebloat
21612163
- interfacer
21622164
- ireturn

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ require (
4444
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
4545
github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8
4646
github.com/gostaticanalysis/forcetypeassert v0.1.0
47+
github.com/gostaticanalysis/innertypealias v0.1.1
4748
github.com/gostaticanalysis/nilerr v0.1.1
4849
github.com/hashicorp/go-multierror v1.1.1
4950
github.com/hashicorp/go-version v1.6.0

go.sum

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/innertypealias.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package golinters
2+
3+
import (
4+
"github.com/gostaticanalysis/innertypealias"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
)
9+
10+
func NewInnerTypeAlias() *goanalysis.Linter {
11+
a := innertypealias.Analyzer
12+
13+
return goanalysis.NewLinter(
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
17+
nil,
18+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
19+
}

pkg/lint/lintersdb/manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
587587
WithPresets(linter.PresetUnused).
588588
WithURL("https://github.com/gordonklaus/ineffassign"),
589589

590+
linter.NewConfig(golinters.NewInnerTypeAlias()).
591+
WithSince("v1.51.0").
592+
WithPresets(linter.PresetBugs).
593+
WithURL("https://github.com/gostaticanalysis/innertypealias"),
594+
590595
linter.NewConfig(golinters.NewInterfaceBloat(interfaceBloatCfg)).
591596
WithSince("v1.49.0").
592597
WithPresets(linter.PresetStyle).

test/testdata/innertypealias.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//golangcitest:args -Einnertypealias
2+
package testdata
3+
4+
type T int
5+
type t int
6+
7+
type A = T // want "A is a alias for T but it is exported type"
8+
type B = t // OK
9+
10+
func _() {
11+
type D = T // OK
12+
}
13+
14+
type E T // OK
15+
type F t // OK
16+
type g = t // OK
17+
18+
type H = T // OK - it is used as an embedded field
19+
type _ struct{ H }
20+
21+
type I = T // OK - it is used as an embedded field
22+
func _() {
23+
type _ struct{ I }
24+
}
25+
26+
type _ = T // OK

0 commit comments

Comments
 (0)