Skip to content

Commit 0f1c447

Browse files
authored
[linting] enable more rules for revive and address issues (#849)
## Summary 1. Enable more rules for revive. 2. Address existing issues. ## How was it tested? devbox run lint
1 parent 81dfd27 commit 0f1c447

File tree

29 files changed

+84
-105
lines changed

29 files changed

+84
-105
lines changed

.golangci.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,25 @@ linters-settings:
3535
errorlint:
3636
errorf: false
3737
revive:
38-
rules:
38+
rules: # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
39+
- name: atomic
40+
- name: bare-return
41+
- name: bool-literal-in-expr
42+
- name: cognitive-complexity
43+
arguments:
44+
- 36 # TODO: gradually reduce it
45+
- name: datarace
46+
- name: duplicated-imports
47+
- name: early-return
48+
- name: error-return
49+
- name: error-strings
50+
- name: if-return
3951
- name: indent-error-flow
52+
- name: range-val-address
53+
- name: receiver-naming
54+
- name: time-naming
55+
- name: var-naming
56+
- name: unreachable-code
4057
varnamelen:
4158
max-distance: 10
4259
ignore-decls:

internal/boxcli/gen-docs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ func genDocsCmd() *cobra.Command {
2121
Hidden: true,
2222
Args: cobra.ExactArgs(1),
2323
RunE: func(cmd *cobra.Command, args []string) error {
24-
2524
wd, err := os.Getwd()
2625
if err != nil {
2726
return errors.WithStack(err)

internal/boxcli/generate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ func direnvCmd() *cobra.Command {
8686
command := &cobra.Command{
8787
Use: "direnv",
8888
Short: "Generate a .envrc file that integrates direnv with this devbox project",
89-
Long: "Generate a .envrc file that integrates direnv with this devbox project. Requires direnv to be installed.",
90-
Args: cobra.MaximumNArgs(0),
89+
Long: "Generate a .envrc file that integrates direnv with this devbox project. " +
90+
"Requires direnv to be installed.",
91+
Args: cobra.MaximumNArgs(0),
9192
RunE: func(cmd *cobra.Command, args []string) error {
9293
return runGenerateCmd(cmd, args, flags)
9394
},

internal/boxcli/init.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ func InitCmd() *cobra.Command {
1313
command := &cobra.Command{
1414
Use: "init [<dir>]",
1515
Short: "Initialize a directory as a devbox project",
16-
Long: "Initialize a directory as a devbox project. This will create an empty devbox.json in the current directory. You can then add packages using `devbox add`",
17-
Args: cobra.MaximumNArgs(1),
16+
Long: "Initialize a directory as a devbox project. " +
17+
"This will create an empty devbox.json in the current directory. " +
18+
"You can then add packages using `devbox add`",
19+
Args: cobra.MaximumNArgs(1),
1820
RunE: func(cmd *cobra.Command, args []string) error {
1921
return runInitCmd(cmd, args)
2022
},

internal/boxcli/log.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
)
88

99
func LogCmd() *cobra.Command {
10-
1110
cmd := &cobra.Command{
1211
Use: "log <event-name> [<event-specific-args>]",
1312
Hidden: true,

internal/boxcli/midcobra/telemetry.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ type event struct {
103103
// newEventIfValid creates a new telemetry event, but returns nil if we cannot construct
104104
// a valid event.
105105
func (m *telemetryMiddleware) newEventIfValid(cmd *cobra.Command, args []string, runErr error) *event {
106-
107106
subcmd, flags, parseErr := getSubcommand(cmd, args)
108107
if parseErr != nil {
109108
// Ignore invalid commands

internal/boxcli/run.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,13 @@ func parseScriptArgs(args []string, flags runCmdFlags) (string, string, []string
8080
return "", "", nil, err
8181
}
8282

83-
script := ""
84-
var scriptArgs []string
85-
if len(args) >= 1 {
86-
script = args[0]
87-
scriptArgs = args[1:]
88-
} else {
83+
if len(args) == 0 {
8984
// this should never happen because cobra should prevent it, but it's better to be defensive.
9085
return "", "", nil, usererr.New("no command or script provided")
9186
}
9287

88+
script := args[0]
89+
scriptArgs := args[1:]
90+
9391
return path, script, scriptArgs, nil
9492
}

internal/cloud/cloud.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func ensureVMForUser(vmHostname string, w io.Writer, username string, sshCmd *op
7474

7575
// We save the username to local file only after we get a successful response
7676
// from the gateway, because the gateway will verify that the user's SSH keys
77-
// match their claimed username from github.
77+
// match their claimed username from GitHub.
7878
err = openssh.SaveGithubUsernameToLocalFile(username)
7979
if err != nil {
8080
debug.Log("Failed to save username: %v", err)
@@ -502,13 +502,13 @@ func parseVMEnvVar() (username string, vmHostname string) {
502502
// DEVBOX_VM = <hostname>
503503
if len(parts) == 1 {
504504
vmHostname = parts[0]
505-
return
505+
return username, vmHostname
506506
}
507507

508508
// DEVBOX_VM = <username>@<hostname>
509509
username = parts[0]
510510
vmHostname = parts[1]
511-
return
511+
return username, vmHostname
512512
}
513513

514514
// Proof of concept: look for a gitignore file in the current directory.

internal/cloud/mutagen/type_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
)
88

99
func TestSanitizeSessionName(t *testing.T) {
10-
1110
testCases := []struct {
1211
input string
1312
sanitized string

internal/cloud/openssh/sshshim/mutagen.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ func checkActiveVM(vmAddr string) (bool, error) {
102102
// vmAddressIfAny will seek to find the devbox-vm hostname if it exists
103103
// in the sshArgs. If not, it returns an empty string.
104104
func vmAddressIfAny(sshArgs []string) string {
105-
106105
const devboxVMAddressSuffix = "devbox-vms.internal"
107106
for _, sshArg := range sshArgs {
108107
if strings.HasSuffix(sshArg, devboxVMAddressSuffix) {

0 commit comments

Comments
 (0)