Skip to content

Commit 231e2f0

Browse files
committed
fix all golangci-lint warnings
1 parent d060ccf commit 231e2f0

47 files changed

Lines changed: 689 additions & 929 deletions

Some content is hidden

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

.golangci.yml

Lines changed: 33 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,69 @@
1+
version: "2"
12
linters:
3+
default: none
24
enable:
3-
# Check for pass []any as any in variadic func(...any).
4-
# Rare case but saved me from debugging a few times.
55
- asasalint
6-
7-
# I prefer plane ASCII identifiers.
8-
# Symbol `∆` instead of `delta` looks cool but no thanks.
96
- asciicheck
10-
11-
# Checks for dangerous unicode character sequences.
12-
# Super rare but why not to be a bit paranoid?
137
- bidichk
14-
15-
# Checks whether HTTP response body is closed successfully.
168
- bodyclose
17-
18-
# Check whether the function uses a non-inherited context.
199
- contextcheck
20-
21-
# Check for two durations multiplied together.
2210
- durationcheck
23-
24-
# Forces to not skip error check.
2511
- errcheck
26-
27-
# Checks `Err-` prefix for var and `-Error` suffix for error type.
2812
- errname
29-
30-
# Suggests to use `%w` for error-wrapping.
3113
- errorlint
32-
33-
# Checks for pointers to enclosing loop variables.
34-
- exportloopref
35-
36-
# Forces to put `.` at the end of the comment. Code is poetry.
3714
- godot
38-
39-
# Might not be that important but I prefer to keep all of them.
40-
# `gofumpt` is amazing, kudos to Daniel Marti https://github.com/mvdan/gofumpt
41-
- gofmt
42-
- gofumpt
43-
- goimports
44-
45-
# Allow or ban replace directives in go.mod
46-
# or force explanation for retract directives.
47-
- gomoddirectives
48-
49-
# Powerful security-oriented linter. But requires some time to
50-
# configure it properly, see https://github.com/securego/gosec#available-rules
5115
- gosec
52-
53-
# Linter that specializes in simplifying code.
54-
- gosimple
55-
56-
# Official Go tool. Must have.
5716
- govet
58-
59-
# Detects when assignments to existing variables are not used
60-
# Last week I caught a bug with it.
6117
- ineffassign
62-
63-
# Fix all the misspells, amazing thing.
6418
- misspell
65-
66-
# Finds naked/bare returns and requires change them.
6719
- nakedret
68-
69-
# Both require a bit more explicit returns.
7020
- nilerr
7121
- nilnil
72-
73-
# Finds sending HTTP request without context.Context.
7422
- noctx
75-
76-
# Forces comment why another check is disabled.
77-
# Better not to have //nolint: at all ;)
7823
- nolintlint
79-
80-
# Finds slices that could potentially be pre-allocated.
81-
# Small performance win + cleaner code.
82-
- prealloc
83-
84-
# Finds shadowing of Go's predeclared identifiers.
85-
# I hear a lot of complaints from junior developers.
86-
# But after some time they find it very useful.
8724
- predeclared
88-
89-
# Lint your Prometheus metrics name.
9025
- promlinter
91-
92-
# Checks that package variables are not reassigned.
93-
# Super rare case but can catch bad things (like `io.EOF = nil`)
9426
- reassign
95-
96-
# Drop-in replacement of `golint`.
9727
- revive
98-
99-
# Somewhat similar to `bodyclose` but for `database/sql` package.
10028
- rowserrcheck
10129
- sqlclosecheck
102-
103-
# I have found that it's not the same as staticcheck binary :\
10430
- staticcheck
105-
106-
# Is a replacement for `golint`, similar to `revive`.
107-
- stylecheck
108-
109-
# Check struct tags.
110-
- tagliatelle
111-
112-
# Test-related checks. All of them are good.
113-
- tenv
11431
- testableexamples
11532
- thelper
11633
- tparallel
117-
118-
# Remove unnecessary type conversions, make code cleaner
11934
- unconvert
120-
121-
# Might be noisy but better to know what is unused
12235
- unparam
123-
124-
# Must have. Finds unused declarations.
12536
- unused
126-
127-
# Detect the possibility to use variables/constants from stdlib.
12837
- usestdlibvars
129-
130-
# Finds wasted assignment statements.
13138
- wastedassign
132-
133-
version: "2"
39+
exclusions:
40+
generated: lax
41+
presets:
42+
- comments
43+
- common-false-positives
44+
- legacy
45+
- std-error-handling
46+
paths:
47+
- third_party$
48+
- builtin$
49+
- examples$
50+
- integration/testdata
51+
- integration/testTarget
52+
- projects/builtInProjects
53+
settings:
54+
nolintlint:
55+
allow-unused: false
56+
allow-no-explanation: []
57+
require-explanation: true
58+
require-specific: true
59+
formatters:
60+
enable:
61+
- gofmt
62+
- gofumpt
63+
- goimports
64+
exclusions:
65+
generated: lax
66+
paths:
67+
- third_party$
68+
- builtin$
69+
- examples$

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2323
### Changed
2424

