Skip to content

Fix the linter #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ jobs:
- name: Check go.mod/go.sum to be consistent
run: go mod tidy -v && git diff --exit-code

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
skip-cache: true
only-new-issues: false
args: --verbose
- name: Run linter
run: |
make lint
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/build/cache/*
test/rigtest
test/footloose.yaml
test/Library
test/.ssh
test/*.iid
/.rigbuild.docker-image.k0s
47 changes: 40 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
GO_TESTS := $(shell find . -type f -name '*_test.go')
INT_TESTS := $(shell git ls-files test/)

alpine_version = 3.21
alpine_patch_version = $(alpine_version).3
go_version = 1.24.2
golang_buildimage=docker.io/library/golang:$(go_version)-alpine$(alpine_version)

GOLANG_IMAGE ?= $(golang_buildimage)

RIG_GO_BUILD_CACHE ?= build/cache
DOCKER ?= docker
BUILD_UID ?= $(shell id -u)
BUILD_GID ?= $(shell id -g)

$(RIG_GO_BUILD_CACHE):
mkdir -p -- '$@'

.rigbuild.docker-image.k0s: build/Dockerfile | $(RIG_GO_BUILD_CACHE)
$(DOCKER) build --progress=plain --iidfile '$@' \
--build-arg BUILDIMAGE=$(GOLANG_IMAGE) \
-t rigbuild.docker-image.k0s - <build/Dockerfile

GO_ENV ?= $(DOCKER) run --rm \
-v '$(realpath $(RIG_GO_BUILD_CACHE))':/run/k0s-build \
-v '$(CURDIR)':/go/src/github.com/k0sproject/rig \
-w /go/src/github.com/k0sproject/rig \
-e GOOS \
-e CGO_ENABLED \
-e CGO_CFLAGS \
-e GOARCH \
--user $(BUILD_UID):$(BUILD_GID) \
-- '$(shell cat .rigbuild.docker-image.k0s)'
GO ?= $(GO_ENV) go

gotest := $(shell which gotest)
ifeq ($(gotest),)
gotest := go test
Expand All @@ -14,13 +46,14 @@ test: $(GO_SRCS) $(GO_TESTS)
inttest: $(GO_SRCS} $(INT_TESTS)
$(MAKE) -C test

ifeq ($(FIX),true)
fixparam := --fix
else
fixparam :=
endif
GO_LINT_DIRS ?= $(shell ls -d */ | grep -v build/)

.PHONY: lint
lint:
golangci-lint run -v $(fixparam)
lint: .rigbuild.docker-image.k0s
$(GO) install github.com/golangci/golangci-lint/cmd/[email protected]
$(GO_ENV) golangci-lint run --verbose --build-tags=$(subst $(space),$(comma),$(BUILD_GO_TAGS)) $(GOLANGCI_LINT_FLAGS) $(GO_LINT_DIRS)

.PHONY: clean-gocache
clean-gocache:
-chmod -R u+w -- '$(RIG_GO_BUILD_CACHE)/go/mod'
rm -rf -- '$(RIG_GO_BUILD_CACHE)/go'
22 changes: 22 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ARG BUILDIMAGE
FROM $BUILDIMAGE

ARG TARGETARCH
RUN set -ex; \
if [ ! -z "$(which apt)" ]; then \
apt update && apt install -y git; \
elif [ ! -z "$(which apk)" ]; then \
apk add --no-cache git; \
else \
echo "unsupported package manager"; \
exit 1; \
fi


ENV \
HOME="/run/k0s-build" \
PATH="/run/k0s-build/go/bin:$PATH" \
GOBIN="/run/k0s-build/go/bin" \
GOCACHE="/run/k0s-build/go/build" \
GOMODCACHE="/run/k0s-build/go/mod" \
GOTELEMETRY="off"
4 changes: 2 additions & 2 deletions protocol/ssh/signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func termSizeWNCH() []byte {
binary.BigEndian.PutUint32(size, 40)
binary.BigEndian.PutUint32(size[4:], 80)
} else {
binary.BigEndian.PutUint32(size, uint32(cols))
binary.BigEndian.PutUint32(size[4:], uint32(rows))
binary.BigEndian.PutUint32(size, uint32(cols)) // #nosec G115 -- ignore "integer overflow conversion int -> uint32"
binary.BigEndian.PutUint32(size[4:], uint32(rows)) // #nosec G115 -- ignore "integer overflow conversion int -> uint32"
}

