Skip to content

Commit 237ddb3

Browse files
committed
rename package to dev.gaijin.team/go/exhaustruct/v4
1 parent bbbf240 commit 237ddb3

File tree

12 files changed

+78
-56
lines changed

12 files changed

+78
-56
lines changed

README.md

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Package being renamed to `dev.gaijin.team/go/exhaustruct/v4` and all further upd
2020
### Installation
2121

2222
```shell
23-
go get -u github.com/GaijinEntertainment/go-exhaustruct/v4/cmd/exhaustruct
23+
go get -u dev.gaijin.team/go/exhaustruct/v4/cmd/exhaustruct
2424
```
2525

2626
### Usage
@@ -80,24 +80,27 @@ it's check regardless global configuration. Comment directives have precedence o
8080
By default, linter will check all structures and report if any accessible field initialization is missing.
8181

8282
```go
83+
package main
84+
8385
type Config struct {
84-
Host string
85-
Port int
86-
Database string
86+
Host string
87+
Port int
88+
Database string
8789
}
8890

8991
// Without any flags - requires all fields
9092
func createConfig() Config {
91-
return Config{} // ERROR: missing fields Host, Port, Database
93+
return Config{} // ERROR: missing fields Host, Port, Database
9294
}
9395

9496
func createValidConfig() Config {
95-
return Config{
96-
Host: "localhost",
97-
Port: 5432,
98-
Database: "mydb",
99-
}
97+
return Config{
98+
Host: "localhost",
99+
Port: 5432,
100+
Database: "mydb",
101+
}
100102
}
103+
101104
```
102105

103106
#### Empty Allowance Options
@@ -112,16 +115,19 @@ exhaustruct -allow-empty ./...
112115
```
113116

114117
```go
118+
package main
119+
115120
// With -allow-empty: ALL empty structs are allowed
116121
func createConfig() Config {
117-
return Config{} // OK: empty structs allowed globally
122+
return Config{} // OK: empty structs allowed globally
118123
}
119124

120125
var globalConfig = Config{} // OK: empty structs allowed globally
121126

122127
func processConfigs() []Config {
123-
return []Config{{}} // OK: empty structs allowed globally
128+
return []Config{{}} // OK: empty structs allowed globally
124129
}
130+
125131
```
126132

127133
##### 2. Return Statement Allowance (`-allow-empty-returns`)
@@ -135,19 +141,22 @@ exhaustruct -allow-empty-returns ./...
135141
```
136142

137143
```go
144+
package main
145+
138146
// With -allow-empty-returns: empty structs allowed only in return statements
139147
func createConfig() Config {
140-
return Config{} // OK: empty struct in return statement
148+
return Config{} // OK: empty struct in return statement
141149
}
142150

143151
func initializeConfig() {
144-
var config = Config{} // ERROR: empty struct in variable declaration
145-
_ = config
152+
var config = Config{} // ERROR: empty struct in variable declaration
153+
_ = config
146154
}
147155

148156
func processConfigs() []Config {
149-
return []Config{{}} // ERROR: empty struct in slice literal (not direct child of return statement)
157+
return []Config{{}} // ERROR: empty struct in slice literal (not direct child of return statement)
150158
}
159+
151160
```
152161

153162
##### 3. Variable Declaration Allowance (`-allow-empty-declarations`)
@@ -161,21 +170,23 @@ exhaustruct -allow-empty-declarations ./...
161170
```
162171

163172
```go
173+
package main
174+
164175
// With -allow-empty-declarations: empty structs allowed in variable declarations
165176
func initializeConfig() {
166-
var config = Config{} // OK: empty struct in variable declaration
167-
config := Config{} // OK: empty struct in short variable declaration
168-
ptr := &Config{} // OK: empty struct in pointer declaration
169-
_ = config
170-
_ = ptr
177+
var config = Config{} // OK: empty struct in variable declaration
178+
config := Config{} // OK: empty struct in short variable declaration
179+
ptr := &Config{} // OK: empty struct in pointer declaration
180+
_ = config
181+
_ = ptr
171182
}
172183

173184
func createConfig() Config {
174-
return Config{} // ERROR: empty struct in return statement
185+
return Config{} // ERROR: empty struct in return statement
175186
}
176187

177188
func processConfigs() []Config {
178-
return []Config{{}} // ERROR: empty struct in slice literal
189+
return []Config{{}} // ERROR: empty struct in slice literal
179190
}
180191
```
181192

@@ -189,35 +200,38 @@ exhaustruct -allow-empty-include ".*Config.*" -allow-empty-include ".*Options.*"
189200
```
190201

191202
```go
203+
package main
204+
192205
type DatabaseConfig struct {
193-
Host string
194-
Port int
206+
Host string
207+
Port int
195208
}
196209

197210
type ServerOptions struct {
198-
Timeout int
199-
MaxConns int
211+
Timeout int
212+
MaxConns int
200213
}
201214

202215
type UserData struct {
203-
Name string
204-
Email string
216+
Name string
217+
Email string
205218
}
206219

207220
func example() {
208-
// OK: matches .*Config.* pattern
209-
config := DatabaseConfig{}
221+
// OK: matches .*Config.* pattern
222+
config := DatabaseConfig{}
210223

211-
// OK: matches .*Options.* pattern
212-
opts := ServerOptions{}
224+
// OK: matches .*Options.* pattern
225+
opts := ServerOptions{}
213226

214-
// ERROR: doesn't match any pattern
215-
user := UserData{}
227+
// ERROR: doesn't match any pattern
228+
user := UserData{}
216229

217-
_ = config
218-
_ = opts
219-
_ = user
230+
_ = config
231+
_ = opts
232+
_ = user
220233
}
234+
221235
```
222236

