Skip to content

Commit c228392

Browse files
committed
feat: added .golangci.yml config file
1 parent 68810a4 commit c228392

File tree

5 files changed

+343
-191
lines changed

5 files changed

+343
-191
lines changed

.golangci.yml

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.jsonschema.json
2+
# golangci-lint configuration for github.com/ralvarezdev/go-loader
3+
# Based on v2.5.0 best practices
4+
# Last updated: 2025-10-21
5+
6+
version: "2"
7+
8+
run:
9+
timeout: 5m
10+
concurrency: 0 # Auto-detect CPU cores
11+
tests: true
12+
modules-download-mode: readonly
13+
go: '1.25.1' # Match your project's Go version
14+
relative-path-mode: gomod
15+
16+
output:
17+
formats:
18+
text:
19+
path: stdout
20+
print-linter-name: true
21+
colors: true
22+
sort-order:
23+
- severity
24+
- linter
25+
- file
26+
show-stats: true
27+
28+
formatters:
29+
enable:
30+
- goimports
31+
- golines
32+
33+
settings:
34+
goimports:
35+
local-prefixes:
36+
- github.com/ralvarezdev/go-loader
37+
38+
golines:
39+
max-len: 120
40+
shorten-comments: true
41+
42+
exclusions:
43+
generated: lax
44+
paths:
45+
- "vendor/"
46+
- "third_party/"
47+
48+
linters:
49+
enable:
50+
# Essential Linters
51+
- govet
52+
- staticcheck
53+
- unused
54+
- goconst
55+
- godoclint
56+
- sloglint
57+
- misspell
58+
59+
# Security Linters
60+
- gosec
61+
- bidichk
62+
63+
# Resource Management
64+
- bodyclose
65+
- sqlclosecheck
66+
- rowserrcheck
67+
68+
# Error Handling Linters
69+
- errorlint
70+
- errcheck
71+
- nilerr
72+
- nilnil
73+
74+
# Code Quality
75+
- dupl
76+
- nestif
77+
- ineffassign
78+
- revive
79+
- gocritic
80+
- unconvert
81+
- wastedassign
82+
- usestdlibvars
83+
84+
# Context & Concurrency
85+
- contextcheck
86+
- noctx
87+
88+
# OPTIONAL - Testing (if using testify)
89+
# - testifylint
90+
# - thelper
91+
92+
settings:
93+
govet:
94+
enable:
95+
- shadow
96+
# - fieldalignment # Enable for performance-critical code
97+
settings:
98+
shadow:
99+
strict: true
100+
101+
errcheck:
102+
check-type-assertions: true
103+
check-blank: true
104+
exclude-functions:
105+
- io.Copy(*bytes.Buffer)
106+
- io.Copy(os.Stdout)
107+
- (*net/http.ResponseWriter).Write
108+
109+
staticcheck:
110+
checks:
111+
- "all"
112+
- "-SA1019" # Deprecation warnings (noisy during refactoring)
113+
- "-ST1000" # Package comment requirements
114+
- "-ST1003" # Underscore naming (conflicts with protobuf)
115+
- "-ST1016" # Receiver naming rules
116+
117+
goconst:
118+
min-len: 3
119+
min-occurrences: 3
120+
ignore-string-values:
121+
- 'http.*'
122+
- '^test.*'
123+
- '.*\.proto$'
124+
125+
godoclint:
126+
default: basic
127+
disable:
128+
- require-pkg-doc
129+
130+
sloglint:
131+
no-global: "all"
132+
static-msg: true
133+
key-naming-case: "snake"
134+
forbidden-keys:
135+
- time
136+
- level
137+
- msg
138+
- source
139+
140+
misspell:
141+
locale: US
142+
mode: restricted
143+
ignore-rules:
144+
- referer
145+
- kubernetes
146+
- grpc
147+
- protobuf
148+
149+
dupl:
150+
threshold: 100
151+
152+
nestif:
153+
min-complexity: 4
154+
155+
nilnil:
156+
only-two: true
157+
detect-opposite: true
158+
159+
gosec:
160+
excludes:
161+
- G104 # Duplicate of errcheck
162+
includes:
163+
- G201 # SQL injection
164+
- G202 # SQL injection
165+
- G204 # Command injection
166+
- G301 # File permissions
167+
- G302 # File permissions
168+
- G304 # File inclusion
169+
- G401 # Weak crypto
170+
- G402 # TLS InsecureSkipVerify
171+
172+
errorlint:
173+
errorf: true
174+
asserts: true
175+
comparison: true
176+
177+
revive:
178+
rules:
179+
# Error handling
180+
- name: error-return
181+
- name: error-strings
182+
- name: error-naming
183+
184+
# Code quality
185+
- name: if-return
186+
- name: increment-decrement
187+
- name: indent-error-flow
188+
- name: superfluous-else
189+
- name: unreachable-code
190+
191+
# Style
192+
- name: var-naming
193+
- name: range
194+
- name: receiver-naming
195+
- name: blank-imports
196+
- name: context-as-argument
197+
- name: dot-imports
198+
- name: empty-block
199+
200+
# Disable noisy rules
201+
- name: exported
202+
disabled: true
203+
- name: package-comments
204+
disabled: true
205+
- name: unused-parameter
206+
disabled: true
207+
208+
gocritic:
209+
enabled-tags:
210+
- diagnostic
211+
- style
212+
- performance
213+
disabled-checks:
214+
- commentFormatting
215+
- whyNoLint
216+
217+
exclusions:
218+
warn-unused: true
219+
220+
presets:
221+
- common-false-positives
222+
- std-error-handling
223+
224+
rules:
225+
# Test file exclusions
226+
- path: '_test\.go'
227+
linters:
228+
- dupl
229+
- errcheck
230+
- nestif
231+
- goconst
232+
- gosec
233+
- funlen
234+
- gocyclo
235+
236+
# Generated code
237+
- path: '\.pb\.go$'
238+
linters:
239+
- all
240+
241+
- path: 'mock_.+\.go$'
242+
linters:
243+
- all
244+
245+
# Long lines in go:generate
246+
- linters:
247+
- lll
248+
source: '^//go:generate '
249+
250+
# SQL linter false positives for repository pattern
251+
- text: "Rows/Stmt was not closed"
252+
path: _repository\.go$
253+
linters:
254+
- sqlclosecheck
255+
256+
issues:
257+
max-issues-per-linter: 0
258+
max-same-issues: 50
259+
uniq-by-line: true
260+
261+
# For gradual adoption on legacy codebases
262+
# new-from-rev: HEAD
263+
# new-from-merge-base: main
264+
265+
severity:
266+
default: error
267+
268+
rules:
269+
# Informational linters
270+
- linters:
271+
- dupl
272+
- goconst
273+
severity: info
274+
275+
# Security linters use their own severity
276+
- linters:
277+
- gosec
278+
severity: "@linter"

