Skip to content

Commit 44f37c5

Browse files
authored
chore: add support for gofumpt (#4055)
1 parent 3bdcce0 commit 44f37c5

File tree

93 files changed

+392
-475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+392
-475
lines changed

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ linters:
1818
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
1919
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
2020
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
21+
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
2122
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
2223
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false]
2324
- goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false]
@@ -73,6 +74,9 @@ linters:
7374
linters-settings:
7475
goconst:
7576
min-len: 5
77+
gosec:
78+
excludes:
79+
- G115
7680

7781
issues:
7882
exclude-dirs:

internal/args/args.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,22 @@ func (a RawArgs) ExistsArgByName(name string) bool {
2424
return ok
2525
}
2626

27-
var (
28-
scalarKinds = map[reflect.Kind]bool{
29-
reflect.Int: true,
30-
reflect.Int8: true,
31-
reflect.Int16: true,
32-
reflect.Int32: true,
33-
reflect.Int64: true,
34-
reflect.Uint: true,
35-
reflect.Uint8: true,
36-
reflect.Uint16: true,
37-
reflect.Uint32: true,
38-
reflect.Uint64: true,
39-
reflect.Float32: true,
40-
reflect.Float64: true,
41-
reflect.Bool: true,
42-
reflect.String: true,
43-
}
44-
)
27+
var scalarKinds = map[reflect.Kind]bool{
28+
reflect.Int: true,
29+
reflect.Int8: true,
30+
reflect.Int16: true,
31+
reflect.Int32: true,
32+
reflect.Int64: true,
33+
reflect.Uint: true,
34+
reflect.Uint8: true,
35+
reflect.Uint16: true,
36+
reflect.Uint32: true,
37+
reflect.Uint64: true,
38+
reflect.Float32: true,
39+
reflect.Float64: true,
40+
reflect.Bool: true,
41+
reflect.String: true,
42+
}
4543

4644
// SplitRaw creates a map that maps arg names to their values.
4745
// ["arg1=1", "arg2=2", "arg3"] => {"arg1": "1", "arg2": "2", "arg3":"" }

internal/args/errors.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010
// Marshal & Unmarshal Errors
1111
//
1212

13-
type DataMustBeAPointerError struct {
14-
}
13+
type DataMustBeAPointerError struct{}
1514

1615
func (e *DataMustBeAPointerError) Error() string {
1716
return "data must be a pointer to a struct"
@@ -21,8 +20,7 @@ func (e *DataMustBeAPointerError) Error() string {
2120
// Marshal Errors
2221
//
2322

24-
type DataMustBeAMarshalableValueError struct {
25-
}
23+
type DataMustBeAMarshalableValueError struct{}
2624

2725
func (e *DataMustBeAMarshalableValueError) Error() string {
2826
return "data must be a marshalable value (a scalar type or a Marshaler)"
@@ -71,22 +69,19 @@ func (e *UnmarshalArgError) Unwrap() error {
7169
return e.Err
7270
}
7371

74-
type InvalidArgNameError struct {
75-
}
72+
type InvalidArgNameError struct{}
7673

7774
func (e *InvalidArgNameError) Error() string {
7875
return "arg name must only contain lowercase letters, numbers or dashes"
7976
}
8077

81-
type UnknownArgError struct {
82-
}
78+
type UnknownArgError struct{}
8379

8480
func (e *UnknownArgError) Error() string {
8581
return "unknown argument"
8682
}
8783

88-
type DuplicateArgError struct {
89-
}
84+
type DuplicateArgError struct{}
9085

9186
func (e *DuplicateArgError) Error() string {
9287
return "duplicate argument"
@@ -100,8 +95,7 @@ func (e *CannotSetNestedFieldError) Error() string {
10095
return fmt.Sprintf("cannot set nested field for unmarshalable type %T", e.Dest)
10196
}
10297

103-
type MissingIndexOnArrayError struct {
104-
}
98+
type MissingIndexOnArrayError struct{}
10599

106100
func (e *MissingIndexOnArrayError) Error() string {
107101
return "missing index on the array"
@@ -129,8 +123,7 @@ func (e *MissingIndicesInArrayError) Error() string {
129123
}
130124
}
131125

132-
type MissingMapKeyError struct {
133-
}
126+
type MissingMapKeyError struct{}
134127

135128
func (e *MissingMapKeyError) Error() string {
136129
return "missing map key"

internal/args/marshal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestMarshal(t *testing.T) {
125125
t.Run("well-known-types", run(TestCase{
126126
data: &WellKnownTypes{
127127
Size: 20 * scw.GB,
128-
Time: time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC),
128+
Time: time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC),
129129
},
130130
expected: []string{
131131
"size=20GB",

internal/args/unmarshal_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func TestUnmarshalStruct(t *testing.T) {
251251
"time=2006-01-02T15:04:05Z",
252252
},
253253
expected: &WellKnownTypes{
254-
Time: time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC),
254+
Time: time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC),
255255
},
256256
}))
257257

@@ -260,7 +260,7 @@ func TestUnmarshalStruct(t *testing.T) {
260260
"time=+1m1s",
261261
},
262262
expected: &WellKnownTypes{
263-
Time: time.Date(1970, 01, 01, 0, 1, 1, 0, time.UTC),
263+
Time: time.Date(1970, 1, 1, 0, 1, 1, 0, time.UTC),
264264
},
265265
}))
266266