223237
#### Errors handling
@@ -226,29 +240,35 @@ In order to avoid unnecessary noise, when dealing with non-pointer types returne
226240
ignore non-error types, in case return statement contains non-nil value that satisfies `error` interface.
227241

228242
```go
243+
package main
244+
245+
import (
246+
"errors"
247+
)
248+
229249
type Shape struct {
230-
Length int
231-
Width int
250+
Length int
251+
Width int
232252
}
233253

234254
func NewShape() (Shape, error) {
235-
return Shape{}, errors.New("error") // will not raise an error
255+
return Shape{}, errors.New("error") // will not raise an error
236256
}
237257

238258
type MyError struct {
239-
Err error
259+
Err error
240260
}
241261

242262
func (e MyError) Error() string {
243-
return e.Err.Error()
263+
return e.Err.Error()
244264
}
245265

246266
func NewSquare() (Shape, error) {
247-
return Shape{}, &MyError{Err: errors.New("error")} // will not raise an error
267+
return Shape{}, &MyError{Err: errors.New("error")} // will not raise an error
248268
}
249269

250270
func NewCircle() (Shape, error) {
251-
return Shape{}, &MyError{} // will raise "main.MyError is missing field Err"
271+
return Shape{}, &MyError{} // will raise "main.MyError is missing field Err"
252272
}
253273

254274
```

analyzer/analyzer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"golang.org/x/tools/go/analysis/passes/inspect"
1313
"golang.org/x/tools/go/ast/inspector"
1414

15-
"github.com/GaijinEntertainment/go-exhaustruct/v4/internal/comment"
16-
"github.com/GaijinEntertainment/go-exhaustruct/v4/internal/structure"
15+
"dev.gaijin.team/go/exhaustruct/v4/internal/comment"
16+
"dev.gaijin.team/go/exhaustruct/v4/internal/structure"
1717
)
1818

1919
type analyzer struct {

analyzer/analyzer_benchmark_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/stretchr/testify/require"
77
"golang.org/x/tools/go/analysis/analysistest"
88

9-
"github.com/GaijinEntertainment/go-exhaustruct/v4/analyzer"
9+
"dev.gaijin.team/go/exhaustruct/v4/analyzer"
1010
)
1111

1212
func BenchmarkAnalyzer(b *testing.B) {

analyzer/analyzer_empty_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/stretchr/testify/require"
77
"golang.org/x/tools/go/analysis/analysistest"
88

9-
"github.com/GaijinEntertainment/go-exhaustruct/v4/analyzer"
9+
"dev.gaijin.team/go/exhaustruct/v4/analyzer"
1010
)
1111

1212
func TestAnalyzerEmpty(t *testing.T) {

analyzer/analyzer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/stretchr/testify/require"
99
"golang.org/x/tools/go/analysis/analysistest"
1010

11-
"github.com/GaijinEntertainment/go-exhaustruct/v4/analyzer"
11+
"dev.gaijin.team/go/exhaustruct/v4/analyzer"
1212
)
1313

1414
var testdataPath, _ = filepath.Abs("./testdata/") //nolint:gochecknoglobals

analyzer/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"dev.gaijin.team/go/golib/e"
88

9-
"github.com/GaijinEntertainment/go-exhaustruct/v4/internal/pattern"
9+
"dev.gaijin.team/go/exhaustruct/v4/internal/pattern"
1010
)
1111

1212
type Config struct {

cmd/exhaustruct/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"golang.org/x/tools/go/analysis/singlechecker"
77

8-
"github.com/GaijinEntertainment/go-exhaustruct/v4/analyzer"
8+
"dev.gaijin.team/go/exhaustruct/v4/analyzer"
99
)
1010

1111
func main() {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/GaijinEntertainment/go-exhaustruct/v4
1+
module dev.gaijin.team/go/exhaustruct/v4
22

33
go 1.24
44

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
dev.gaijin.team/go/golib v0.6.0 h1:v6nnznFTs4bppib/NyU1PQxobwDHwCXXl15P7DV5Zgo=
22
dev.gaijin.team/go/golib v0.6.0/go.mod h1:uY1mShx8Z/aNHWDyAkZTkX+uCi5PdX7KsG1eDQa2AVE=
3+
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.1 h1:Sz1JIXEcSfhz7fUi7xHnhpIE0thVASYjvosApmHuD2k=
4+
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.1/go.mod h1:n/LSCXNuIYqVfBlVXyHfMQkZDdp1/mmxfSjADd3z1Zg=
35
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
46
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
57
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=

internal/comment/directive_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/stretchr/testify/assert"
88

9-
"github.com/GaijinEntertainment/go-exhaustruct/v4/internal/comment"
9+
"dev.gaijin.team/go/exhaustruct/v4/internal/comment"
1010
)
1111

1212
func TestParseDirective(t *testing.T) {

0 commit comments

Comments
 (0)