filesystem/read_files.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func CloseFile(file *os.File) error {
7575
// - []string: A slice of strings containing the headers (if readHeaders is true)
7676
// - error: An error if something went wrong
7777
func ReadCSVFile(file *os.File, readHeaders bool) (
78-
[][]string,
79-
[]string,
80-
error,
78+
records [][]string,
79+
headers []string,
80+
err error,
8181
) {
8282
// Check if the file is nil
8383
if file == nil {
@@ -86,17 +86,15 @@ func ReadCSVFile(file *os.File, readHeaders bool) (
8686

8787
// Defer closing the file
8888
defer func(file *os.File) {
89-
if err := CloseFile(file); err != nil {
90-
fmt.Println(err)
89+
if closeErr := CloseFile(file); closeErr != nil {
90+
fmt.Println(closeErr)
9191
}
9292
}(file)
9393

9494
// Create a new CSV reader
9595
reader := csv.NewReader(file)
9696

9797
// Read the header line
98-
var headers []string
99-
var err error
10098
if readHeaders {
10199
headers, err = reader.Read()
102100
if err != nil {
@@ -105,7 +103,7 @@ func ReadCSVFile(file *os.File, readHeaders bool) (
105103
}
106104

107105
// Read all records from the CSV file
108-
records, err := reader.ReadAll()
106+
records, err = reader.ReadAll()
109107
if err != nil {
110108
return nil, nil, fmt.Errorf("failed to read CSV file: %w", err)
111109
}

go.mod

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module github.com/ralvarezdev/go-loader
33
go 1.24.0
44

55
require (
6-
golang.org/x/oauth2 v0.31.0
7-
google.golang.org/api v0.251.0
8-
google.golang.org/grpc v1.75.1
6+
golang.org/x/oauth2 v0.32.0
7+
google.golang.org/api v0.252.0
8+
google.golang.org/grpc v1.76.0
99
)
1010

1111
require (
12-
cloud.google.com/go/auth v0.16.5 // indirect
12+
cloud.google.com/go/auth v0.17.0 // indirect
1313
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
1414
cloud.google.com/go/compute/metadata v0.9.0 // indirect
1515
github.com/felixge/httpsnoop v1.0.4 // indirect
@@ -18,14 +18,15 @@ require (
1818
github.com/google/s2a-go v0.1.9 // indirect
1919
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
2020
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
21-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
22-
go.opentelemetry.io/otel v1.37.0 // indirect
23-
go.opentelemetry.io/otel/metric v1.37.0 // indirect
24-
go.opentelemetry.io/otel/trace v1.37.0 // indirect
25-
golang.org/x/crypto v0.42.0 // indirect
26-
golang.org/x/net v0.44.0 // indirect
27-
golang.org/x/sys v0.36.0 // indirect
28-
golang.org/x/text v0.29.0 // indirect
29-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251002232023-7c0ddcbb5797 // indirect
21+
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
22+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 // indirect
23+
go.opentelemetry.io/otel v1.38.0 // indirect
24+
go.opentelemetry.io/otel/metric v1.38.0 // indirect
25+
go.opentelemetry.io/otel/trace v1.38.0 // indirect
26+
golang.org/x/crypto v0.43.0 // indirect
27+
golang.org/x/net v0.46.0 // indirect
28+
golang.org/x/sys v0.37.0 // indirect
29+
golang.org/x/text v0.30.0 // indirect
30+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251020155222-88f65dc88635 // indirect
3031
google.golang.org/protobuf v1.36.10 // indirect
3132
)

0 commit comments

Comments
 (0)