chore: upgrade golangci-lint and address findings (#1904)

This commit is contained in:
Casey Lee 2023-07-10 17:12:12 -07:00 committed by GitHub
parent 79f93beef2
commit 724ec918c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 57 additions and 59 deletions

View file

@ -25,7 +25,8 @@ jobs:
check-latest: true check-latest: true
- uses: golangci/golangci-lint-action@v3.6.0 - uses: golangci/golangci-lint-action@v3.6.0
with: with:
version: v1.47.2 version: v1.53
only-new-issues: true
- uses: megalinter/megalinter/flavors/go@v7.1.0 - uses: megalinter/megalinter/flavors/go@v7.1.0
env: env:
DEFAULT_BRANCH: master DEFAULT_BRANCH: master

View file

@ -19,17 +19,15 @@ linters-settings:
- pkg: 'github.com/stretchr/testify/assert' - pkg: 'github.com/stretchr/testify/assert'
alias: assert alias: assert
depguard: depguard:
list-type: blacklist rules:
include-go-root: true main:
packages: deny:
- github.com/pkg/errors - pkg: github.com/pkg/errors
- gotest.tools/v3/assert desc: Please use "errors" package from standard library
- log - pkg: gotest.tools/v3
packages-with-error-message: desc: Please keep tests unified using only github.com/stretchr/testify
- github.com/pkg/errors: 'Please use "errors" package from standard library' - pkg: log
- gotest.tools/v3: 'Please keep tests unified using only github.com/stretchr/testify' desc: Please keep logging unified using only github.com/sirupsen/logrus
- log: 'Please keep logging unified using only github.com/sirupsen/logrus'
linters: linters:
enable: enable:
- megacheck - megacheck

View file

@ -273,7 +273,7 @@ func readArgsFile(file string, split bool) []string {
return args return args
} }
func setup(inputs *Input) func(*cobra.Command, []string) { func setup(_ *Input) func(*cobra.Command, []string) {
return func(cmd *cobra.Command, _ []string) { return func(cmd *cobra.Command, _ []string) {
verbose, _ := cmd.Flags().GetBool("verbose") verbose, _ := cmd.Flags().GetBool("verbose")
if verbose { if verbose {
@ -343,13 +343,12 @@ func parseMatrix(matrix []string) map[string]map[string]bool {
matrix := r.Split(m, 2) matrix := r.Split(m, 2)
if len(matrix) < 2 { if len(matrix) < 2 {
log.Fatalf("Invalid matrix format. Failed to parse %s", m) log.Fatalf("Invalid matrix format. Failed to parse %s", m)
} else { }
if _, ok := matrixes[matrix[0]]; !ok { if _, ok := matrixes[matrix[0]]; !ok {
matrixes[matrix[0]] = make(map[string]bool) matrixes[matrix[0]] = make(map[string]bool)
} }
matrixes[matrix[0]][matrix[1]] = true matrixes[matrix[0]][matrix[1]] = true
} }
}
return matrixes return matrixes
} }

View file

@ -79,7 +79,7 @@ func (fwfs readWriteFSImpl) OpenAppendable(name string) (WritableFile, error) {
return nil, err return nil, err
} }
_, err = file.Seek(0, os.SEEK_END) _, err = file.Seek(0, io.SeekEnd)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -174,7 +174,7 @@ func FindGithubRepo(ctx context.Context, file, githubInstance, remoteName string
return slug, err return slug, err
} }
func findGitRemoteURL(ctx context.Context, file, remoteName string) (string, error) { func findGitRemoteURL(_ context.Context, file, remoteName string) (string, error) {
repo, err := git.PlainOpenWithOptions( repo, err := git.PlainOpenWithOptions(
file, file,
&git.PlainOpenOptions{ &git.PlainOpenOptions{

View file

@ -604,7 +604,7 @@ func (cr *containerReference) tryReadGID() common.Executor {
return cr.tryReadID("-g", func(id int) { cr.GID = id }) return cr.tryReadID("-g", func(id int) { cr.GID = id })
} }
func (cr *containerReference) waitForCommand(ctx context.Context, isTerminal bool, resp types.HijackedResponse, idResp types.IDResponse, user string, workdir string) error { func (cr *containerReference) waitForCommand(ctx context.Context, isTerminal bool, resp types.HijackedResponse, _ types.IDResponse, _ string, _ string) error {
logger := common.Logger(ctx) logger := common.Logger(ctx)
cmdResponse := make(chan error) cmdResponse := make(chan error)

View file

@ -78,7 +78,7 @@ type endlessReader struct {
io.Reader io.Reader
} }
func (r endlessReader) Read(p []byte) (n int, err error) { func (r endlessReader) Read(_ []byte) (n int, err error) {
return 1, nil return 1, nil
} }

View file

@ -34,7 +34,7 @@ type HostEnvironment struct {
StdOut io.Writer StdOut io.Writer
} }
func (e *HostEnvironment) Create(capAdd []string, capDrop []string) common.Executor { func (e *HostEnvironment) Create(_ []string, _ []string) common.Executor {
return func(ctx context.Context) error { return func(ctx context.Context) error {
return nil return nil
} }
@ -140,13 +140,13 @@ func (e *HostEnvironment) GetContainerArchive(ctx context.Context, srcPath strin
return io.NopCloser(buf), nil return io.NopCloser(buf), nil
} }
func (e *HostEnvironment) Pull(forcePull bool) common.Executor { func (e *HostEnvironment) Pull(_ bool) common.Executor {
return func(ctx context.Context) error { return func(ctx context.Context) error {
return nil return nil
} }
} }
func (e *HostEnvironment) Start(attach bool) common.Executor { func (e *HostEnvironment) Start(_ bool) common.Executor {
return func(ctx context.Context) error { return func(ctx context.Context) error {
return nil return nil
} }
@ -240,7 +240,7 @@ func copyPtyOutput(writer io.Writer, ppty io.Reader, finishLog context.CancelFun
} }
} }
func (e *HostEnvironment) UpdateFromImageEnv(env *map[string]string) common.Executor { func (e *HostEnvironment) UpdateFromImageEnv(_ *map[string]string) common.Executor {
return func(ctx context.Context) error { return func(ctx context.Context) error {
return nil return nil
} }
@ -254,7 +254,7 @@ func getEnvListFromMap(env map[string]string) []string {
return envList return envList
} }
func (e *HostEnvironment) exec(ctx context.Context, command []string, cmdline string, env map[string]string, user, workdir string) error { func (e *HostEnvironment) exec(ctx context.Context, command []string, cmdline string, env map[string]string, _, workdir string) error {
envList := getEnvListFromMap(env) envList := getEnvListFromMap(env)
var wd string var wd string
if workdir != "" { if workdir != "" {
@ -411,7 +411,7 @@ func goOsToActionOs(os string) string {
return os return os
} }
func (e *HostEnvironment) GetRunnerContext(ctx context.Context) map[string]interface{} { func (e *HostEnvironment) GetRunnerContext(_ context.Context) map[string]interface{} {
return map[string]interface{}{ return map[string]interface{}{
"os": goOsToActionOs(runtime.GOOS), "os": goOsToActionOs(runtime.GOOS),
"arch": goArchToActionArch(runtime.GOARCH), "arch": goArchToActionArch(runtime.GOARCH),
@ -420,7 +420,7 @@ func (e *HostEnvironment) GetRunnerContext(ctx context.Context) map[string]inter
} }
} }
func (e *HostEnvironment) ReplaceLogWriter(stdout io.Writer, stderr io.Writer) (io.Writer, io.Writer) { func (e *HostEnvironment) ReplaceLogWriter(stdout io.Writer, _ io.Writer) (io.Writer, io.Writer) {
org := e.StdOut org := e.StdOut
e.StdOut = stdout e.StdOut = stdout
return org, org return org, org

View file

@ -9,7 +9,7 @@ import (
"github.com/creack/pty" "github.com/creack/pty"
) )
func getSysProcAttr(cmdLine string, tty bool) *syscall.SysProcAttr { func getSysProcAttr(_ string, tty bool) *syscall.SysProcAttr {
if tty { if tty {
return &syscall.SysProcAttr{ return &syscall.SysProcAttr{
Setsid: true, Setsid: true,

View file

@ -182,7 +182,7 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
} }
} }
func setupActionEnv(ctx context.Context, step actionStep, remoteAction *remoteAction) error { func setupActionEnv(ctx context.Context, step actionStep, _ *remoteAction) error {
rc := step.getRunContext() rc := step.getRunContext()
// A few fields in the environment (e.g. GITHUB_ACTION_REPOSITORY) // A few fields in the environment (e.g. GITHUB_ACTION_REPOSITORY)

View file

@ -171,7 +171,7 @@ func unescapeKvPairs(kvPairs map[string]string) map[string]string {
return kvPairs return kvPairs
} }
func (rc *RunContext) saveState(ctx context.Context, kvPairs map[string]string, arg string) { func (rc *RunContext) saveState(_ context.Context, kvPairs map[string]string, arg string) {
stepID := rc.CurrentStep stepID := rc.CurrentStep
if stepID != "" { if stepID != "" {
if rc.IntraActionState == nil { if rc.IntraActionState == nil {

View file

@ -181,7 +181,7 @@ func (ee expressionEvaluator) evaluateScalarYamlNode(ctx context.Context, node *
} }
func (ee expressionEvaluator) evaluateMappingYamlNode(ctx context.Context, node *yaml.Node) (*yaml.Node, error) { func (ee expressionEvaluator) evaluateMappingYamlNode(ctx context.Context, node *yaml.Node) (*yaml.Node, error) {
var ret *yaml.Node = nil var ret *yaml.Node
// GitHub has this undocumented feature to merge maps, called insert directive // GitHub has this undocumented feature to merge maps, called insert directive
insertDirective := regexp.MustCompile(`\${{\s*insert\s*}}`) insertDirective := regexp.MustCompile(`\${{\s*insert\s*}}`)
for i := 0; i < len(node.Content)/2; i++ { for i := 0; i < len(node.Content)/2; i++ {
@ -239,7 +239,7 @@ func (ee expressionEvaluator) evaluateMappingYamlNode(ctx context.Context, node
} }
func (ee expressionEvaluator) evaluateSequenceYamlNode(ctx context.Context, node *yaml.Node) (*yaml.Node, error) { func (ee expressionEvaluator) evaluateSequenceYamlNode(ctx context.Context, node *yaml.Node) (*yaml.Node, error) {
var ret *yaml.Node = nil var ret *yaml.Node
for i := 0; i < len(node.Content); i++ { for i := 0; i < len(node.Content); i++ {
v := node.Content[i] v := node.Content[i]
// Preserve nested sequences // Preserve nested sequences
@ -503,6 +503,6 @@ func getWorkflowSecrets(ctx context.Context, rc *RunContext) map[string]string {
return rc.Config.Secrets return rc.Config.Secrets
} }
func getWorkflowVars(ctx context.Context, rc *RunContext) map[string]string { func getWorkflowVars(_ context.Context, rc *RunContext) map[string]string {
return rc.Config.Vars return rc.Config.Vars
} }

View file

@ -101,7 +101,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
// always allow 1 min for stopping and removing the runner, even if we were cancelled // always allow 1 min for stopping and removing the runner, even if we were cancelled
ctx, cancel := context.WithTimeout(common.WithLogger(context.Background(), common.Logger(ctx)), time.Minute) ctx, cancel := context.WithTimeout(common.WithLogger(context.Background(), common.Logger(ctx)), time.Minute)
defer cancel() defer cancel()
err = info.stopContainer()(ctx) err = info.stopContainer()(ctx) //nolint:contextcheck
} }
setJobResult(ctx, info, rc, jobError == nil) setJobResult(ctx, info, rc, jobError == nil)
setJobOutputs(ctx, rc) setJobOutputs(ctx, rc)
@ -114,7 +114,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
pipeline = append(pipeline, steps...) pipeline = append(pipeline, steps...)
return common.NewPipelineExecutor(info.startContainer(), common.NewPipelineExecutor(pipeline...). return common.NewPipelineExecutor(info.startContainer(), common.NewPipelineExecutor(pipeline...).
Finally(func(ctx context.Context) error { Finally(func(ctx context.Context) error { //nolint:contextcheck
var cancel context.CancelFunc var cancel context.CancelFunc
if ctx.Err() == context.Canceled { if ctx.Err() == context.Canceled {
// in case of an aborted run, we still should execute the // in case of an aborted run, we still should execute the

View file

@ -82,7 +82,7 @@ type jobContainerMock struct {
container.LinuxContainerEnvironmentExtensions container.LinuxContainerEnvironmentExtensions
} }
func (jcm *jobContainerMock) ReplaceLogWriter(stdout, stderr io.Writer) (io.Writer, io.Writer) { func (jcm *jobContainerMock) ReplaceLogWriter(_, _ io.Writer) (io.Writer, io.Writer) {
return nil, nil return nil, nil
} }

View file

@ -515,7 +515,7 @@ func (rc *RunContext) platformImage(ctx context.Context) string {
return rc.runsOnImage(ctx) return rc.runsOnImage(ctx)
} }
func (rc *RunContext) options(ctx context.Context) string { func (rc *RunContext) options(_ context.Context) string {
job := rc.Run.Job() job := rc.Run.Job()
c := job.Container() c := job.Container()
if c == nil { if c == nil {
@ -813,35 +813,35 @@ func setActionRuntimeVars(rc *RunContext, env map[string]string) {
env["ACTIONS_RUNTIME_TOKEN"] = actionsRuntimeToken env["ACTIONS_RUNTIME_TOKEN"] = actionsRuntimeToken
} }
func (rc *RunContext) handleCredentials(ctx context.Context) (username, password string, err error) { func (rc *RunContext) handleCredentials(ctx context.Context) (string, string, error) {
// TODO: remove below 2 lines when we can release act with breaking changes // TODO: remove below 2 lines when we can release act with breaking changes
username = rc.Config.Secrets["DOCKER_USERNAME"] username := rc.Config.Secrets["DOCKER_USERNAME"]
password = rc.Config.Secrets["DOCKER_PASSWORD"] password := rc.Config.Secrets["DOCKER_PASSWORD"]
container := rc.Run.Job().Container() container := rc.Run.Job().Container()
if container == nil || container.Credentials == nil { if container == nil || container.Credentials == nil {
return return username, password, nil
} }
if container.Credentials != nil && len(container.Credentials) != 2 { if container.Credentials != nil && len(container.Credentials) != 2 {
err = fmt.Errorf("invalid property count for key 'credentials:'") err := fmt.Errorf("invalid property count for key 'credentials:'")
return return "", "", err
} }
ee := rc.NewExpressionEvaluator(ctx) ee := rc.NewExpressionEvaluator(ctx)
if username = ee.Interpolate(ctx, container.Credentials["username"]); username == "" { if username = ee.Interpolate(ctx, container.Credentials["username"]); username == "" {
err = fmt.Errorf("failed to interpolate container.credentials.username") err := fmt.Errorf("failed to interpolate container.credentials.username")
return return "", "", err
} }
if password = ee.Interpolate(ctx, container.Credentials["password"]); password == "" { if password = ee.Interpolate(ctx, container.Credentials["password"]); password == "" {
err = fmt.Errorf("failed to interpolate container.credentials.password") err := fmt.Errorf("failed to interpolate container.credentials.password")
return return "", "", err
} }
if container.Credentials["username"] == "" || container.Credentials["password"] == "" { if container.Credentials["username"] == "" || container.Credentials["password"] == "" {
err = fmt.Errorf("container.credentials cannot be empty") err := fmt.Errorf("container.credentials cannot be empty")
return return "", "", err
} }
return username, password, err return username, password, nil
} }

View file

@ -256,7 +256,7 @@ func isStepEnabled(ctx context.Context, expr string, step step, stage stepStage)
return runStep, nil return runStep, nil
} }
func isContinueOnError(ctx context.Context, expr string, step step, stage stepStage) (bool, error) { func isContinueOnError(ctx context.Context, expr string, step step, _ stepStage) (bool, error) {
// https://github.com/github/docs/blob/3ae84420bd10997bb5f35f629ebb7160fe776eae/content/actions/reference/workflow-syntax-for-github-actions.md?plain=true#L962 // https://github.com/github/docs/blob/3ae84420bd10997bb5f35f629ebb7160fe776eae/content/actions/reference/workflow-syntax-for-github-actions.md?plain=true#L962
if len(strings.TrimSpace(expr)) == 0 { if len(strings.TrimSpace(expr)) == 0 {
return false, nil return false, nil

View file

@ -85,7 +85,7 @@ func (sal *stepActionLocal) getEnv() *map[string]string {
return &sal.env return &sal.env
} }
func (sal *stepActionLocal) getIfExpression(context context.Context, stage stepStage) string { func (sal *stepActionLocal) getIfExpression(_ context.Context, stage stepStage) string {
switch stage { switch stage {
case stepStageMain: case stepStageMain:
return sal.Step.If.Value return sal.Step.If.Value

View file

@ -24,7 +24,7 @@ func (salm *stepActionLocalMocks) runAction(step actionStep, actionDir string, r
return args.Get(0).(func(context.Context) error) return args.Get(0).(func(context.Context) error)
} }
func (salm *stepActionLocalMocks) readAction(ctx context.Context, step *model.Step, actionDir string, actionPath string, readFile actionYamlReader, writeFile fileWriter) (*model.Action, error) { func (salm *stepActionLocalMocks) readAction(_ context.Context, step *model.Step, actionDir string, actionPath string, readFile actionYamlReader, writeFile fileWriter) (*model.Action, error) {
args := salm.Called(step, actionDir, actionPath, readFile, writeFile) args := salm.Called(step, actionDir, actionPath, readFile, writeFile)
return args.Get(0).(*model.Action), args.Error(1) return args.Get(0).(*model.Action), args.Error(1)
} }

View file

@ -21,7 +21,7 @@ type stepActionRemoteMocks struct {
mock.Mock mock.Mock
} }
func (sarm *stepActionRemoteMocks) readAction(ctx context.Context, step *model.Step, actionDir string, actionPath string, readFile actionYamlReader, writeFile fileWriter) (*model.Action, error) { func (sarm *stepActionRemoteMocks) readAction(_ context.Context, step *model.Step, actionDir string, actionPath string, readFile actionYamlReader, writeFile fileWriter) (*model.Action, error) {
args := sarm.Called(step, actionDir, actionPath, readFile, writeFile) args := sarm.Called(step, actionDir, actionPath, readFile, writeFile)
return args.Get(0).(*model.Action), args.Error(1) return args.Get(0).(*model.Action), args.Error(1)
} }

View file

@ -51,7 +51,7 @@ func (sd *stepDocker) getEnv() *map[string]string {
return &sd.env return &sd.env
} }
func (sd *stepDocker) getIfExpression(context context.Context, stage stepStage) string { func (sd *stepDocker) getIfExpression(_ context.Context, _ stepStage) string {
return sd.Step.If.Value return sd.Step.If.Value
} }

View file

@ -59,7 +59,7 @@ func (sr *stepRun) getEnv() *map[string]string {
return &sr.env return &sr.env
} }
func (sr *stepRun) getIfExpression(context context.Context, stage stepStage) string { func (sr *stepRun) getIfExpression(_ context.Context, _ stepStage) string {
return sr.Step.If.Value return sr.Step.If.Value
} }