Skip to content

Commit 2095f62

Browse files
committed
chore: add more linting checks and fix them
1 parent 74ac2bc commit 2095f62

9 files changed

Lines changed: 196 additions & 112 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ jobs:
3333
cache: true
3434

3535
- name: golangci-lint
36-
uses: golangci/golangci-lint-action@v6
37-
with:
38-
version: latest
36+
run: |
37+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
38+
golangci-lint run
3939
4040
- name: Check formatting
4141
run: |

.golangci.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,86 @@
11
linters:
22
enable:
3+
# Default linters
34
- errcheck
45
- gosimple
56
- govet
67
- ineffassign
78
- staticcheck
89
- unused
910

11+
# Code style
12+
- gofmt
13+
- goimports
14+
- misspell
15+
- unconvert
16+
- whitespace
17+
18+
# Bug detection
19+
- bodyclose
20+
- durationcheck
21+
- nilerr
22+
- noctx
23+
- rowserrcheck
24+
- sqlclosecheck
25+
- wastedassign
26+
27+
# Code complexity & maintenance
28+
- copyloopvar
29+
- dupword
30+
- errname
31+
- errorlint
32+
- fatcontext
33+
- goconst
34+
- goprintffuncname
35+
- makezero
36+
- nosprintfhostport
37+
- prealloc
38+
- predeclared
39+
- reassign
40+
- revive
41+
- usetesting
42+
- tparallel
43+
- usestdlibvars
44+
45+
linters-settings:
46+
errcheck:
47+
check-type-assertions: true
48+
goconst:
49+
min-len: 3
50+
min-occurrences: 3
51+
misspell:
52+
locale: US
53+
revive:
54+
rules:
55+
- name: blank-imports
56+
- name: context-as-argument
57+
- name: context-keys-type
58+
- name: dot-imports
59+
- name: error-return
60+
- name: error-strings
61+
- name: error-naming
62+
- name: exported
63+
disabled: true
64+
- name: increment-decrement
65+
- name: var-naming
66+
- name: range
67+
- name: receiver-naming
68+
- name: time-naming
69+
- name: unexported-return
70+
- name: indent-error-flow
71+
- name: errorf
72+
- name: empty-block
73+
- name: superfluous-else
74+
- name: unused-parameter
75+
disabled: true
76+
- name: unreachable-code
77+
- name: redefines-builtin-id
78+
1079
issues:
1180
exclude-dirs:
1281
- vendor
82+
max-issues-per-linter: 0
83+
max-same-issues: 0
1384

1485
run:
1586
timeout: 5m

internal/common/helpers.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package common
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"strings"
89
"time"
@@ -36,8 +37,8 @@ func WithUserAgent(version string) client.ClientOption {
3637

3738
// ClientForProject creates a new SDK client targeting a specific project.
3839
func (ac *AppwriteClients) ClientForProject(projectID string) client.Client {
39-
opts := make([]client.ClientOption, len(ac.BaseOptions))
40-
copy(opts, ac.BaseOptions)
40+
opts := make([]client.ClientOption, 0, len(ac.BaseOptions)+1)
41+
opts = append(opts, ac.BaseOptions...)
4142
opts = append(opts, appwrite.WithProject(projectID))
4243
return appwrite.NewClient(opts...)
4344
}
@@ -66,23 +67,26 @@ func ProjectIDAttribute() schema.StringAttribute {
6667

6768
// IsNotFoundError checks if an Appwrite SDK error is a 404.
6869
func IsNotFoundError(err error) bool {
69-
if appErr, ok := err.(*client.AppwriteError); ok {
70+
var appErr *client.AppwriteError
71+
if errors.As(err, &appErr) {
7072
return appErr.GetStatusCode() == 404
7173
}
7274
return false
7375
}
7476

7577
// IsColumnNotAvailableError checks if the error is due to a column still being processed.
7678
func IsColumnNotAvailableError(err error) bool {
77-
if appErr, ok := err.(*client.AppwriteError); ok {
79+
var appErr *client.AppwriteError
80+
if errors.As(err, &appErr) {
7881
return appErr.GetStatusCode() == 400 && strings.Contains(appErr.GetMessage(), "not yet available")
7982
}
8083
return false
8184
}
8285

8386
// FormatError returns a detailed error string including status code and response body.
8487
func FormatError(err error) string {
85-
if appErr, ok := err.(*client.AppwriteError); ok {
88+
var appErr *client.AppwriteError
89+
if errors.As(err, &appErr) {
8690
return fmt.Sprintf("%s (status: %d, response: %s)", appErr.GetMessage(), appErr.GetStatusCode(), appErr.GetResponse())
8791
}
8892
return err.Error()
@@ -104,8 +108,12 @@ func GetColumnRaw(c client.Client, databaseID, tableID, key string) (map[string]
104108
if !strings.HasPrefix(resp.Type, "application/json") {
105109
return nil, fmt.Errorf("unexpected response type: %s", resp.Type)
106110
}
111+
resultStr, ok := resp.Result.(string)
112+
if !ok {
113+
return nil, fmt.Errorf("unexpected response result type: %T", resp.Result)
114+
}
107115
var result map[string]interface{}
108-
if err := json.Unmarshal([]byte(resp.Result.(string)), &result); err != nil {
116+
if err := json.Unmarshal([]byte(resultStr), &result); err != nil {
109117
return nil, fmt.Errorf("failed to unmarshal column response: %w", err)
110118
}
111119
return result, nil

0 commit comments

Comments
 (0)