Skip to content

Commit 9437aa2

Browse files
authored
refactor: enable linter rule ST1008 for 'error should be last return value' (#76)
* refactor: enable linter ST1008 'function's error value should be its last return value' * refactor: update SDKConfig.Exists to return error last
1 parent f21cbc2 commit 9437aa2

7 files changed

Lines changed: 11 additions & 12 deletions

File tree

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ linters:
3434
checks:
3535
- all
3636
- '-ST1005' # disable rule 'Incorrectly formatted error string'
37-
- '-ST1008' # disable rule 'Function’s error value should be its last return value'
3837
- '-ST1023' # disable rule 'Redundant type in variable declaration'
3938
- '-QF1001' # disable rule 'Apply De Morgan’s law'
4039
- '-QF1012' # disable rule 'Use fmt.Fprintf instead of x.Write(fmt.Sprintf(...))'

cmd/auth/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func printAuthSuccess(cmd *cobra.Command, IO iostreams.IOStreamer, credentialsPa
146146

147147
// printAuthNextSteps suggests possible commands to run after logging in
148148
func printAuthNextSteps(ctx context.Context, clients *shared.ClientFactory) {
149-
_, project := clients.SDKConfig.Exists()
149+
project, _ := clients.SDKConfig.Exists()
150150
if !project {
151151
clients.IO.PrintInfo(ctx, false, style.Sectionf(style.TextSection{
152152
Emoji: "bulb",

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func ExecuteContext(ctx context.Context, rootCmd *cobra.Command, clients *shared
406406
func cleanup(ctx context.Context, clients *shared.ClientFactory) {
407407
clients.IO.PrintDebug(ctx, "Starting root command cleanup routine")
408408
// clean up any json in project .slack folder if needed
409-
if _, sdkConfigExists := clients.SDKConfig.Exists(); sdkConfigExists {
409+
if sdkConfigExists, _ := clients.SDKConfig.Exists(); sdkConfigExists {
410410
clients.AppClient().CleanUp()
411411
}
412412
}

cmd/root_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,15 @@ func Test_Aliases(t *testing.T) {
236236
}
237237
for name, tt := range tests {
238238
t.Run(name, func(t *testing.T) {
239-
err, output := testExecCmd(ctx, strings.Fields(tt.args))
239+
output, err := testExecCmd(ctx, strings.Fields(tt.args))
240240
require.NoError(t, err)
241241
require.Contains(t, output, tt.expected)
242242
})
243243
}
244244
}
245245

246246
// testExecCmd will execute the root cobra command with args and return the output
247-
func testExecCmd(ctx context.Context, args []string) (error, string) {
247+
func testExecCmd(ctx context.Context, args []string) (string, error) {
248248
// Get command
249249
cmd, clients := Init(ctx)
250250

@@ -257,7 +257,7 @@ func testExecCmd(ctx context.Context, args []string) (error, string) {
257257
cmd.SetArgs(args)
258258
err := cmd.ExecuteContext(ctx)
259259
if err != nil {
260-
return err, ""
260+
return "", err
261261
}
262-
return nil, clientsMock.GetCombinedOutput()
262+
return clientsMock.GetCombinedOutput(), nil
263263
}

internal/cmdutil/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func IsSlackHostedProject(ctx context.Context, clients *shared.ClientFactory) er
5353

5454
// IsValidProjectDirectory verifies that a command is run in a valid project directory and returns nil, otherwise returns an error
5555
func IsValidProjectDirectory(clients *shared.ClientFactory) error {
56-
if err, _ := clients.SDKConfig.Exists(); err != nil {
56+
if _, err := clients.SDKConfig.Exists(); err != nil {
5757
return slackerror.New(slackerror.ErrInvalidAppDirectory)
5858
}
5959
return nil

internal/hooks/sdk_config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ type SDKCLIConfig struct {
4646
}
4747

4848
// Exists returns true when the SDKCLIConfig was successfully loaded, otherwise false with an error
49-
func (s *SDKCLIConfig) Exists() (error, bool) {
49+
func (s *SDKCLIConfig) Exists() (bool, error) {
5050
if strings.TrimSpace(s.WorkingDirectory) == "" {
51-
return slackerror.New(slackerror.ErrInvalidSlackProjectDirectory), false
51+
return false, slackerror.New(slackerror.ErrInvalidSlackProjectDirectory)
5252
}
53-
return nil, true
53+
return true, nil
5454
}
5555

5656
type ProtocolVersions []Protocol

internal/hooks/sdk_config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func Test_SDKCLIConfig_Exists(t *testing.T) {
4040
}
4141
for name, tt := range tests {
4242
t.Run(name, func(t *testing.T) {
43-
err, exists := tt.sdkCLIConfig.Exists()
43+
exists, err := tt.sdkCLIConfig.Exists()
4444
require.Equal(t, tt.expectedError, err)
4545
require.Equal(t, tt.exists, exists)
4646
})

0 commit comments

Comments
 (0)