From 733b6140376e4c361110146c2c278bf309bf04ab Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 27 Dec 2024 09:27:41 +0100 Subject: chore(lint): fix lint errors - upgrade to golangci-lint@v1.62.2 - make it renovate friendly - remove most frequent lint check that are not of consequence (unused args, etc.) - fix remaining lint errors - add renovate custom manager to update the Makefile variable --- .forgejo/workflows/test.yml | 1 + .golangci.yml | 14 +++++++------- Makefile | 3 ++- pkg/common/git/git.go | 2 -- pkg/container/docker_cli.go | 2 +- pkg/container/docker_cli_test.go | 1 - pkg/container/host_environment.go | 2 +- pkg/exprparser/interpreter.go | 2 -- pkg/filecollector/file_collector.go | 1 - pkg/model/action.go | 4 ++-- pkg/model/planner.go | 2 -- pkg/model/workflow.go | 2 -- pkg/runner/action.go | 6 ++---- pkg/runner/expression.go | 2 -- pkg/runner/job_executor.go | 1 - pkg/runner/reusable_workflow.go | 18 ------------------ pkg/runner/run_context.go | 5 ++--- renovate.json | 10 ++++++++++ 18 files changed, 28 insertions(+), 50 deletions(-) diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml index b329fad..6cf9ddb 100644 --- a/.forgejo/workflows/test.yml +++ b/.forgejo/workflows/test.yml @@ -51,6 +51,7 @@ jobs: exit 1 fi + - run: make lint-go - name: vet checks run: go vet -v ./... - name: build diff --git a/.golangci.yml b/.golangci.yml index 4082864..12a114c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,9 +6,6 @@ skip-dirs: - report # megalinter results+fixes linters-settings: - gocyclo: - # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 15 gocritic: disabled-checks: - ifElseChain @@ -18,6 +15,10 @@ linters-settings: alias: log - pkg: 'github.com/stretchr/testify/assert' alias: assert + revive: + rules: + - name: unused-parameter + disabled: true depguard: rules: main: @@ -29,23 +30,22 @@ linters-settings: - pkg: log desc: Please keep logging unified using only github.com/sirupsen/logrus linters: + disable: + - staticcheck enable: - - megacheck - govet - - revive - gocyclo - gosec - unconvert - dupl - nakedret - prealloc - - exportloopref - gocritic + - gosimple - goimports - whitespace - misspell - depguard - importas - - contextcheck - nolintlint - revive diff --git a/Makefile b/Makefile index 97a57f7..80c3c53 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ MAJOR_VERSION = $(word 1, $(subst ., ,$(VERSION))) MINOR_VERSION = $(word 2, $(subst ., ,$(VERSION))) PATCH_VERSION = $(word 3, $(subst ., ,$(word 1,$(subst -, , $(VERSION))))) NEW_VERSION ?= $(MAJOR_VERSION).$(MINOR_VERSION).$(shell echo $$(( $(PATCH_VERSION) + 1)) ) +GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 # renovate: datasource=go fix = false ifeq (true,$(fix)) @@ -41,7 +42,7 @@ test: .PHONY: lint-go lint-go: - golangci-lint run $(FIX) + go run $(GOLANGCI_LINT_PACKAGE) run $(FIX) .PHONY: lint-js lint-js: diff --git a/pkg/common/git/git.go b/pkg/common/git/git.go index c7ee889..1050647 100644 --- a/pkg/common/git/git.go +++ b/pkg/common/git/git.go @@ -291,8 +291,6 @@ func gitOptions(token string) (fetchOptions git.FetchOptions, pullOptions git.Pu } // NewGitCloneExecutor creates an executor to clone git repos -// -//nolint:gocyclo func NewGitCloneExecutor(input NewGitCloneExecutorInput) common.Executor { return func(ctx context.Context) error { logger := common.Logger(ctx) diff --git a/pkg/container/docker_cli.go b/pkg/container/docker_cli.go index 82d3246..2f2d8b2 100644 --- a/pkg/container/docker_cli.go +++ b/pkg/container/docker_cli.go @@ -597,7 +597,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con BlkioDeviceReadIOps: copts.deviceReadIOps.GetList(), BlkioDeviceWriteIOps: copts.deviceWriteIOps.GetList(), IOMaximumIOps: copts.ioMaxIOps, - IOMaximumBandwidth: uint64(copts.ioMaxBandwidth), + IOMaximumBandwidth: uint64(copts.ioMaxBandwidth), //nolint:gosec Ulimits: copts.ulimits.GetList(), DeviceCgroupRules: copts.deviceCgroupRules.GetAll(), Devices: deviceMappings, diff --git a/pkg/container/docker_cli_test.go b/pkg/container/docker_cli_test.go index d871a89..f0b9657 100644 --- a/pkg/container/docker_cli_test.go +++ b/pkg/container/docker_cli_test.go @@ -191,7 +191,6 @@ func TestParseRunWithInvalidArgs(t *testing.T) { } } -//nolint:gocyclo func TestParseWithVolumes(t *testing.T) { // A single volume diff --git a/pkg/container/host_environment.go b/pkg/container/host_environment.go index b12e69f..48b2a67 100644 --- a/pkg/container/host_environment.go +++ b/pkg/container/host_environment.go @@ -62,7 +62,7 @@ func (e *HostEnvironment) Copy(destPath string, files ...*FileEntry) common.Exec if err := os.MkdirAll(filepath.Dir(filepath.Join(destPath, f.Name)), 0o777); err != nil { return err } - if err := os.WriteFile(filepath.Join(destPath, f.Name), []byte(f.Body), fs.FileMode(f.Mode)); err != nil { + if err := os.WriteFile(filepath.Join(destPath, f.Name), []byte(f.Body), fs.FileMode(f.Mode)); err != nil { //nolint:gosec return err } } diff --git a/pkg/exprparser/interpreter.go b/pkg/exprparser/interpreter.go index 021e5c9..576ee45 100644 --- a/pkg/exprparser/interpreter.go +++ b/pkg/exprparser/interpreter.go @@ -150,7 +150,6 @@ func (impl *interperterImpl) evaluateNode(exprNode actionlint.ExprNode) (interfa } } -//nolint:gocyclo func (impl *interperterImpl) evaluateVariable(variableNode *actionlint.VariableNode) (interface{}, error) { switch strings.ToLower(variableNode.Name) { case "github": @@ -580,7 +579,6 @@ func (impl *interperterImpl) evaluateLogicalCompare(compareNode *actionlint.Logi return nil, fmt.Errorf("Unable to compare incompatibles types '%s' and '%s'", leftValue.Kind(), rightValue.Kind()) } -//nolint:gocyclo func (impl *interperterImpl) evaluateFuncCall(funcCallNode *actionlint.FuncCallNode) (interface{}, error) { args := make([]reflect.Value, 0) diff --git a/pkg/filecollector/file_collector.go b/pkg/filecollector/file_collector.go index 8547bb7..7273621 100644 --- a/pkg/filecollector/file_collector.go +++ b/pkg/filecollector/file_collector.go @@ -124,7 +124,6 @@ func (*DefaultFs) Readlink(path string) (string, error) { return os.Readlink(path) } -//nolint:gocyclo func (fc *FileCollector) CollectFiles(ctx context.Context, submodulePath []string) filepath.WalkFunc { i, _ := fc.Fs.OpenGitIndex(path.Join(fc.SrcPath, path.Join(submodulePath...))) return func(file string, fi os.FileInfo, err error) error { diff --git a/pkg/model/action.go b/pkg/model/action.go index 2fc39db..88df6f1 100644 --- a/pkg/model/action.go +++ b/pkg/model/action.go @@ -23,14 +23,14 @@ func (a *ActionRunsUsing) UnmarshalYAML(unmarshal func(interface{}) error) error case ActionRunsUsingNode20, ActionRunsUsingNode16, ActionRunsUsingNode12, ActionRunsUsingDocker, ActionRunsUsingComposite, ActionRunsUsingGo: *a = format default: - return fmt.Errorf(fmt.Sprintf("The runs.using key in action.yml must be one of: %v, got %s", []string{ + return fmt.Errorf("The runs.using key in action.yml must be one of: %v, got %s", []string{ ActionRunsUsingComposite, ActionRunsUsingDocker, ActionRunsUsingNode12, ActionRunsUsingNode16, ActionRunsUsingNode20, ActionRunsUsingGo, - }, format)) + }, format) } return nil } diff --git a/pkg/model/planner.go b/pkg/model/planner.go index 2d68145..ce0e2bb 100644 --- a/pkg/model/planner.go +++ b/pkg/model/planner.go @@ -56,8 +56,6 @@ type WorkflowFiles struct { } // NewWorkflowPlanner will load a specific workflow, all workflows from a directory or all workflows from a directory and its subdirectories -// -//nolint:gocyclo func NewWorkflowPlanner(path string, noWorkflowRecurse bool) (WorkflowPlanner, error) { path, err := filepath.Abs(path) if err != nil { diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index 7bec766..eda6e08 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -386,8 +386,6 @@ func (j *Job) Matrix() map[string][]interface{} { // GetMatrixes returns the matrix cross product // It skips includes and hard fails excludes for non-existing keys -// -//nolint:gocyclo func (j *Job) GetMatrixes() ([]map[string]interface{}, error) { matrixes := make([]map[string]interface{}, 0) if j.Strategy != nil { diff --git a/pkg/runner/action.go b/pkg/runner/action.go index fd52c0b..b26e52a 100644 --- a/pkg/runner/action.go +++ b/pkg/runner/action.go @@ -213,14 +213,14 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction rc.execJobContainer(execArgs, *step.getEnv(), "", ""), )(ctx) default: - return fmt.Errorf(fmt.Sprintf("The runs.using key must be one of: %v, got %s", []string{ + return fmt.Errorf("The runs.using key must be one of: %v, got %s", []string{ model.ActionRunsUsingDocker, model.ActionRunsUsingNode12, model.ActionRunsUsingNode16, model.ActionRunsUsingNode20, model.ActionRunsUsingComposite, model.ActionRunsUsingGo, - }, action.Runs.Using)) + }, action.Runs.Using) } } } @@ -257,8 +257,6 @@ func removeGitIgnore(ctx context.Context, directory string) error { } // TODO: break out parts of function to reduce complexicity -// -//nolint:gocyclo func execAsDocker(ctx context.Context, step actionStep, actionName string, basedir string, localAction bool) error { logger := common.Logger(ctx) rc := step.getRunContext() diff --git a/pkg/runner/expression.go b/pkg/runner/expression.go index 412d1c0..ae3f145 100644 --- a/pkg/runner/expression.go +++ b/pkg/runner/expression.go @@ -403,7 +403,6 @@ func escapeFormatString(in string) string { return strings.ReplaceAll(strings.ReplaceAll(in, "{", "{{"), "}", "}}") } -//nolint:gocyclo func rewriteSubExpression(ctx context.Context, in string, forceFormat bool) (string, error) { if !strings.Contains(in, "${{") || !strings.Contains(in, "}}") { return in, nil @@ -470,7 +469,6 @@ func rewriteSubExpression(ctx context.Context, in string, forceFormat bool) (str return out, nil } -//nolint:gocyclo func getEvaluatorInputs(ctx context.Context, rc *RunContext, step step, ghc *model.GithubContext) map[string]interface{} { inputs := map[string]interface{}{} diff --git a/pkg/runner/job_executor.go b/pkg/runner/job_executor.go index 0a86683..ed40563 100644 --- a/pkg/runner/job_executor.go +++ b/pkg/runner/job_executor.go @@ -20,7 +20,6 @@ type jobInfo interface { result(result string) } -//nolint:contextcheck,gocyclo func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executor { steps := make([]common.Executor, 0) preSteps := make([]common.Executor, 0) diff --git a/pkg/runner/reusable_workflow.go b/pkg/runner/reusable_workflow.go index 717913f..9d87365 100644 --- a/pkg/runner/reusable_workflow.go +++ b/pkg/runner/reusable_workflow.go @@ -225,21 +225,3 @@ func newRemoteReusableWorkflowWithPlat(url, uses string) *remoteReusableWorkflow URL: url, } } - -// deprecated: use newRemoteReusableWorkflowWithPlat -func newRemoteReusableWorkflow(uses string) *remoteReusableWorkflow { - // GitHub docs: - // https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iduses - r := regexp.MustCompile(`^([^/]+)/([^/]+)/.github/workflows/([^@]+)@(.*)$`) - matches := r.FindStringSubmatch(uses) - if len(matches) != 5 { - return nil - } - return &remoteReusableWorkflow{ - Org: matches[1], - Repo: matches[2], - Filename: matches[3], - Ref: matches[4], - URL: "https://github.com", - } -} diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 6aaf2d8..3597ce6 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -391,7 +391,6 @@ func (rc *RunContext) startHostEnvironment() common.Executor { } } -//nolint:gocyclo func (rc *RunContext) startJobContainer() common.Executor { return func(ctx context.Context) error { logger := common.Logger(ctx) @@ -591,7 +590,7 @@ func (rc *RunContext) execJobContainer(cmd []string, env map[string]string, user } func (rc *RunContext) ApplyExtraPath(ctx context.Context, env *map[string]string) { - if rc.ExtraPath != nil && len(rc.ExtraPath) > 0 { + if len(rc.ExtraPath) > 0 { path := rc.JobContainer.GetPathVariableName() if rc.JobContainer.IsEnvironmentCaseInsensitive() { // On windows system Path and PATH could also be in the map @@ -939,7 +938,7 @@ func mergeMaps(maps ...map[string]string) map[string]string { return rtnMap } -// deprecated: use createSimpleContainerName +// Deprecated: use createSimpleContainerName func createContainerName(parts ...string) string { name := strings.Join(parts, "-") pattern := regexp.MustCompile("[^a-zA-Z0-9]") diff --git a/renovate.json b/renovate.json index de95ff5..133076f 100644 --- a/renovate.json +++ b/renovate.json @@ -17,5 +17,15 @@ "matchDepNames": ["github.com/rhysd/actionlint"], "separateMinorPatch": true } + ], + "customManagers": [ + { + "description": "Update deps inside Makefile", + "customType": "regex", + "fileMatch": ["^Makefile$"], + "matchStrings": [ + " \\?= (?.+?)@(?.+?) # renovate: datasource=(?.+?)(?: packageName=(?.+?))?( versioning=(?.+?))?\\s" + ] + } ] } -- cgit v1.2.3