return size
Expand Down
3 changes: 2 additions & 1 deletion remotefs/posixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ func posixBitsToFileMode(bits int64) fs.FileMode {
}

// Mapping permission bits
mode |= fs.FileMode(bits & 0o777) // Owner, group, and other permissions
// Owner, group, and other permissions
mode |= fs.FileMode(bits & 0o777) // #nosec G115 -- ignore "integer overflow conversion int64 -> uint64"

// Mapping special permission bits
if bits&0o4000 != 0 { // Set-user-ID
Expand Down
24 changes: 16 additions & 8 deletions remotefs/withname.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ package remotefs
import "io/fs"

const (
OpClose = "close" // OpClose Close operation
OpOpen = "open" // OpOpen Open operation
OpRead = "read" // OpRead Read operation
OpSeek = "seek" // OpSeek Seek operation
OpStat = "stat" // OpStat Stat operation
OpWrite = "write" // OpWrite Write operation
OpCopyTo = "copy-to" // OpCopyTo CopyTo operation
OpCopyFrom = "copy-from" // OpCopyFrom CopyFrom operation
// OpClose Close operation.
OpClose = "close"
// OpOpen Open operation.
OpOpen = "open"
// OpRead Read operation.
OpRead = "read"
// OpSeek Seek operation.
OpSeek = "seek"
// OpStat Stat operation.
OpStat = "stat"
// OpWrite Write operation.
OpWrite = "write"
// OpCopyTo CopyTo operation.
OpCopyTo = "copy-to"
// OpCopyFrom CopyFrom operation.
OpCopyFrom = "copy-from"
)

type withPath struct {
Expand Down
4 changes: 2 additions & 2 deletions sshconfig/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ func (p *printer) number(key string) (string, bool) {
}
if field, err := p.get(key, reflect.Uint); err == nil {
if key == "StreamLocalBindMask" {
return "0" + strconv.FormatInt(int64(field.Uint()), 8), true
return "0" + strconv.FormatInt(int64(field.Uint()), 8), true // #nosec G115 -- ignore "integer overflow conversion int64 -> uint64"
}
return strconv.FormatInt(int64(field.Uint()), 10), true
return strconv.FormatInt(int64(field.Uint()), 10), true // #nosec G115 -- ignore "integer overflow conversion int64 -> uint64"
}
return "", false
}
Expand Down
6 changes: 3 additions & 3 deletions sshconfig/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ func (s *Setter) expandToken(token string) (string, error) { //nolint:cyclop

if f, err := s.get("Port", reflect.Uint); err == nil {
if f.Uint() > 0 {
return strconv.Itoa(int(f.Uint())), nil
return strconv.Itoa(int(f.Uint())), nil // #nosec G115 -- ignore "integer overflow conversion uint64 -> int"
}
}
if f, err := s.get("Port", reflect.String); err == nil {
Expand Down Expand Up @@ -1349,7 +1349,7 @@ func (s *Setter) matchesHost(conditions ...string) (bool, error) {
// matchesMatch checks if the Match directive conditions are met.
func (s *Setter) matchesMatch(conditions ...string) (bool, error) { //nolint:funlen,cyclop // TODO extract functions
log.Trace(context.Background(), "matching Match directive", "conditions", conditions)
for i := range len(conditions) {
for i := range conditions {
condition := conditions[i]
log.Trace(context.Background(), "matching Match directive", "condition", condition)
var negate bool
Expand Down Expand Up @@ -1607,7 +1607,7 @@ func (s *Setter) canonicalizeMaxDots() int {
if md, err := s.get("CanonicalizeMaxDots", reflect.Int); err == nil {
return int(md.Int())
} else if md, err := s.get("CanonicalizeMaxDots", reflect.Uint); err == nil {
return int(md.Uint())
return int(md.Uint()) // #nosec G115 -- ignore "integer overflow conversion int64 -> uint64"
}
return 1
}
Expand Down
Loading