Skip to content

Commit 053d730

Browse files
committed
feat: Basic linting config
1 parent 4ec3e97 commit 053d730

File tree

9 files changed

+82
-14
lines changed

9 files changed

+82
-14
lines changed

.github/workflows/lint.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Lint
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
- "test/**"
7+
- "release/**"
8+
pull_request:
9+
branches:
10+
- main
11+
paths:
12+
- "**.go"
13+
- "go.*"
14+
permissions:
15+
contents: read
16+
jobs:
17+
test:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
25+
with:
26+
go-version: "1.23.2"
27+
28+
- name: Format code
29+
run: |
30+
make format
31+
git diff --exit-code ||
32+
(echo "Code is not formatted. Please run 'make format' and commit the changes." && exit 1)
33+
34+
- name: golangci-lint
35+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
36+
with:
37+
version: v2.2.2
38+
39+
timeout-minutes: 10

.golangci.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "2"
2+
linters:
3+
default: none
4+
enable:
5+
# - errcheck
6+
- govet
7+
- ineffassign
8+
- staticcheck
9+
- unused
10+
formatters:
11+
enable:
12+
- gofmt
13+
# - goimports

.mise.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ backend = "core:go"
66
"go1.23.10.darwin-arm64.tar.gz" = "sha256:25c64bfa8a8fd8e7f62fb54afa4354af8409a4bb2358c2699a1003b733e6fce5"
77
"go1.23.10.linux-amd64.tar.gz" = "sha256:535f9f81802499f2a7dbfa70abb8fda3793725fcc29460f719815f6e10b5fd60"
88

9+
[tools.golangci-lint]
10+
version = "2.2.2"
11+
backend = "aqua:golangci/golangci-lint"
12+
13+
[tools.golangci-lint.checksums]
14+
"golangci-lint-2.2.2-linux-amd64.tar.gz" = "sha256:c27fbde948a87d326feacd21df2f61a9c54dbd2e3bfa185c0a1cd6917a6f964f"
15+
916
[tools.protoc]
1017
version = "27.3"
1118
backend = "aqua:protocolbuffers/protobuf/protoc"

.mise.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ experimental = true
33

44
[tools]
55
go = "1.23"
6+
golangci-lint = "2.2.2"
67
protoc = "27.3"
78
protoc-gen-go = "1.34.2"
89
protoc-gen-go-grpc = "1.5.1"

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ test-clean:
8989
vet:
9090
go vet ./...
9191

92+
.PHONY: format
93+
format:
94+
go fmt ./...
95+
96+
.PHONY: lint
97+
lint:
98+
golangci-lint run
99+
92100
.PHONY: docs-image-push
93101
docs-image:
94102
docker buildx build --push --platform linux/amd64,linux/arm64 -t "$(DOCS_IMAGE)" ./docs

internal/machine/docker/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ func NewServer(cli *client.Client, db *sqlx.DB, internalDNSIP func() netip.Addr,
8080
db: db,
8181
internalDNSIP: internalDNSIP,
8282
}
83-
83+
8484
for _, opt := range opts {
8585
opt(s)
8686
}
87-
87+
8888
return s
8989
}
9090

internal/machine/machine.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func NewMachine(config *Config) (*Machine, error) {
251251
internalDNSIP := func() netip.Addr {
252252
return m.IP()
253253
}
254-
m.docker = machinedocker.NewServer(dockerCli, db, internalDNSIP,
254+
m.docker = machinedocker.NewServer(dockerCli, db, internalDNSIP,
255255
machinedocker.WithNetworkReady(m.IsNetworkReady),
256256
machinedocker.WithWaitForNetworkReady(m.WaitForNetworkReady))
257257
m.localMachineServer = newGRPCServer(m, c, m.docker)
@@ -373,7 +373,7 @@ func (m *Machine) Run(ctx context.Context) error {
373373
// It can be reset when leaving the cluster and then re-initialised again with a new configuration.
374374
case <-m.initialised:
375375
var err error
376-
376+
377377
// Reset networkReady channel for the new cluster configuration
378378
m.networkReadyMu.Lock()
379379
m.networkReady = make(chan struct{})
@@ -800,11 +800,11 @@ func (m *Machine) IsNetworkReady() bool {
800800
// If machine is not initialized, there's no network to check
801801
return true
802802
}
803-
803+
804804
// Check if network is ready by checking if the networkReady channel has been closed
805805
m.networkReadyMu.RLock()
806806
defer m.networkReadyMu.RUnlock()
807-
807+
808808
select {
809809
case <-m.networkReady:
810810
return true
@@ -820,12 +820,12 @@ func (m *Machine) WaitForNetworkReady(ctx context.Context) error {
820820
// If machine is not initialized, there's no network to wait for
821821
return nil
822822
}
823-
823+
824824
// Get a copy of the channel to wait on
825825
m.networkReadyMu.RLock()
826826
networkReady := m.networkReady
827827
m.networkReadyMu.RUnlock()
828-
828+
829829
// Wait for network to be ready or context to be cancelled
830830
select {
831831
case <-networkReady:

internal/machine/network/wireguard_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (n *WireGuardNetwork) configureDevice(config Config) error {
129129
// rotations and connection disruptions.
130130
n.peers = make(map[string]*peer, len(config.Peers))
131131
wgPeers := make(map[string]*wgtypes.Peer, len(dev.Peers))
132-
for i, _ := range dev.Peers {
132+
for i := range dev.Peers {
133133
wgPeers[secret.Secret(dev.Peers[i].PublicKey[:]).String()] = &dev.Peers[i]
134134
}
135135
for _, pc := range config.Peers {

pkg/client/compose/project.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package compose
55
import (
66
"context"
77
"fmt"
8-
8+
99
composecli "github.com/compose-spec/compose-go/v2/cli"
1010
"github.com/compose-spec/compose-go/v2/types"
1111
)
@@ -27,23 +27,23 @@ func LoadProject(ctx context.Context, paths []string, opts ...composecli.Project
2727
composecli.WithExtension(PortsExtensionKey, PortsSource{}),
2828
composecli.WithExtension(MachinesExtensionKey, MachinesSource{}),
2929
}
30-
30+
3131
options, err := composecli.NewProjectOptions(
3232
paths,
3333
append(defaultOpts, opts...)...,
3434
)
3535
if err != nil {
3636
return nil, fmt.Errorf("create compose parser options: %w", err)
3737
}
38-
38+
3939
project, err := options.LoadProject(ctx)
4040
if err != nil {
4141
return nil, err
4242
}
43-
43+
4444
if project, err = transformServicesPortsExtension(project); err != nil {
4545
return nil, err
4646
}
47-
47+
4848
return project, nil
4949
}

0 commit comments

Comments
 (0)