Skip to content

Commit 3583a69

Browse files
chore(golangci): update golangci-lint configuration to version 2 and enable formatters for gofmt and goimports
fix(tests): change file permission mode from octal 0644 to 0o644 for consistency with Go 1.19+ syntax fix(config): change file permission mode from octal 0600 to 0o600 for consistency with Go 1.19+ syntax refactor(help): rename variable max to maxLen for better clarity in maxCommandNameLen function chore(ui): remove unused error formatting variable errFmt from ui.go chore(webhooks): remove unused line from webhooks.go chore(binary_test): clean up temporary directory after running tests in TestMain fix(client): replace nil with http.NoBody in NewRequestWithContext for clarity style(client_test): simplify deferred body closing in tests for better readability chore(config): change file permission mode from octal 0755 to 0o755 for consistency with Go 1.19+ syntax
1 parent dfeaf65 commit 3583a69

12 files changed

Lines changed: 52 additions & 45 deletions

File tree

.golangci.yml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
version: "2"
2+
3+
formatters:
4+
enable:
5+
- gofmt
6+
- goimports
7+
18
linters:
29
enable:
310
- errcheck
@@ -6,20 +13,23 @@ linters:
613
- unused
714
- ineffassign
815
- gocritic
9-
- gofmt
10-
- goimports
1116
- misspell
12-
13-
linters-settings:
14-
gocritic:
15-
enabled-tags:
16-
- diagnostic
17-
- style
18-
misspell:
19-
locale: US
20-
21-
issues:
22-
exclude-dirs:
23-
- vendor
24-
max-issues-per-linter: 50
25-
max-same-issues: 10
17+
exclusions:
18+
paths:
19+
- vendor
20+
rules:
21+
- path: _test\.go
22+
linters:
23+
- errcheck
24+
settings:
25+
gocritic:
26+
enabled-tags:
27+
- diagnostic
28+
- style
29+
misspell:
30+
locale: US
31+
extra-words:
32+
- typo: cancelled
33+
correction: cancelled
34+
- typo: cancelling
35+
correction: cancelling

cmd/rentalot/bulk_import_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func TestLoadImportFile_CSV(t *testing.T) {
1010
dir := t.TempDir()
1111
path := filepath.Join(dir, "test.csv")
1212
content := "name,email,phone\nAlice,alice@example.com,555-0001\nBob,bob@example.com,555-0002\n"
13-
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
13+
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
1414
t.Fatal(err)
1515
}
1616

@@ -33,7 +33,7 @@ func TestLoadImportFile_JSON(t *testing.T) {
3333
dir := t.TempDir()
3434
path := filepath.Join(dir, "test.json")
3535
content := `[{"name":"Alice","email":"alice@example.com"},{"name":"Bob","email":"bob@example.com"}]`
36-
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
36+
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
3737
t.Fatal(err)
3838
}
3939

@@ -53,7 +53,7 @@ func TestLoadImportFile_JSONUpperCase(t *testing.T) {
5353
dir := t.TempDir()
5454
path := filepath.Join(dir, "test.JSON")
5555
content := `[{"id":"1"}]`
56-
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
56+
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
5757
t.Fatal(err)
5858
}
5959

