mirror of
https://code.forgejo.org/forgejo/act.git
synced 2025-04-19 08:22:16 +03:00
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
This commit is contained in:
parent
1e90052340
commit
733b614037
@ -51,6 +51,7 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- run: make lint-go
|
||||
- name: vet checks
|
||||
run: go vet -v ./...
|
||||
- name: build
|
||||
|
@ -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
|
||||
|
3
Makefile
3
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:
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -191,7 +191,6 @@ func TestParseRunWithInvalidArgs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
func TestParseWithVolumes(t *testing.T) {
|
||||
|
||||
// A single volume
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
|
@ -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{}{}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
@ -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]")
|
||||
|
@ -17,5 +17,15 @@
|
||||
"matchDepNames": ["github.com/rhysd/actionlint"],
|
||||
"separateMinorPatch": true
|
||||
}
|
||||
],
|
||||
"customManagers": [
|
||||
{
|
||||
"description": "Update deps inside Makefile",
|
||||
"customType": "regex",
|
||||
"fileMatch": ["^Makefile$"],
|
||||
"matchStrings": [
|
||||
" \\?= (?<depName>.+?)@(?<currentValue>.+?) # renovate: datasource=(?<datasource>.+?)(?: packageName=(?<packageName>.+?))?( versioning=(?<versioning>.+?))?\\s"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user