@@ -533,6 +533,7 @@ func TestUnmarshalStruct(t *testing.T) {
533533
error: "cannot unmarshal arg 'strings': missing index on the array",
534534
}))
535535
}
536+
536537
func TestIsUmarshalableValue(t *testing.T) {
537538
type TestCase struct {
538539
expected bool

internal/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818
ScwConfigPathEnv = "SCW_CLI_CONFIG_PATH"
1919

2020
DefaultConfigFileName = "cli.yaml"
21-
defaultConfigPermission = 0644
21+
defaultConfigPermission = 0o644
2222

2323
DefaultOutput = "human"
2424
configFileTemplate = `# Scaleway CLI config file
@@ -101,7 +101,7 @@ func (c *Config) Save() error {
101101
return err
102102
}
103103

104-
err = os.MkdirAll(filepath.Dir(c.path), 0700)
104+
err = os.MkdirAll(filepath.Dir(c.path), 0o700)
105105
if err != nil {
106106
return err
107107
}

internal/config/editor.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import (
55
"runtime"
66
)
77

8-
var (
9-
// List of env variables where to find the editor to use
10-
// Order in slice is override order, the latest will override the first ones
11-
editorEnvVariables = []string{"EDITOR", "VISUAL"}
12-
)
8+
// List of env variables where to find the editor to use
9+
// Order in slice is override order, the latest will override the first ones
10+
var editorEnvVariables = []string{"EDITOR", "VISUAL"}
1311

1412
func GetSystemDefaultEditor() string {
1513
switch runtime.GOOS {

internal/core/autocomplete_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,8 @@ func TestAutocompleteArgs(t *testing.T) {
219219
Namespace: "test",
220220
Resource: "flower",
221221
Verb: "list",
222-
ArgsType: reflect.TypeOf(struct {
223-
}{}),
224-
ArgSpecs: core.ArgSpecs{},
222+
ArgsType: reflect.TypeOf(struct{}{}),
223+
ArgSpecs: core.ArgSpecs{},
225224
Run: func(_ context.Context, _ interface{}) (interface{}, error) {
226225
return []*struct {
227226
Name string
@@ -239,9 +238,8 @@ func TestAutocompleteArgs(t *testing.T) {
239238
Namespace: "test",
240239
Resource: "material",
241240
Verb: "list",
242-
ArgsType: reflect.TypeOf(struct {
243-
}{}),
244-
ArgSpecs: core.ArgSpecs{},
241+
ArgsType: reflect.TypeOf(struct{}{}),
242+
ArgSpecs: core.ArgSpecs{},
245243
Run: func(_ context.Context, _ interface{}) (interface{}, error) {
246244
return []*struct {
247245
Name string

internal/core/bootstrap.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ func Bootstrap(config *BootstrapConfig) (exitCode int, result interface{}, err e
261261
rootCmd.SetArgs(args)
262262
rootCmd.SetHelpCommand(&cobra.Command{Hidden: true})
263263
err = rootCmd.Execute()
264-
265264
if err != nil {
266265
if _, ok := err.(*interactive.InterruptError); ok {
267266
return 130, nil, err

internal/core/checks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ func GetLatestVersionUpdateFilePath(cacheDir string) string {
3535

3636
// CreateAndCloseFile creates a file and closes it. It returns true on succeed, false on failure.
3737
func CreateAndCloseFile(path string) error {
38-
err := os.MkdirAll(filepath.Dir(path), 0700)
38+
err := os.MkdirAll(filepath.Dir(path), 0o700)
3939
if err != nil {
4040
return fmt.Errorf("failed creating path %s: %s", path, err)
4141
}
42-
newFile, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0600)
42+
newFile, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0o600)
4343
if err != nil {
4444
return fmt.Errorf("failed creating file %s: %s", path, err)
4545
}

0 commit comments

Comments
 (0)