Skip to content

Commit d5b2cf1

Browse files
authored
linters: Add modernise tool check and fix issues (#2012)
* linters: Add modernise tool check and fix issues * engine: Simplify exch.SetDefaults call and remove localWG * CI: Revert config versions lint workflow
1 parent 85403fe commit d5b2cf1

File tree

22 files changed

+103
-159
lines changed

22 files changed

+103
-159
lines changed

.github/workflows/config-versions-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ jobs:
1313
with:
1414
go-version: ${{ env.GO_VERSION }}
1515
- name: Check config versions are continuous
16-
run: go test ./config/versions/ -tags config_versions -run Continuity
16+
run: go test ./config/versions/ -tags config_versions -run Continuity

.github/workflows/configs-json-lint.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/misc.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ jobs:
66
runs-on: ubuntu-latest
77
steps:
88
- uses: actions/checkout@v5
9+
- name: Setup Go
10+
uses: actions/setup-go@v5
11+
with:
12+
go-version: 1.25.x
13+
914
- name: Check for currency.NewPair(BTC, USD) used instead of currency.NewBTCUSD
1015
run: |
1116
grep -r -n --color=always -E "currency.NewPair\(currency.BTC, currency.USDT?\)" * || exit 0
@@ -62,4 +67,24 @@ jobs:
6267
grep -r -n -I --color=always --exclude-dir=.git -P "$PATTERN" . || exit 0
6368
echo "::error::Remove zero-width/format, separator or combining-mark characters"
6469
exit 1
70+
71+
- name: Check configs JSON format
72+
run: |
73+
files=("config_example.json" "testdata/configtest.json")
74+
for file in "${files[@]}"; do
75+
processed_file="${file%.*}_processed.${file##*.}"
76+
jq '.exchanges |= sort_by(.name)' --indent 1 $file > $processed_file
77+
if ! diff $file $processed_file; then
78+
echo "jq differences found in $file! Please run 'make lint_configs'"
79+
exit 1
80+
else
81+
rm $processed_file
82+
echo "No differences found in $file 🌞"
83+
fi
84+
done
85+
86+
- name: Check Go modernise tool issues
87+
run: |
88+
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test ./...
89+
6590

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ DRIVER ?= psql
1111
RACE_FLAG := $(if $(NO_RACE_TEST),,-race)
1212
CONFIG_FLAG = $(if $(CONFIG),-config $(CONFIG),)
1313

14-
.PHONY: all lint lint_docker check test build install fmt gofumpt update_deps
14+
.PHONY: all lint lint_docker check test build install fmt gofumpt update_deps modernise
1515

1616
all: check build
1717

@@ -41,6 +41,10 @@ gofumpt:
4141
@command -v gofumpt >/dev/null 2>&1 || go install mvdan.cc/gofumpt@latest
4242
$(GOFUMPTBIN) -l -w $(GO_FILES_TO_FORMAT)
4343

44+
modernise:
45+
@command -v modernize >/dev/null 2>&1 || go install golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest
46+
modernize -test ./...
47+
4448
update_deps:
4549
go mod verify
4650
go mod tidy

backtester/engine/backtest.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,20 @@ func (bt *BackTest) RunLive() error {
8181
if bt.LiveDataHandler == nil {
8282
return errLiveOnly
8383
}
84-
var err error
8584
if bt.LiveDataHandler.IsRealOrders() {
86-
err = bt.LiveDataHandler.UpdateFunding(false)
87-
if err != nil {
85+
if err := bt.LiveDataHandler.UpdateFunding(false); err != nil {
8886
return err
8987
}
9088
}
91-
err = bt.LiveDataHandler.Start()
92-
if err != nil {
89+
if err := bt.LiveDataHandler.Start(); err != nil {
9390
return err
9491
}
95-
bt.wg.Add(1)
96-
go func() {
97-
err = bt.liveCheck()
98-
if err != nil {
92+
93+
bt.wg.Go(func() {
94+
if err := bt.liveCheck(); err != nil {
9995
log.Errorln(common.LiveStrategy, err)
10096
}
101-
bt.wg.Done()
102-
}()
97+
})
10398

10499
return nil
105100
}

backtester/engine/backtest_test.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,37 +1321,27 @@ func TestLiveLoop(t *testing.T) {
13211321

13221322
// dataUpdated case
13231323
var wg sync.WaitGroup
1324-
wg.Add(1)
1325-
go func() {
1326-
err = bt.liveCheck()
1327-
assert.NoError(t, err)
1328-
1329-
wg.Done()
1330-
}()
1324+
wg.Go(func() {
1325+
assert.NoError(t, bt.liveCheck())
1326+
})
13311327
dc.dataUpdated <- true
13321328
dc.shutdown <- true
13331329
wg.Wait()
13341330

13351331
// shutdown from error case
1336-
wg.Add(1)
13371332
dc.started = 0
1338-
go func() {
1339-
defer wg.Done()
1340-
err = bt.liveCheck()
1341-
assert.NoError(t, err)
1342-
}()
1333+
wg.Go(func() {
1334+
assert.NoError(t, bt.liveCheck())
1335+
})
13431336
dc.shutdownErr <- true
13441337
wg.Wait()
13451338

13461339
// shutdown case
13471340
dc.started = 1
13481341
bt.shutdown = make(chan struct{})
1349-
wg.Add(1)
1350-
go func() {
1351-
defer wg.Done()
1352-
err = bt.liveCheck()
1353-
assert.NoError(t, err)
1354-
}()
1342+
wg.Go(func() {
1343+
assert.NoError(t, bt.liveCheck())
1344+
})
13551345
dc.shutdown <- true
13561346
wg.Wait()
13571347

backtester/engine/live_test.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,9 @@ func TestLiveHandlerStopFromError(t *testing.T) {
135135

136136
dc.started = 1
137137
var wg sync.WaitGroup
138-
wg.Add(1)
139-
go func() {
140-
defer wg.Done()
141-
err = dc.SignalStopFromError(errNoCredsNoLive)
142-
assert.NoError(t, err)
143-
}()
138+
wg.Go(func() {
139+
assert.NoError(t, dc.SignalStopFromError(errNoCredsNoLive))
140+
})
144141
wg.Wait()
145142

146143
var dh *dataChecker
@@ -177,19 +174,15 @@ func TestUpdated(t *testing.T) {
177174
dataUpdated: make(chan bool, 10),
178175
}
179176
var wg sync.WaitGroup
180-
wg.Add(1)
181-
go func() {
177+
wg.Go(func() {
182178
_ = dc.Updated()
183-
wg.Done()
184-
}()
179+
})
185180
wg.Wait()
186181

187182
dc = nil
188-
wg.Add(1)
189-
go func() {
183+
wg.Go(func() {
190184
_ = dc.Updated()
191-
wg.Done()
192-
}()
185+
})
193186
wg.Wait()
194187
}
195188

cmd/exchange_wrapper_coverage/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ func main() {
3434
var wg sync.WaitGroup
3535
for i := range exchange.Exchanges {
3636
name := exchange.Exchanges[i]
37-
wg.Add(1)
38-
go func() {
39-
defer wg.Done()
37+
wg.Go(func() {
4038
if err := engine.Bot.LoadExchange(name); err != nil {
4139
log.Printf("Failed to load exchange %s. Err: %s", name, err)
4240
}
43-
}()
41+
})
4442
}
4543
wg.Wait()
4644
log.Println("Done.")

cmd/exchange_wrapper_issues/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,11 @@ func main() {
7474
wrapperConfig.Exchanges[strings.ToLower(name)] = &config.APICredentialsConfig{}
7575
}
7676
if shouldLoadExchange(name) {
77-
wg.Add(1)
78-
go func() {
79-
defer wg.Done()
77+
wg.Go(func() {
8078
if err = bot.LoadExchange(name); err != nil {
8179
log.Printf("Failed to load exchange %s. Err: %s", name, err)
8280
}
83-
}()
81+
})
8482
}
8583
}
8684
wg.Wait()

docs/CODING_GUIDELINES.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,22 @@ Run the following after completing changes:
179179

180180
This ensures proper formatting across the codebase.
181181

182-
## Linters
182+
## Linters and other miscellaneous checks
183183

184184
Run the following to check for linting issues:
185185

186186
```console
187187
golangci-lint run ./... (or make lint)
188188
```
189189

190+
Run the following tool to check for Go modernise issues:
191+
192+
```console
193+
make modernise
194+
```
195+
196+
Several other miscellaneous checks will be ran via [GitHub actions](/.github/workflows/misc.yml).
197+
190198
- All lint warnings and errors must be resolved before merging.
191199
- Use `//nolint:linter-name` sparingly and always explain the reason in a comment next to the code.
192200
- Examples of valid use:

0 commit comments

Comments
 (0)