Skip to content

Commit 072c7bd

Browse files
committed
fix: lint issues and update to golangci-lint v2 config
- Migrate .golangci.yml to v2 format with strict but pragmatic settings - Fix unchecked type assertions in powersync/sync.go (could panic) - Fix error comparisons to use errors.Is() (works with wrapped errors) - Use http.MethodPost/Get and http.StatusUnauthorized constants - Remove unused renderCentered function - Update .envrc to default to local control plane - Simplify Taskfile to use hermit-installed golangci-lint Exclusions: - internal/sqlite/: noctx (local DB, context not needed) - pkg/client/: ST1003 naming (matches API naming)
1 parent 942ce28 commit 072c7bd

25 files changed

Lines changed: 150 additions & 131 deletions

File tree

‎.envrc‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
# Ensure hermit is loaded by the editor
44
eval "$("$PWD/bin/hermit" env -)"
55

6-
# Tero CLI configuration
7-
# Uncomment to use local control plane (production is the default)
8-
# export TERO_API_ENDPOINT="http://localhost:8081/graphql"
6+
# Tero CLI configuration - Local control plane (default for development)
7+
export TERO_API_ENDPOINT="http://localhost:8081/graphql"
8+
export TERO_POWERSYNC_ENDPOINT="http://localhost:8084"
99

10-
# Use staging environment
11-
export TERO_API_ENDPOINT="https://api.usetero.dev/graphql"
10+
# WorkOS client ID (same for local dev)
1211
export TERO_WORKOS_CLIENT_ID="client_01JQCC2CJMTB8AY2JRMZXFY9R1"
13-
export TERO_POWERSYNC_ENDPOINT="https://powersync.usetero.dev"
12+
13+
# Staging environment (uncomment to use instead of local)
14+
# export TERO_API_ENDPOINT="https://api.usetero.dev/graphql"
15+
# export TERO_POWERSYNC_ENDPOINT="https://powersync.usetero.dev"
1416

1517
# Development: Skip to app mode after onboarding complete
1618
# Set to "true" to automatically transition from onboarding complete screen to app

‎.golangci.yml‎

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
# GolangCI-Lint configuration for Tero CLI
3-
# Focuses on catching real issues while avoiding noise
2+
# GolangCI-Lint v2 configuration for Tero CLI
3+
# Strict but pragmatic - catches real bugs, ignores noise
44

55
version: "2"
66

@@ -9,6 +9,7 @@ run:
99
tests: true
1010

1111
linters:
12+
default: none
1213
enable:
1314
# Core static analysis (essential)
1415
- errcheck # Unchecked errors
@@ -17,7 +18,7 @@ linters:
1718
- unused # Unused code
1819
- ineffassign # Ineffectual assignments
1920

20-
# Code quality and style
21+
# Code quality
2122
- misspell # Common misspellings
2223
- unconvert # Unnecessary type conversions
2324
- wastedassign # Wasted assignments
@@ -26,62 +27,63 @@ linters:
2627
- bodyclose # HTTP response body not closed
2728
- noctx # HTTP requests without context
2829
- rowserrcheck # SQL rows.Err() not checked
29-
- copyloopvar # Loop variable copying (Go 1.22+)
30+
- copyloopvar # Loop variable copying
3031

3132
# Error handling
32-
- errorlint # Error wrapping issues
33+
- errorlint # Error wrapping issues (use errors.Is)
3334
- errname # Error naming conventions
3435

