From 03f5c0bb1b5405ee8339a2e7667c703dcdba0ce4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 May 2025 17:35:09 +0000 Subject: [PATCH 1/3] build(deps): bump github.com/uudashr/iface from 1.3.2 to 1.4.0 Bumps [github.com/uudashr/iface](https://github.com/uudashr/iface) from 1.3.2 to 1.4.0. - [Release notes](https://github.com/uudashr/iface/releases) - [Commits](https://github.com/uudashr/iface/compare/v1.3.2...v1.4.0) --- updated-dependencies: - dependency-name: github.com/uudashr/iface dependency-version: 1.4.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cdc954f4ad7b..03810322d94d 100644 --- a/go.mod +++ b/go.mod @@ -119,7 +119,7 @@ require ( github.com/ultraware/funlen v0.2.0 github.com/ultraware/whitespace v0.2.0 github.com/uudashr/gocognit v1.2.0 - github.com/uudashr/iface v1.3.2 + github.com/uudashr/iface v1.4.0 github.com/valyala/quicktemplate v1.8.0 github.com/xen0n/gosmopolitan v1.3.0 github.com/yagipy/maintidx v1.0.0 diff --git a/go.sum b/go.sum index 41ec9620c99d..2c8a91e0c1b7 100644 --- a/go.sum +++ b/go.sum @@ -598,8 +598,8 @@ github.com/ultraware/whitespace v0.2.0 h1:TYowo2m9Nfj1baEQBjuHzvMRbp19i+RCcRYrSW github.com/ultraware/whitespace v0.2.0/go.mod h1:XcP1RLD81eV4BW8UhQlpaR+SDc2givTvyI8a586WjW8= github.com/uudashr/gocognit v1.2.0 h1:3BU9aMr1xbhPlvJLSydKwdLN3tEUUrzPSSM8S4hDYRA= github.com/uudashr/gocognit v1.2.0/go.mod h1:k/DdKPI6XBZO1q7HgoV2juESI2/Ofj9AcHPZhBBdrTU= -github.com/uudashr/iface v1.3.2 h1:viQ7WtLvznR+Z4H+IP/fqhqPl3UF9Y2aj6wTeHF6X+Y= -github.com/uudashr/iface v1.3.2/go.mod h1:i/H4cfRMPe0izticV8Yz0g6/zcsh5xXlvthrdh1kqcY= +github.com/uudashr/iface v1.4.0 h1:ImZ+1oEJPXvjap7nK0md7gA9RRH7PMp4vliaLkJ2+cg= +github.com/uudashr/iface v1.4.0/go.mod h1:i/H4cfRMPe0izticV8Yz0g6/zcsh5xXlvthrdh1kqcY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/quicktemplate v1.8.0 h1:zU0tjbIqTRgKQzFY1L42zq0qR3eh4WoQQdIdqCysW5k= From 9596f2cea6b03dd7f96b64ee9f25a96f4619b1d4 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 20 May 2025 19:45:22 +0200 Subject: [PATCH 2/3] chore: update implementation --- pkg/golinters/iface/iface.go | 8 +- pkg/golinters/iface/testdata/iface_all.go | 8 +- pkg/golinters/iface/testdata/iface_cgo.go | 4 +- pkg/golinters/iface/testdata/iface_default.go | 4 +- .../iface/testdata/iface_identical.go | 4 +- pkg/golinters/iface/testdata/iface_opaque.go | 2 +- .../iface/testdata/iface_unexported.go | 84 +++++++++++++++++++ .../iface/testdata/iface_unexported.yml | 7 ++ pkg/golinters/iface/testdata/iface_unused.go | 6 +- 9 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 pkg/golinters/iface/testdata/iface_unexported.go create mode 100644 pkg/golinters/iface/testdata/iface_unexported.yml diff --git a/pkg/golinters/iface/iface.go b/pkg/golinters/iface/iface.go index a3c2816d4385..0a4a38abc931 100644 --- a/pkg/golinters/iface/iface.go +++ b/pkg/golinters/iface/iface.go @@ -5,6 +5,7 @@ import ( "github.com/uudashr/iface/identical" "github.com/uudashr/iface/opaque" + "github.com/uudashr/iface/unexported" "github.com/uudashr/iface/unused" "golang.org/x/tools/go/analysis" @@ -28,9 +29,10 @@ func New(settings *config.IfaceSettings) *goanalysis.Linter { func analyzersFromSettings(settings *config.IfaceSettings) []*analysis.Analyzer { allAnalyzers := map[string]*analysis.Analyzer{ - "identical": identical.Analyzer, - "unused": unused.Analyzer, - "opaque": opaque.Analyzer, + "identical": identical.Analyzer, + "unused": unused.Analyzer, + "opaque": opaque.Analyzer, + "unexported": unexported.Analyzer, } if settings == nil || len(settings.Enable) == 0 { diff --git a/pkg/golinters/iface/testdata/iface_all.go b/pkg/golinters/iface/testdata/iface_all.go index 3a6f912a1d2a..3dd95cdc24bf 100644 --- a/pkg/golinters/iface/testdata/iface_all.go +++ b/pkg/golinters/iface/testdata/iface_all.go @@ -6,11 +6,11 @@ import "fmt" // identical -type Pinger interface { // want "identical: interface Pinger contains identical methods or type constraints from another interface, causing redundancy" +type Pinger interface { // want "identical: interface 'Pinger' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } -type Healthcheck interface { // want "identical: interface Healthcheck contains identical methods or type constraints from another interface, causing redundancy" +type Healthcheck interface { // want "identical: interface 'Healthcheck' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } @@ -28,7 +28,7 @@ func (s server) Serve() error { return nil } -func NewServer(addr string) Server { // want "opaque: NewServer function return Server interface at the 1st result, abstract a single concrete implementation of \\*server" +func NewServer(addr string) Server { // want "opaque: 'NewServer' function return 'Server' interface at the 1st result, abstract a single concrete implementation of '\\*server'" return &server{addr: addr} } @@ -39,7 +39,7 @@ type User struct { Name string } -type UserRepository interface { // want "unused: interface UserRepository is declared but not used within the package" +type UserRepository interface { // want "unused: interface 'UserRepository' is declared but not used within the package" UserOf(id string) (*User, error) } diff --git a/pkg/golinters/iface/testdata/iface_cgo.go b/pkg/golinters/iface/testdata/iface_cgo.go index 43ef0216a036..16a9944854f0 100644 --- a/pkg/golinters/iface/testdata/iface_cgo.go +++ b/pkg/golinters/iface/testdata/iface_cgo.go @@ -24,11 +24,11 @@ func _() { // identical -type Pinger interface { // want "identical: interface Pinger contains identical methods or type constraints from another interface, causing redundancy" +type Pinger interface { // want "identical: interface 'Pinger' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } -type Healthcheck interface { // want "identical: interface Healthcheck contains identical methods or type constraints from another interface, causing redundancy" +type Healthcheck interface { // want "identical: interface 'Healthcheck' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } diff --git a/pkg/golinters/iface/testdata/iface_default.go b/pkg/golinters/iface/testdata/iface_default.go index 34117389738b..d0344b36c58f 100644 --- a/pkg/golinters/iface/testdata/iface_default.go +++ b/pkg/golinters/iface/testdata/iface_default.go @@ -5,11 +5,11 @@ import "fmt" // identical -type Pinger interface { // want "identical: interface Pinger contains identical methods or type constraints from another interface, causing redundancy" +type Pinger interface { // want "identical: interface 'Pinger' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } -type Healthcheck interface { // want "identical: interface Healthcheck contains identical methods or type constraints from another interface, causing redundancy" +type Healthcheck interface { // want "identical: interface 'Healthcheck' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } diff --git a/pkg/golinters/iface/testdata/iface_identical.go b/pkg/golinters/iface/testdata/iface_identical.go index 821aff7bd41e..c8a2de4818bb 100644 --- a/pkg/golinters/iface/testdata/iface_identical.go +++ b/pkg/golinters/iface/testdata/iface_identical.go @@ -6,11 +6,11 @@ import "fmt" // identical -type Pinger interface { // want "identical: interface Pinger contains identical methods or type constraints from another interface, causing redundancy" +type Pinger interface { // want "identical: interface 'Pinger' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } -type Healthcheck interface { // want "identical: interface Healthcheck contains identical methods or type constraints from another interface, causing redundancy" +type Healthcheck interface { // want "identical: interface 'Healthcheck' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } diff --git a/pkg/golinters/iface/testdata/iface_opaque.go b/pkg/golinters/iface/testdata/iface_opaque.go index b7ebeddc600f..8610a3fa05c1 100644 --- a/pkg/golinters/iface/testdata/iface_opaque.go +++ b/pkg/golinters/iface/testdata/iface_opaque.go @@ -28,7 +28,7 @@ func (s server) Serve() error { return nil } -func NewServer(addr string) Server { // want "opaque: NewServer function return Server interface at the 1st result, abstract a single concrete implementation of \\*server" +func NewServer(addr string) Server { // want "opaque: 'NewServer' function return 'Server' interface at the 1st result, abstract a single concrete implementation of '\\*server'" return &server{addr: addr} } diff --git a/pkg/golinters/iface/testdata/iface_unexported.go b/pkg/golinters/iface/testdata/iface_unexported.go new file mode 100644 index 000000000000..01a4f210f9f7 --- /dev/null +++ b/pkg/golinters/iface/testdata/iface_unexported.go @@ -0,0 +1,84 @@ +//golangcitest:args -Eiface +//golangcitest:config_path testdata/iface_unexported.yml +package testdata + +import "fmt" + +// identical + +type Pinger interface { + Ping() error +} + +type Healthcheck interface { + Ping() error +} + +// opaque + +type Server interface { + Serve() error +} + +type server struct { + addr string +} + +func (s server) Serve() error { + return nil +} + +func NewServer(addr string) Server { + return &server{addr: addr} +} + +// unused + +type User struct { + ID string + Name string +} + +type UserRepository interface { + UserOf(id string) (*User, error) +} + +type UserRepositorySQL struct { +} + +func (r *UserRepositorySQL) UserOf(id string) (*User, error) { + return nil, nil +} + +type Granter interface { + Grant(permission string) error +} + +func AllowAll(g Granter) error { + return g.Grant("all") +} + +type Allower interface { + Allow(permission string) error +} + +func Allow(x any) { + _ = x.(Allower) + fmt.Println("allow") +} + +// unexported + +type unexportedReader interface { + Read([]byte) (int, error) +} + +func ReadAll(r unexportedReader) ([]byte, error) { // want "unexported interface 'unexportedReader' used as parameter in exported function 'ReadAll'" + buf := make([]byte, 1024) + _, err := r.Read(buf) + return buf, err +} + +func NewUnexportedReader() unexportedReader { // want "unexported interface 'unexportedReader' used as return value in exported function 'NewUnexportedReader'" + return nil // stub +} diff --git a/pkg/golinters/iface/testdata/iface_unexported.yml b/pkg/golinters/iface/testdata/iface_unexported.yml new file mode 100644 index 000000000000..cc0a84c0aa1e --- /dev/null +++ b/pkg/golinters/iface/testdata/iface_unexported.yml @@ -0,0 +1,7 @@ +version: "2" + +linters: + settings: + iface: + enable: + - unexported diff --git a/pkg/golinters/iface/testdata/iface_unused.go b/pkg/golinters/iface/testdata/iface_unused.go index b75fdc8964c6..58e5ffdbaf25 100644 --- a/pkg/golinters/iface/testdata/iface_unused.go +++ b/pkg/golinters/iface/testdata/iface_unused.go @@ -6,11 +6,11 @@ import "fmt" // identical -type Pinger interface { // want "unused: interface Pinger is declared but not used within the package" +type Pinger interface { // want "unused: interface 'Pinger' is declared but not used within the package" Ping() error } -type Healthcheck interface { // want "unused: interface Healthcheck is declared but not used within the package" +type Healthcheck interface { // want "unused: interface 'Healthcheck' is declared but not used within the package" Ping() error } @@ -39,7 +39,7 @@ type User struct { Name string } -type UserRepository interface { // want "unused: interface UserRepository is declared but not used within the package" +type UserRepository interface { // want "unused: interface 'UserRepository' is declared but not used within the package" UserOf(id string) (*User, error) } From e25c23180eeed81664f838ba6a858e03e002a280 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 20 May 2025 19:53:35 +0200 Subject: [PATCH 3/3] chore: update implementation --- .golangci.next.reference.yml | 1 + jsonschema/golangci.next.jsonschema.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index fa205ce7596f..4c8e1615682b 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -1795,6 +1795,7 @@ linters: - identical # Identifies interfaces in the same package that have identical method sets. - unused # Identifies interfaces that are not used anywhere in the same package where the interface is defined. - opaque # Identifies functions that return interfaces, but the actual returned value is always a single concrete implementation. + - unexported # Identifies interfaces that are not exported but are used in exported functions or methods. settings: unused: # List of packages path to exclude from the check. diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index ef1c956ef1c4..1bd33923a5de 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -661,7 +661,8 @@ "enum": [ "identical", "unused", - "opaque" + "opaque", + "unexported" ] }, "tagliatelle-cases": {