@@ -76,7 +76,7 @@ func TestLoadImportFile_MissingFile(t *testing.T) {
7676
func TestLoadImportFile_InvalidJSON(t *testing.T) {
7777
dir := t.TempDir()
7878
path := filepath.Join(dir, "bad.json")
79-
if err := os.WriteFile(path, []byte(`{invalid`), 0644); err != nil {
79+
if err := os.WriteFile(path, []byte(`{invalid`), 0o644); err != nil {
8080
t.Fatal(err)
8181
}
8282

@@ -90,7 +90,7 @@ func TestLoadImportFile_EmptyCSV(t *testing.T) {
9090
dir := t.TempDir()
9191
path := filepath.Join(dir, "empty.csv")
9292
content := "name,email\n"
93-
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
93+
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
9494
t.Fatal(err)
9595
}
9696

@@ -107,7 +107,7 @@ func TestLoadImportFile_CSVTrimHeaders(t *testing.T) {
107107
dir := t.TempDir()
108108
path := filepath.Join(dir, "spaces.csv")
109109
content := " name , email \nAlice,alice@test.com\n"
110-
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
110+
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
111111
t.Fatal(err)
112112
}
113113

cmd/rentalot/commands_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ func TestWebhooksTestCmd_TableOutput(t *testing.T) {
727727
func TestBulkImportRun_Success(t *testing.T) {
728728
dir := t.TempDir()
729729
csvPath := dir + "/import.csv"
730-
if err := os.WriteFile(csvPath, []byte("name,email\nAlice,a@t.com\n"), 0644); err != nil {
730+
if err := os.WriteFile(csvPath, []byte("name,email\nAlice,a@t.com\n"), 0o644); err != nil {
731731
t.Fatal(err)
732732
}
733733

@@ -761,7 +761,7 @@ func TestBulkImportRun_Success(t *testing.T) {
761761
func TestBulkImportRun_NoPoll(t *testing.T) {
762762
dir := t.TempDir()
763763
csvPath := dir + "/import.csv"
764-
if err := os.WriteFile(csvPath, []byte("name,email\nAlice,a@t.com\n"), 0644); err != nil {
764+
if err := os.WriteFile(csvPath, []byte("name,email\nAlice,a@t.com\n"), 0o644); err != nil {
765765
t.Fatal(err)
766766
}
767767

@@ -782,7 +782,7 @@ func TestBulkImportRun_NoPoll(t *testing.T) {
782782
func TestBulkImportRun_EmptyFile(t *testing.T) {
783783
dir := t.TempDir()
784784
csvPath := dir + "/empty.csv"
785-
if err := os.WriteFile(csvPath, []byte("name,email\n"), 0644); err != nil {
785+
if err := os.WriteFile(csvPath, []byte("name,email\n"), 0o644); err != nil {
786786
t.Fatal(err)
787787
}
788788

@@ -802,7 +802,7 @@ func TestBulkImportRun_EmptyFile(t *testing.T) {
802802
func TestBulkImportRun_APIError(t *testing.T) {
803803
dir := t.TempDir()
804804
csvPath := dir + "/import.csv"
805-
if err := os.WriteFile(csvPath, []byte("name\nAlice\n"), 0644); err != nil {
805+
if err := os.WriteFile(csvPath, []byte("name\nAlice\n"), 0o644); err != nil {
806806
t.Fatal(err)
807807
}
808808

cmd/rentalot/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func runConfigInit(cmd *cobra.Command, args []string) error {
6262
if err := rentalotcli.SaveConfig(&rentalotcli.Config{}, globalConfigFile); err != nil {
6363
return err
6464
}
65-
if err := os.WriteFile(globalConfigFile, []byte(content), 0600); err != nil {
65+
if err := os.WriteFile(globalConfigFile, []byte(content), 0o600); err != nil {
6666
return fmt.Errorf("writing config: %w", err)
6767
}
6868
success("Created %s", fileRef(globalConfigFile))

cmd/rentalot/help.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ func visibleSubcommands(cmd *cobra.Command) []*cobra.Command {
116116
}
117117

118118
func maxCommandNameLen(cmds []*cobra.Command) int {
119-
max := 0
119+
maxLen := 0
120120
for _, c := range cmds {
121-
if len(c.Name()) > max {
122-
max = len(c.Name())
121+
if len(c.Name()) > maxLen {
122+
maxLen = len(c.Name())
123123
}
124124
}
125-
return max
125+
return maxLen
126126
}

cmd/rentalot/ui.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
var (
1010
successFmt = color.New(color.FgGreen)
1111
warnFmt = color.New(color.FgYellow)
12-
errFmt = color.New(color.FgRed)
1312
boldFmt = color.New(color.Bold)
1413
fileFmt = color.New(color.FgCyan)
1514
versionFmt = color.New(color.FgMagenta, color.Bold)
@@ -39,4 +38,3 @@ func fileRef(s string) string {
3938
func versionRef(s string) string {
4039
return versionFmt.Sprint(s)
4140
}
42-

cmd/rentalot/webhooks.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,3 @@ func webhooksTestCmd() *cobra.Command {
192192
},
193193
}
194194
}
195-

e2e/binary_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ func TestMain(m *testing.M) {
2121
if err != nil {
2222
panic(err)
2323
}
24-
defer os.RemoveAll(tmp)
25-
2624
bin := filepath.Join(tmp, "rentalot")
2725
if runtime.GOOS == "windows" {
2826
bin += ".exe"
@@ -34,7 +32,9 @@ func TestMain(m *testing.M) {
3432
}
3533
binaryPath = bin
3634

37-
os.Exit(m.Run())
35+
code := m.Run()
36+
os.RemoveAll(tmp)
37+
os.Exit(code)
3838
}
3939

4040
// runBinary executes the CLI binary with the given args and env overrides.

pkg/rentalotcli/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (c *Client) do(ctx context.Context, method, rawURL string, body *strings.Re
9595
if body != nil {
9696
req, err = http.NewRequestWithContext(ctx, method, rawURL, body)
9797
} else {
98-
req, err = http.NewRequestWithContext(ctx, method, rawURL, nil)
98+
req, err = http.NewRequestWithContext(ctx, method, rawURL, http.NoBody)
9999
}
100100
if err != nil {
101101
return nil, fmt.Errorf("creating request: %w", err)

pkg/rentalotcli/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestGet_WithQueryParams(t *testing.T) {
5757
if err != nil {
5858
t.Fatalf("unexpected error: %v", err)
5959
}
60-
defer func() { _ = resp.Body.Close() }()
60+
_ = resp.Body.Close()
6161
}
6262

6363
func TestGet_EmptyParamsIgnored(t *testing.T) {
@@ -74,7 +74,7 @@ func TestGet_EmptyParamsIgnored(t *testing.T) {
7474
if err != nil {
7575
t.Fatalf("unexpected error: %v", err)
7676
}
77-
defer func() { _ = resp.Body.Close() }()
77+
_ = resp.Body.Close()
7878
}
7979

8080
func TestPost_SendsJSONBody(t *testing.T) {
@@ -123,7 +123,7 @@ func TestPatch_SendsJSONBody(t *testing.T) {
123123
if err != nil {
124124
t.Fatalf("unexpected error: %v", err)
125125
}
126-
defer func() { _ = resp.Body.Close() }()
126+
_ = resp.Body.Close()
127127
}
128128

129129
func TestDelete_SendsDeleteRequest(t *testing.T) {

0 commit comments

Comments
 (0)