Skip to content

Commit

Permalink
Upgrade golangci-lint to v1.62.2 (#1756)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybeard authored Dec 17, 2024
1 parent 69c034c commit 356be0b
Show file tree
Hide file tree
Showing 29 changed files with 418 additions and 461 deletions.
17 changes: 6 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ linters-settings:
funlen:
lines: 100
statements: 50
gci:
local-prefixes: github.com/golangci/golangci-lint
goconst:
min-len: 3
min-occurrences: 3
Expand All @@ -44,14 +42,8 @@ linters-settings:
local-prefixes: github.com/golangci/golangci-lint
revive:
confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: [argument, case, condition, return]
ignored-numbers: 2,10,64 # numbers used by strconv
govet:
check-shadowing: true
shadow: true
settings:
printf:
funcs:
Expand All @@ -65,6 +57,10 @@ linters-settings:
suggest-new: true
misspell:
locale: US
mnd:
# don't include the "operation" and "assign"
checks: [argument, case, condition, return]
ignored-numbers: 2,10,64 # numbers used by strconv
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: true # don't report any unused nolint directives
Expand All @@ -82,20 +78,19 @@ linters:
- dogsled
- dupl
- errcheck
- exportloopref
- exhaustive
- goconst
- gocritic
- gocyclo
- gofumpt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- misspell
- mnd
- nakedret
- noctx
- nolintlint
Expand Down
11 changes: 6 additions & 5 deletions airflow/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
componentName = "airflow"
dockerStateUp = "running"
dockerExitState = "exited"
defaultAirflowVersion = uint64(0x2) //nolint:gomnd
defaultAirflowVersion = uint64(0x2) //nolint:mnd
triggererAllowedRuntimeVersion = "4.0.0"
triggererAllowedAirflowVersion = "2.2.0"
pytestDirectory = "tests"
Expand Down Expand Up @@ -308,7 +308,8 @@ func (d *DockerCompose) ComposeExport(settingsFile, composeFile string) error {
}

// write the yaml to a file
err = os.WriteFile(composeFile, []byte(yaml), 0o666) //nolint:gosec, gomnd
composeFilePerms := 0o666
err = os.WriteFile(composeFile, []byte(yaml), fs.FileMode(composeFilePerms))
if err != nil {
return errors.Wrap(err, "failed to write to compose file")
}
Expand Down Expand Up @@ -382,7 +383,7 @@ func (d *DockerCompose) PS() error {

// Create a new tabwriter
tw := new(tabwriter.Writer)
tw.Init(os.Stdout, 0, 8, 2, '\t', tabwriter.AlignRight) //nolint:gomnd
tw.Init(os.Stdout, 0, 8, 2, '\t', tabwriter.AlignRight) //nolint:mnd

// Append data to table
fmt.Fprintln(tw, strings.Join(infoColumns, "\t"))
Expand Down Expand Up @@ -681,7 +682,7 @@ func (d *DockerCompose) versionTest(testHomeDirectory, currentAirflowVersion, de
if err != nil {
return err
}
fmt.Printf("Pip Freeze comparison can be found at \n" + pipFreezeCompareFile)
fmt.Printf("Pip Freeze comparison can be found at %s", pipFreezeCompareFile)
return nil
}

Expand Down Expand Up @@ -795,7 +796,7 @@ func upgradeDockerfile(oldDockerfilePath, newDockerfilePath, newTag, newImage st
}

// Write the new content to the new Dockerfile
err = os.WriteFile(newDockerfilePath, []byte(newContent.String()), 0o600) //nolint:gomnd
err = os.WriteFile(newDockerfilePath, []byte(newContent.String()), 0o600) //nolint:mnd
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions airflow/docker_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ func (d *DockerImage) Pytest(pytestFile, airflowHome, envFile, testHomeDirectory

// start pytest container
err = cmdExec(containerRuntime, stdout, stderr, []string{"start", "astro-pytest", "-a"}...)
if docErr != nil {
log.Debugf("Error starting pytest container: %s", docErr.Error())
if err != nil {
log.Debugf("Error starting pytest container: %s", err.Error())
}

// get exit code
Expand Down
4 changes: 2 additions & 2 deletions airflow/docker_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func (s *Suite) TestDockerImagePush() {
s.Run("success", func() {
cmdExec = func(cmd string, stdout, stderr io.Writer, args ...string) error { return nil }

displayJSONMessagesToStream = func(responseBody io.ReadCloser, auxCallback func(jsonmessage.JSONMessage)) error {
displayJSONMessagesToStream = func(_ io.ReadCloser, _ func(jsonmessage.JSONMessage)) error {
return nil
}

Expand All @@ -464,7 +464,7 @@ func (s *Suite) TestDockerImagePush() {
})

s.Run("success with docker cred store", func() {
displayJSONMessagesToStream = func(responseBody io.ReadCloser, auxCallback func(jsonmessage.JSONMessage)) error {
displayJSONMessagesToStream = func(_ io.ReadCloser, _ func(jsonmessage.JSONMessage)) error {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions airflow/runtimes/docker_runtime.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package runtimes

import (
"fmt"
"errors"
"time"

"github.com/briandowns/spinner"
Expand Down Expand Up @@ -68,15 +68,15 @@ func (rt DockerRuntime) initializeDocker(timeoutSeconds int) error {
// If we got an error, Docker is not running, so we attempt to start it.
_, err = rt.Engine.Start()
if err != nil {
return fmt.Errorf(dockerOpenNotice) //nolint:stylecheck
return errors.New(dockerOpenNotice) //nolint: stylecheck
}

// Wait for Docker to start.
s.Start()
for {
select {
case <-timeout:
return fmt.Errorf(timeoutErrMsg)
return errors.New(timeoutErrMsg)
case <-ticker.C:
_, err := rt.Engine.IsRunning()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions airflow/runtimes/docker_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s *DockerRuntimeSuite) TestStartDocker() {
rt := CreateDockerRuntime(mockDockerEngine, mockDockerOSChecker)
// Run our test and assert expectations.
err := rt.Initialize()
assert.Equal(s.T(), fmt.Errorf(dockerOpenNotice), err, "Expected timeout error")
assert.Equal(s.T(), dockerOpenNotice, err.Error(), "Expected timeout error")
mockDockerEngine.AssertExpectations(s.T())
})

Expand All @@ -83,7 +83,7 @@ func (s *DockerRuntimeSuite) TestStartDocker() {
// Call the helper method directly with custom timeout.
// Simulate the timeout after 1 second.
err := rt.initializeDocker(1)
assert.Equal(s.T(), fmt.Errorf(timeoutErrMsg), err, "Expected timeout error")
assert.Equal(s.T(), timeoutErrMsg, err.Error(), "Expected timeout error")
mockDockerEngine.AssertExpectations(s.T())
})
}
4 changes: 2 additions & 2 deletions airflow/runtimes/podman_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (rt PodmanRuntime) Configure() error {
}

// Otherwise, we return an error indicating that the project isn't running.
return fmt.Errorf(projectNotRunningErrMsg)
return errors.New(projectNotRunningErrMsg)
}

func (rt PodmanRuntime) ConfigureOrKill() error {
Expand All @@ -94,7 +94,7 @@ func (rt PodmanRuntime) ConfigureOrKill() error {

// We also return an error indicating that you can't kill
// a project that isn't running.
return fmt.Errorf(projectNotRunningErrMsg)
return errors.New(projectNotRunningErrMsg)
}

func (rt PodmanRuntime) Kill() error {
Expand Down
2 changes: 1 addition & 1 deletion airflow_versions/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewAirflowVersion(v string, tags []string) (*AirflowVersion, error) {

// get post_n1
m := AirflowVersionReg.FindStringSubmatch(v)
postN1, _ := strconv.ParseUint(m[8], 10, 64) //nolint:gomnd
postN1, _ := strconv.ParseUint(m[8], 10, 64) //nolint:mnd

av := AirflowVersion{
*semV,
Expand Down
9 changes: 6 additions & 3 deletions cloud/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func authorizeCallbackHandler() (string, error) {

func (a *Authenticator) authDeviceLogin(authConfig Config, shouldDisplayLoginLink bool) (Result, error) { //nolint:gocritic
// Generate PKCE verifier and challenge
token := make([]byte, 32) //nolint:gomnd
token := make([]byte, 32) //nolint:mnd
r := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec
r.Read(token)
verifier := util.Base64URLEncode(token)
Expand All @@ -211,7 +211,10 @@ func (a *Authenticator) authDeviceLogin(authConfig Config, shouldDisplayLoginLin
// open browser
if !shouldDisplayLoginLink {
fmt.Printf("\n%s to open the browser to log in or %s to quit…", ansi.Green("Press Enter"), ansi.Red("^C"))
fmt.Scanln()
_, err := fmt.Scanln()
if err != nil {
return Result{}, err
}
err = openURL(authorizeURL)
if err != nil {
fmt.Println("\nUnable to open the URL, please visit the following link: " + authorizeURL)
Expand Down Expand Up @@ -367,7 +370,7 @@ func Login(domain, token string, coreClient astrocore.CoreClient, platformCoreCl
fmt.Print("You are logging into Astro via an OAuth token\nThis token will expire in 1 hour and will not refresh\n\n")
res = Result{
AccessToken: token,
ExpiresIn: 3600, //nolint:gomnd
ExpiresIn: 3600, //nolint:mnd
}
}

Expand Down
4 changes: 2 additions & 2 deletions cloud/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func removeDagsFromDockerIgnore(fullpath string) error {
if err := scanner.Err(); err != nil {
return err
}
err = os.WriteFile(fullpath, bytes.Trim(buf.Bytes(), "\n"), 0o666) //nolint:gosec, gomnd
err = os.WriteFile(fullpath, bytes.Trim(buf.Bytes(), "\n"), 0o666) //nolint:gosec, mnd
if err != nil {
return err
}
Expand Down Expand Up @@ -608,7 +608,7 @@ func buildImageWithoutDags(path, buildSecretString string, imageHandler airflow.
}
contains, _ := fileutil.Contains(lines, "dags/")
if !contains {
f, err := os.OpenFile(fullpath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) //nolint:gomnd
f, err := os.OpenFile(fullpath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) //nolint:mnd
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cloud/deployment/deployment_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func getDeploymentToken(id, name, deploymentID, message string, tokens []astroco

func TimeAgo(date time.Time) string {
duration := time.Since(date)
days := int(duration.Hours() / 24) //nolint:gomnd
days := int(duration.Hours() / 24) //nolint:mnd
hours := int(duration.Hours())
minutes := int(duration.Minutes())

Expand Down
8 changes: 4 additions & 4 deletions cloud/deployment/deployment_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func readLines(path string) ([]string, error) {

// writes vars from cloud into a file
func writeVarToFile(environmentVariablesObjects []astroplatformcore.DeploymentEnvironmentVariable, envFile string) error {
f, err := os.OpenFile(envFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) //nolint:gomnd
f, err := os.OpenFile(envFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) //nolint:mnd
if err != nil {
return err
}
Expand Down Expand Up @@ -284,13 +284,13 @@ func addVariablesFromFile(envFile string, oldKeyList []string, oldEnvironmentVar
if vars[i] == "" {
continue
}
if len(strings.SplitN(vars[i], "=", 2)) == 1 { //nolint:gomnd
if len(strings.SplitN(vars[i], "=", 2)) == 1 { //nolint:mnd
fmt.Printf("%s is an improperly formatted variable, no variable created\n", vars[i])
errVarBool = true
continue
}
key := strings.SplitN(vars[i], "=", 2)[0] //nolint:gomnd
value := strings.SplitN(vars[i], "=", 2)[1] //nolint:gomnd
key := strings.SplitN(vars[i], "=", 2)[0] //nolint:mnd
value := strings.SplitN(vars[i], "=", 2)[1] //nolint:mnd
if key == "" {
fmt.Printf("empty key! skipping creating variable with key: %s\n", key)
errVarBool = true
Expand Down
3 changes: 2 additions & 1 deletion cloud/organization/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ func ExportAuditLogs(coreClient astrocore.CoreClient, platformCoreClient astropl
return err
}

err = os.WriteFile(filePath, resp.Body, os.ModePerm)
filePerms := 0o644
err = os.WriteFile(filePath, resp.Body, os.FileMode(filePerms))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cloud/organization/organization_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func DeleteToken(id, name string, force bool, out io.Writer, client astrocore.Co

func TimeAgo(date time.Time) string {
duration := time.Since(date)
days := int(duration.Hours() / 24) //nolint:gomnd
days := int(duration.Hours() / 24) //nolint:mnd
hours := int(duration.Hours())
minutes := int(duration.Minutes())

Expand Down
2 changes: 1 addition & 1 deletion cloud/workspace-token/workspace_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func getWorkspaceToken(id, name, workspaceID, message string, tokens []astrocore

func TimeAgo(date time.Time) string {
duration := time.Since(date)
days := int(duration.Hours() / 24) //nolint:gomnd
days := int(duration.Hours() / 24) //nolint:mnd
hours := int(duration.Hours())
minutes := int(duration.Minutes())

Expand Down
14 changes: 7 additions & 7 deletions cmd/airflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ astro dev init --from-template

pytestDir = "/tests"

airflowUpgradeCheckCmd = []string{"bash", "-c", "pip install --no-deps 'apache-airflow-upgrade-check'; python -c 'from packaging.version import Version\nfrom airflow import __version__\nif Version(__version__) < Version(\"1.10.14\"):\n print(\"Please upgrade your image to Airflow 1.10.14 first, then try again.\");exit(1)\nelse:\n from airflow.upgrade.checker import __main__;__main__()'"}
errPytestArgs = errors.New("you can only pass one pytest file or directory")
buildSecrets = []string{}
errNoCompose = errors.New("cannot use '--compose-file' without '--compose' flag")
TemplateList = airflow.FetchTemplateList
defaultWaitTime = 1 * time.Minute
directoryPermissions = 0o755
airflowUpgradeCheckCmd = []string{"bash", "-c", "pip install --no-deps 'apache-airflow-upgrade-check'; python -c 'from packaging.version import Version\nfrom airflow import __version__\nif Version(__version__) < Version(\"1.10.14\"):\n print(\"Please upgrade your image to Airflow 1.10.14 first, then try again.\");exit(1)\nelse:\n from airflow.upgrade.checker import __main__;__main__()'"}
errPytestArgs = errors.New("you can only pass one pytest file or directory")
buildSecrets = []string{}
errNoCompose = errors.New("cannot use '--compose-file' without '--compose' flag")
TemplateList = airflow.FetchTemplateList
defaultWaitTime = 1 * time.Minute
directoryPermissions uint32 = 0o755
)

func newDevRootCmd(platformCoreClient astroplatformcore.CoreClient, astroCoreClient astrocore.CoreClient) *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloud/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func deploy(cmd *cobra.Command, args []string) error {
}

// Save deploymentId in config if specified
if len(deploymentID) > 0 && saveDeployConfig {
if deploymentID != "" && saveDeployConfig {
err := config.CFG.ProjectDeployment.SetProjectString(deploymentID)
if err != nil {
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func configGet(cmd *cobra.Command, args []string) error {
}

func configSet(cmd *cobra.Command, args []string) error {
if len(args) != 2 { //nolint:gomnd
if len(args) != 2 { //nolint:mnd
return errInvalidSetArgs
}

Expand Down
16 changes: 4 additions & 12 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package cmd

import (
"bytes"
"os/exec"
"strings"
"testing"

testUtil "github.com/astronomer/astro-cli/pkg/testing"
Expand Down Expand Up @@ -68,16 +66,10 @@ func (s *CmdSuite) TestRootCommandCloudContext() {

func (s *CmdSuite) TestRootCompletionCommand() {
testUtil.InitTestConfig(testUtil.LocalPlatform)
completionShellMapSha := map[string]string{"bash": "291b774846025599cd10107324f8a776", "fish": "44b594d5d9e4203e1089396732832061", "zsh": "b9baad5816441d010ca622974699274b", "powershell": "8e03321aa8fa1b18756662efd3fca6d5"}
for shell, sha := range completionShellMapSha {
output1, _ := executeCommand("completion", shell)
cmd2 := exec.Command("openssl", "md5")
cmd2.Stdin = strings.NewReader(output1)
output2, _ := cmd2.Output()
cmd3 := exec.Command("sed", "s/^.*= //")
cmd3.Stdin = strings.NewReader(string(output2))
output, _ := cmd3.Output()
s.Contains(string(output), sha)
shells := []string{"bash", "fish", "zsh", "powershell"}
for _, shell := range shells {
_, err := executeCommand("completion", shell)
s.NoError(err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/software/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func deployAirflow(cmd *cobra.Command, args []string) error {
}

// Save release name in config if specified
if len(deploymentID) > 0 && saveDeployConfig {
if deploymentID != "" && saveDeployConfig {
err = config.CFG.ProjectDeployment.SetProjectString(deploymentID)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 356be0b

Please sign in to comment.