2525
- Update to new goMLX project structure (0.24.0+)
26-
- remove the depency on python when installing goMLX libraries
26+
- remove the dependency on python when installing goMLX libraries
2727

2828
## [0.5.5] - 2025-09-30
2929

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ following models:
217217
- **Gemma Family**: `onnx-community/gemma-3-1b-it-ONNX`, `onnx-community/gemma-3-270m-it-ONNX`
218218
- **Phi Family**: `microsoft/Phi-3-mini-4k-instruct-onnx`, `microsoft/Phi-3.5-mini-instruct-onnx`
219219

220-
Generative models typically use external weights, so use the downloadOptions.ExternalDataPath option when downloading the model. See the [example](./testData/downloadModels.go ) here.
220+
Generative models typically use external weights, so use the downloadOptions.ExternalDataPath option when downloading the model. See the [example](testdata/downloadModels.go ) here.
221221

222222
### Example Usage
223223
````go
@@ -316,7 +316,7 @@ We is currently supported only for the **FeatureExtractionPipeline**. This can b
316316
{"sentence1": "The quick brown fox jumps over the lazy dog", "sentence2": "A quick brown cow jumps over a lazy caterpillar", "score": 0.5}
317317
```
318318
319-
See the [example](./testData/semanticSimilarityTest.jsonl) for a sample dataset.
319+
See the [example](testdata/semanticSimilarityTest.jsonl) for a sample dataset.
320320
321321
The score is assumed to be a float between 0 and 1 that encodes the semantic similarity between the sentences, and by default a cosine similarity loss is used (see [sentence transformers](https://sbert.net/docs/package_reference/sentence_transformer/losses.html#cosinesimilarityloss)). However, you can also specify a different loss function from `goMLX` using the `XLATrainingOptions` field in the `TrainingConfig` struct. See [the training tests](./hugot_training_test.go) for examples on how to train or fine-tune feature extraction pipelines.
322322
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chatTemplates
1+
package chattemplates
22

33
import (
44
"strings"

cmd/main.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@ import (
1616
"sync"
1717

1818
"github.com/knights-analytics/hugot/options"
19-
"github.com/knights-analytics/hugot/pipelineBackends"
19+
"github.com/knights-analytics/hugot/pipelinebackends"
2020

2121
"github.com/urfave/cli/v3"
2222

2323
"github.com/knights-analytics/hugot"
24-
"github.com/knights-analytics/hugot/util"
24+
"github.com/knights-analytics/hugot/util/fileutil"
2525
)
2626

27-
var modelPath string
28-
var onnxFilename string
29-
var inputPath string
30-
var outputPath string
31-
var pipelineType string
32-
var sharedLibraryPath string
33-
var batchSize int
34-
var modelsDir string
27+
var (
28+
modelPath string
29+
onnxFilename string
30+
inputPath string
31+
outputPath string
32+
pipelineType string
33+
sharedLibraryPath string
34+
batchSize int
35+
modelsDir string
36+
)
3537

3638
var runCommand = &cli.Command{
3739
Name: "run",
@@ -104,22 +106,22 @@ var runCommand = &cli.Command{
104106
Value: "",
105107
},
106108
},
107-
Action: func(ctx context.Context, cmd *cli.Command) error {
109+
Action: func(ctx context.Context, _ *cli.Command) error {
108110
var opts []options.WithOption
109111
if modelsDir == "" {
110112
userDir, err := os.UserHomeDir()
111113
if err != nil {
112114
return err
113115
}
114-
modelsDir = util.PathJoinSafe(userDir, "hugot", "models")
116+
modelsDir = fileutil.PathJoinSafe(userDir, "hugot", "models")
115117
}
116118

117119
if sharedLibraryPath != "" {
118120
opts = append(opts, options.WithOnnxLibraryPath(sharedLibraryPath))
119121
} else {
120122
homeDir, err := os.UserHomeDir()
121123
if err != nil {
122-
if exists, err := util.FileExists(path.Join(homeDir, "lib", "hugot", "onnxruntime.so")); err != nil && exists {
124+
if exists, err := fileutil.FileExists(path.Join(homeDir, "lib", "hugot", "onnxruntime.so")); err != nil && exists {
123125
opts = append(opts, options.WithOnnxLibraryPath(path.Join(homeDir, "lib", "hugot", "onnxruntime.so")))
124126
}
125127
}
@@ -138,25 +140,25 @@ var runCommand = &cli.Command{
138140
}()
139141

140142
// is the model a full path to a model
141-
ok, err := util.FileExists(modelPath)
143+
ok, err := fileutil.FileExists(modelPath)
142144
if err != nil {
143145
return err
144146
}
145147
if !ok {
146148
// is the model the name of a model previously downloaded
147-
downloadedModelName := strings.Replace(modelPath, "/", "_", -1)
148-
ok, err = util.FileExists(util.PathJoinSafe(modelsDir, downloadedModelName))
149+
downloadedModelName := strings.ReplaceAll(modelPath, "/", "_")
150+
ok, err = fileutil.FileExists(fileutil.PathJoinSafe(modelsDir, downloadedModelName))
149151
if err != nil {
150152
return err
151153
}
152154
if ok {
153-
modelPath = util.PathJoinSafe(modelsDir, downloadedModelName)
155+
modelPath = fileutil.PathJoinSafe(modelsDir, downloadedModelName)
154156
} else {
155157
// is the model the name of a model to download
156158
if strings.Contains(modelPath, ":") {
157159
return fmt.Errorf("filters with : are currently not supported")
158160
}
159-
err = util.CreateFile(modelsDir, true)
161+
err = fileutil.CreateFile(modelsDir, true)
160162
if err != nil {
161163
return err
162164
}
@@ -167,7 +169,7 @@ var runCommand = &cli.Command{
167169
}
168170
}
169171

170-
var pipe pipelineBackends.Pipeline
172+
var pipe pipelinebackends.Pipeline
171173
switch pipelineType {
172174
case "tokenClassification":
173175
config := hugot.TokenClassificationConfig{
@@ -229,8 +231,8 @@ var runCommand = &cli.Command{
229231
var writer io.WriteCloser
230232

231233
if outputPath != "" {
232-
dest := util.PathJoinSafe(outputPath, fmt.Sprintf("result-%d.jsonl", i))
233-
writer, err = util.NewFileWriter(dest, "application/json")
234+
dest := fileutil.PathJoinSafe(outputPath, fmt.Sprintf("result-%d.jsonl", i))
235+
writer, err = fileutil.NewFileWriter(dest, "application/json")
234236
if err != nil {
235237
return err
236238
}
@@ -259,7 +261,7 @@ var runCommand = &cli.Command{
259261

260262
// read inputs
261263

262-
exists, err := util.FileExists(inputPath)
264+
exists, err := fileutil.FileExists(inputPath)
263265
if err != nil {
264266
return err
265267
}
@@ -277,7 +279,7 @@ var runCommand = &cli.Command{
277279
return true, nil
278280
}
279281

280-
err := util.WalkDir()(ctx, inputPath, fileWalker)
282+
err := fileutil.WalkDir()(ctx, inputPath, fileWalker)
281283
if err != nil {
282284
return err
283285
}
@@ -345,7 +347,7 @@ func writeOutputs(wg *sync.WaitGroup, processedChannel chan []byte, errorChannel
345347
wg.Done()
346348
}
347349

348-
func processWithPipeline(wg *sync.WaitGroup, inputChannel chan []input, processedChannel chan []byte, errorsChannel chan error, p pipelineBackends.Pipeline) {
350+
func processWithPipeline(wg *sync.WaitGroup, inputChannel chan []input, processedChannel chan []byte, errorsChannel chan error, p pipelinebackends.Pipeline) {
349351
for inputBatch := range inputChannel {
350352
inputStrings := make([]string, len(inputBatch))
351353
for i := 0; i < len(inputBatch); i++ {

cmd/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/urfave/cli/v3"
1414

15-
"github.com/knights-analytics/hugot/util"
15+
"github.com/knights-analytics/hugot/util/fileutil"
1616
)
1717

1818
//go:embed testData/textClassification.jsonl
@@ -147,7 +147,7 @@ func TestModelChain(t *testing.T) {
147147
// wipe the hugo folder
148148
userFolder, err := os.UserHomeDir()
149149
check(t, err)
150-
check(t, util.DeleteFile(util.PathJoinSafe(userFolder, "hugot")))
150+
check(t, fileutil.DeleteFile(fileutil.PathJoinSafe(userFolder, "hugot")))
151151

152152
// try to download the model to hugo folder and run it
153153
args := append(baseArgs, "run",

0 commit comments

Comments
 (0)