35-
# Interface and type safety
36-
- forcetypeassert # Type assertion checking
37-
38-
# Additional valuable checks
39-
- nilerr # Finds code that returns nil even if it checks that error is not nil
40-
- nolintlint # Reports ill-formed or insufficient nolint directives
41-
- usestdlibvars # Detects possibility to use variables/constants from stdlib
42-
43-
linters-settings:
44-
errcheck:
45-
# Don't require error checks for these functions where it's reasonable to ignore
46-
exclude-functions:
47-
- (io.Closer).Close
48-
- (*os.File).Close
49-
50-
govet:
51-
enable-all: true
52-
disable:
53-
- fieldalignment # Can be noisy and performance impact is usually minimal
54-
- shadow # Can be overly strict
55-
56-
staticcheck:
57-
checks: ["all"]
58-
59-
nolintlint:
60-
# Require explanation for nolint directives
61-
require-explanation: true
62-
# Require specific linter names in nolint directives
63-
require-specific: true
64-
65-
issues:
66-
max-issues-per-linter: 0
67-
max-same-issues: 0
68-
69-
exclude-rules:
70-
# Allow security issues in test files
71-
- path: '.*_test\.go$'
72-
linters: [gosec]
73-
74-
# Allow unchecked type assertions in test files
75-
- path: '.*_test\.go$'
76-
linters: [forcetypeassert]
77-
78-
# Skip generated files entirely
79-
- path: 'pkg/client/generated\.go$'
80-
linters: [all]
81-
82-
# Allow unused parameters in interfaces
83-
- text: "`(ctx|logger)` is unused"
84-
linters: [unused]
36+
# Type safety
37+
- forcetypeassert # Unchecked type assertions can panic
38+
39+
# Additional checks
40+
- nilerr # Returns nil even when error is not nil
41+
- nolintlint # Validates nolint directives
42+
- usestdlibvars # Use stdlib constants
43+
44+
settings:
45+
govet:
46+
enable-all: true
47+
disable:
48+
- fieldalignment # Noisy, minimal impact
49+
- shadow # Overly strict
50+
51+
staticcheck:
52+
checks: ["all"]
53+
54+
nolintlint:
55+
require-explanation: true
56+
require-specific: true
57+
58+
exclusions:
59+
# Presets for common false positives
60+
presets:
61+
- comments
62+
- std-error-handling
63+
64+
rules:
65+
# Skip generated files
66+
- path: 'pkg/client/generated\.go$'
67+
linters: [all]
68+
69+
# Client wrappers match API naming (ApiKey not APIKey)
70+
- path: "pkg/client/"
71+
text: "ST1003"
72+
linters: [staticcheck]
73+
74+
# API test mocks match the client interface naming
75+
- path: "internal/api/apitest/"
76+
text: "ST1003"
77+
linters: [staticcheck]
78+
79+
# sqlite package: local DB, context cancellation not critical
80+
# The interface intentionally omits context for simplicity
81+
- path: "internal/sqlite/"
82+
linters: [noctx]
83+
84+
# Allow unused ctx/logger parameters in interface implementations
85+
- text: "`(ctx|logger)` is unused"
86+
linters: [unused]
8587

8688
severity:
8789
default: error

‎Taskfile.yml‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@ tasks:
9797
lint:go:
9898
desc: Run golangci-lint
9999
cmds:
100-
- |
101-
if ! command -v golangci-lint &> /dev/null; then
102-
echo "golangci-lint not found. Installing..."
103-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
104-
fi
105-
- $(go env GOPATH)/bin/golangci-lint run ./...
100+
- golangci-lint run ./...
106101

107102
lint:scripts:
108103
desc: Lint shell scripts with shellcheck

‎internal/powersync/schema.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func FetchSchemaJSON(ctx context.Context, endpoint, token string) (string, error
103103

104104
// fetchColumnTypes fetches column type information from the schema API.
105105
func fetchColumnTypes(ctx context.Context, endpoint, token string) (map[string]map[string]columnType, error) {
106-
req, err := http.NewRequestWithContext(ctx, "POST", endpoint+"/api/admin/v1/schema", strings.NewReader("{}"))
106+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint+"/api/admin/v1/schema", strings.NewReader("{}"))
107107
if err != nil {
108108
return nil, err
109109
}
@@ -149,7 +149,7 @@ func fetchColumnTypes(ctx context.Context, endpoint, token string) (map[string]m
149149

150150
// fetchSyncedTables fetches the synced tables from the sync rules API.
151151
func fetchSyncedTables(ctx context.Context, endpoint, token string, columnTypes map[string]map[string]columnType) ([]SchemaTable, error) {
152-
req, err := http.NewRequestWithContext(ctx, "GET", endpoint+"/api/sync-rules/v1/current", nil)
152+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint+"/api/sync-rules/v1/current", nil)
153153
if err != nil {
154154
return nil, err
155155
}

0 commit comments

Comments
 (0)