Skip to content

Commit deb20e2

Browse files
committed
fix lint errors, improve UX
1 parent eda9d4f commit deb20e2

File tree

12 files changed

+1501
-789
lines changed

12 files changed

+1501
-789
lines changed

Makefile

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ deps:
3737
$(GOMOD) tidy
3838

3939
run-server: server
40-
./$(SERVER_BINARY) -git=/tmp/gitmdm-repo
40+
$(SERVER_BINARY) -git=/tmp/gitmdm-repo
4141

4242
run-agent: agent
43-
./$(AGENT_BINARY) -server=http://localhost:8080
43+
$(AGENT_BINARY) -server=http://localhost:8080
4444

4545
build-linux:
4646
GOOS=linux GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(SERVER_BINARY)-linux-amd64 $(SERVER_PATH)
@@ -82,61 +82,57 @@ help:
8282
@echo " make build-all - Build for all platforms"
8383
@echo " make ko-build - Build server container with ko"
8484
@echo " make ko-publish - Publish server container with ko"
85-
# BEGIN: lint-install .
86-
# http://github.com/codeGROOVE-dev/lint-install
85+
86+
# BEGIN: lint-install - POSIX-compliant version
87+
# Works with both BSD make and GNU make
8788

8889
.PHONY: lint
8990
lint: _lint
9091

91-
LINT_ARCH := $(shell uname -m)
92-
LINT_OS := $(shell uname)
93-
LINT_OS_LOWER := $(shell echo $(LINT_OS) | tr '[:upper:]' '[:lower:]')
94-
LINT_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
92+
# Use simple assignment for maximum compatibility
93+
LINT_ARCH != uname -m || echo x86_64
94+
LINT_OS != uname || echo Darwin
95+
LINT_ROOT = .
9596

96-
# shellcheck and hadolint lack arm64 native binaries: rely on x86-64 emulation
97-
ifeq ($(LINT_OS),Darwin)
98-
ifeq ($(LINT_ARCH),arm64)
99-
LINT_ARCH=x86_64
100-
endif
101-
endif
97+
LINTERS =
98+
FIXERS =
10299

103-
LINTERS :=
104-
FIXERS :=
100+
GOLANGCI_LINT_CONFIG = $(LINT_ROOT)/.golangci.yml
101+
GOLANGCI_LINT_VERSION = v2.3.1
102+
GOLANGCI_LINT_BIN = $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
105103

106-
GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml
107-
GOLANGCI_LINT_VERSION ?= v2.3.1
108-
GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
109104
$(GOLANGCI_LINT_BIN):
110105
mkdir -p $(LINT_ROOT)/out/linters
111106
rm -rf $(LINT_ROOT)/out/linters/golangci-lint-*
112107
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LINT_ROOT)/out/linters $(GOLANGCI_LINT_VERSION)
113-
mv $(LINT_ROOT)/out/linters/golangci-lint $@
108+
mv $(LINT_ROOT)/out/linters/golangci-lint $(GOLANGCI_LINT_BIN)
114109

115110
LINTERS += golangci-lint-lint
116111
golangci-lint-lint: $(GOLANGCI_LINT_BIN)
117-
find . -name go.mod -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLANGCI_LINT_CONFIG)" \;
112+
find . -name go.mod -execdir $(GOLANGCI_LINT_BIN) run -c $(GOLANGCI_LINT_CONFIG) \;
118113

119114
FIXERS += golangci-lint-fix
120115
golangci-lint-fix: $(GOLANGCI_LINT_BIN)
121-
find . -name go.mod -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLANGCI_LINT_CONFIG)" --fix \;
116+
find . -name go.mod -execdir $(GOLANGCI_LINT_BIN) run -c $(GOLANGCI_LINT_CONFIG) --fix \;
117+
118+
YAMLLINT_VERSION = 1.37.1
119+
YAMLLINT_ROOT = $(LINT_ROOT)/out/linters/yamllint-$(YAMLLINT_VERSION)
120+
YAMLLINT_BIN = $(YAMLLINT_ROOT)/dist/bin/yamllint
122121

123-
YAMLLINT_VERSION ?= 1.37.1
124-
YAMLLINT_ROOT := $(LINT_ROOT)/out/linters/yamllint-$(YAMLLINT_VERSION)
125-
YAMLLINT_BIN := $(YAMLLINT_ROOT)/dist/bin/yamllint
126122
$(YAMLLINT_BIN):
127123
mkdir -p $(LINT_ROOT)/out/linters
128124
rm -rf $(LINT_ROOT)/out/linters/yamllint-*
129125
curl -sSfL https://github.com/adrienverge/yamllint/archive/refs/tags/v$(YAMLLINT_VERSION).tar.gz | tar -C $(LINT_ROOT)/out/linters -zxf -
130-
cd $(YAMLLINT_ROOT) && pip3 install --target dist . || pip install --target dist .
126+
cd $(YAMLLINT_ROOT) && (pip3 install --target dist . || pip install --target dist .)
131127

132128
LINTERS += yamllint-lint
133129
yamllint-lint: $(YAMLLINT_BIN)
134-
PYTHONPATH=$(YAMLLINT_ROOT)/dist $(YAMLLINT_ROOT)/dist/bin/yamllint .
130+
PYTHONPATH=$(YAMLLINT_ROOT)/dist $(YAMLLINT_BIN) .
135131

136132
.PHONY: _lint $(LINTERS)
137133
_lint: $(LINTERS)
138134

139135
.PHONY: fix $(FIXERS)
140136
fix: $(FIXERS)
141137

142-
# END: lint-install .
138+
# END: lint-install

cmd/agent/executeCheck.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func (a *Agent) executeCheck(ctx context.Context, checkName string, rule config.CommandRule) gitmdm.CommandOutput {
1818
// Handle file checks
1919
if rule.File != "" {
20-
return a.readFile(ctx, checkName, rule)
20+
return a.readFile(checkName, rule)
2121
}
2222

2323
// Handle command checks
@@ -33,7 +33,7 @@ func (a *Agent) executeCheck(ctx context.Context, checkName string, rule config.
3333
}
3434

3535
// readFile reads a file and returns its contents as a CommandOutput.
36-
func (a *Agent) readFile(ctx context.Context, checkName string, rule config.CommandRule) gitmdm.CommandOutput {
36+
func (*Agent) readFile(checkName string, rule config.CommandRule) gitmdm.CommandOutput {
3737
start := time.Now()
3838

3939
if *debug {

cmd/agent/executeCommand.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"time"
1515
)
1616

17-
// getSecurePath returns a secure PATH based on the OS
17+
// getSecurePath returns a secure PATH based on the OS.
1818
func getSecurePath() string {
1919
switch runtime.GOOS {
2020
case "windows":

0 commit comments

Comments
 (0)