Skip to content

Commit 9c22e9a

Browse files
author
Gustavo Bazan
authored
task: enable perfsprint (#2912)
1 parent d58d3cf commit 9c22e9a

File tree

25 files changed

+65
-57
lines changed

25 files changed

+65
-57
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ linters:
122122
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
123123
- noctx # noctx finds sending http request without context.Context [fast: false, auto-fix: false]
124124
- nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false]
125+
- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative.
125126
- prealloc # Finds slice declarations that could potentially be pre-allocated [fast: true, auto-fix: false]
126127
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
127128
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
128129
- rowserrcheck # checks whether Err of rows is checked successfully [fast: false, auto-fix: false]
129130
- staticcheck # (megacheck) It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary. The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint. [fast: false, auto-fix: false]
130131
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
131132
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false]
133+
- testableexamples # linter checks if examples are testable (have an expected output)
132134
- testifylint # Checks usage of github.com/stretchr/testify. [fast: false, auto-fix: false]
133135
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
134136
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false]

internal/cli/deployments/options/deployment_opts.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,27 @@ func (opts *DeploymentOpts) LocalCheckHostname() string {
135135
}
136136

137137
func (opts *DeploymentOpts) LocalNetworkName() string {
138-
return fmt.Sprintf("mdb-local-%s", opts.DeploymentName)
138+
return "mdb-local-" + opts.DeploymentName
139139
}
140140

141141
func (opts *DeploymentOpts) LocalMongotDataVolume() string {
142-
return fmt.Sprintf("mongot-local-data-%s", opts.DeploymentName)
142+
return "mongot-local-data-" + opts.DeploymentName
143143
}
144144

145145
func (opts *DeploymentOpts) LocalMongodDataVolume() string {
146-
return fmt.Sprintf("mongod-local-data-%s", opts.DeploymentName)
146+
return "mongod-local-data-" + opts.DeploymentName
147147
}
148148

149149
func (opts *DeploymentOpts) LocalMongoMetricsVolume() string {
150-
return fmt.Sprintf("mongot-local-metrics-%s", opts.DeploymentName)
150+
return "mongot-local-metrics-" + opts.DeploymentName
151151
}
152152

153153
func (opts *DeploymentOpts) MongodDockerImageName() string {
154154
return fmt.Sprintf("docker.io/mongodb/mongodb-enterprise-server:%s-ubi8", opts.MdbVersion)
155155
}
156156

157157
func LocalDeploymentName(hostname string) string {
158-
return strings.TrimPrefix(hostname, fmt.Sprintf("%s-", MongodHostnamePrefix))
158+
return strings.TrimPrefix(hostname, MongodHostnamePrefix+"-")
159159
}
160160

161161
func (opts *DeploymentOpts) StartSpinner() {

internal/cli/deployments/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ func (opts *SetupOpts) runAtlas(ctx context.Context) error {
794794

795795
// replace deployment name with cluster name
796796
if opts.DeploymentName != "" {
797-
newArgs = append(newArgs, fmt.Sprintf("--%s", flag.ClusterName), opts.DeploymentName)
797+
newArgs = append(newArgs, "--"+flag.ClusterName, opts.DeploymentName)
798798
}
799799

800800
// update args

internal/cli/kubernetes/config/apply.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (opts *ApplyOpts) autoDetectParams(kubeCtl *kubernetes.KubeCtl) error {
7272
}
7373

7474
if opts.operatorVersion == "" {
75-
if !strings.HasPrefix(operatorDeployment.Spec.Template.Spec.Containers[0].Image, fmt.Sprintf("%s:", containerImage)) {
75+
if !strings.HasPrefix(operatorDeployment.Spec.Template.Spec.Containers[0].Image, containerImage+":") {
7676
return errors.New("unable to auto detect operator version. you should explicitly set operator version if you are running an openshift certified installation")
7777
}
7878

@@ -173,7 +173,7 @@ func ApplyBuilder() *cobra.Command {
173173
}
174174

175175
func getOperatorMajorVersion(image string) string {
176-
version := strings.Trim(image, fmt.Sprintf("%s:", containerImage))
176+
version := strings.TrimPrefix(image, containerImage+":")
177177

178178
semVer := strings.Split(version, ".")
179179
semVer[2] = "0"

internal/cli/organizations/apikeys/apikeys.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import (
2020
"github.com/spf13/cobra"
2121
)
2222

23+
const longDesc = `To view possible values for the ID argument, run atlas organizations apiKeys list.
24+
25+
`
26+
2327
func Builder() *cobra.Command {
2428
const use = "apiKeys"
2529
var cmd = &cobra.Command{

internal/cli/organizations/apikeys/delete.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ func DeleteBuilder() *cobra.Command {
5555
Use: "delete <ID>",
5656
Aliases: []string{"rm"},
5757
Short: "Remove the specified API key for your organization.",
58-
Long: fmt.Sprintf(`To view possible values for the ID argument, run atlas organizations apiKeys list.
59-
60-
%s`, fmt.Sprintf(usage.RequiredRole, "Organization User Admin")),
61-
Args: require.ExactArgs(1),
58+
Long: longDesc + fmt.Sprintf(usage.RequiredRole, "Organization User Admin"),
59+
Args: require.ExactArgs(1),
6260
Annotations: map[string]string{
6361
"IDDesc": "Unique 24-digit string that identifies the organization's API key.",
6462
"output": opts.SuccessMessage(),

internal/cli/organizations/apikeys/describe.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ func DescribeBuilder() *cobra.Command {
6363
Aliases: []string{"show"},
6464
Args: require.ExactArgs(1),
6565
Short: "Return the details for the specified API key for your organization.",
66-
Long: fmt.Sprintf(`To view possible values for the ID argument, run atlas organizations apiKeys list.
67-
68-
%s`, fmt.Sprintf(usage.RequiredRole, "Organization Member")),
66+
Long: longDesc + fmt.Sprintf(usage.RequiredRole, "Organization Member"),
6967
Annotations: map[string]string{
7068
"IDDesc": "Unique 24-digit string that identifies your API key.",
7169
"output": describeTemplate,

internal/cli/organizations/apikeys/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ func UpdateBuilder() *cobra.Command {
7171
Aliases: []string{"updates"},
7272
Args: require.ExactArgs(1),
7373
Short: "Modify the roles or description for the specified organization API key.",
74-
Long: fmt.Sprintf(`When you modify the roles for an organization API key with this command, the values you specify overwrite the existing roles assigned to the API key.
74+
Long: `When you modify the roles for an organization API key with this command, the values you specify overwrite the existing roles assigned to the API key.
7575
7676
To view possible values for the apiKeyId argument, run atlas organizations apiKeys list.
7777
78-
%s`, fmt.Sprintf(usage.RequiredRole, "Organization User Admin")),
78+
` + fmt.Sprintf(usage.RequiredRole, "Organization User Admin"),
7979
Annotations: map[string]string{
8080
"apiKeyIdDesc": "Unique 24-digit string that identifies your API key.",
8181
"output": updateTemplate,

internal/cli/setup/prompt.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
package setup
1616

1717
import (
18-
"fmt"
19-
2018
"github.com/AlecAivazis/survey/v2"
2119
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
2220
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/validate"
@@ -49,7 +47,7 @@ func newClusterProviderQuestion() *survey.Question {
4947
func newAccessListQuestion(publicIP, message string) survey.Prompt {
5048
extraInfo := " Set to 0.0.0.0/0 if you want to enable connection from anywhere; use comma (,) to separate multiple entries."
5149
return &survey.Input{
52-
Message: fmt.Sprintf("IP Access List Entry%s", message),
50+
Message: "IP Access List Entry" + message,
5351
Help: usage.NetworkAccessListIPEntry + extraInfo,
5452
Default: publicIP,
5553
}
@@ -72,7 +70,7 @@ func newDBUserPasswordQuestion(password, message string) *survey.Question {
7270
return &survey.Question{
7371
Name: "DBUserPassword",
7472
Prompt: &survey.Input{
75-
Message: fmt.Sprintf("Database User Password%s", message),
73+
Message: "Database User Password" + message,
7674
Help: usage.Password,
7775
Default: password,
7876
},

internal/kubernetes/operator/install_resources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func (ir *InstallResources) addDeployment(ctx context.Context, config map[string
305305
for i := range obj.Spec.Template.Spec.Containers[0].Args {
306306
arg := obj.Spec.Template.Spec.Containers[0].Args[i]
307307
if arg == "--atlas-domain=https://cloud.mongodb.com/" {
308-
obj.Spec.Template.Spec.Containers[0].Args[i] = fmt.Sprintf("--atlas-domain=%s", atlasDomain)
308+
obj.Spec.Template.Spec.Containers[0].Args[i] = "--atlas-domain=" + atlasDomain
309309
}
310310
}
311311

0 commit comments

Comments
 (0)