Skip to content

Commit 9879800

Browse files
committed
linting
1 parent 9b5165d commit 9879800

15 files changed

Lines changed: 58 additions & 73 deletions

File tree

.github/workflows/cli-output-compatibility.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
branches: [main]
88
workflow_dispatch:
99

10+
env:
11+
GOPRIVATE: "github.com/brevdev/*"
12+
1013
jobs:
1114
cli-output-compatibility:
1215
runs-on: ubuntu-22.04
@@ -15,18 +18,17 @@ jobs:
1518
- name: Checkout code
1619
uses: actions/checkout@v2
1720

18-
- name: Set up Go
19-
uses: actions/setup-go@v5
20-
with:
21-
go-version: '1.22.6'
22-
cache: true
23-
24-
- name: Install dependencies
25-
run: go mod download
21+
- name: Configure git for private modules
22+
env:
23+
TOKEN: ${{ secrets.GH_TOKEN }}
24+
run: git config --global url."https://${TOKEN}@github.com".insteadOf "https://github.com"
2625

26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-go@v5
28+
with:
29+
go-version-file: go.mod
2730
- name: Run CLI output compatibility tests
2831
run: go test -v ./pkg/integration/
29-
3032
- name: Report test results
3133
if: failure()
3234
run: |

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ linters:
7676
staticcheck:
7777
checks:
7878
- all
79+
- -ST1020 # https://staticcheck.dev/docs/checks#ST1020 - ignore exported fuction doc style
80+
- -ST1021 # https://staticcheck.dev/docs/checks#ST1021 - ignore forced exported type doc style
7981
- -S1016 # https://staticcheck.dev/docs/checks/#S1016 - ignore as explicit field copy is preferred
8082
- -QF1008 # https://staticcheck.dev/docs/checks/#QF1008 - ignore as explicit use of embedded fields is preferred
8183
- -QF1001 # https://staticcheck.dev/docs/checks/#QF1001 - De Morgan's law (use of "!a && !b" over "!(a || b)") is typically preferred, but this is always case by case

pkg/cmd/configureenvvars/configureenvvars_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export ` + BrevManagedEnvVarsKey + "=foo",
148148
got := generateExportString(tt.args.brevEnvsString, tt.args.envFileContents)
149149
diff := cmp.Diff(tt.want, got)
150150
if diff != "" {
151-
t.Fatalf(diff)
151+
t.Fatalf("%s", diff)
152152
}
153153
})
154154
}
@@ -234,7 +234,7 @@ func Test_addUnsetEntriesToOutput(t *testing.T) {
234234
got := addUnsetEntriesToOutput(tt.args.currentEnvs, tt.args.newEnvs, tt.args.output)
235235
diff := cmp.Diff(tt.want, got)
236236
if diff != "" {
237-
t.Fatalf(diff)
237+
t.Fatalf("%s", diff)
238238
}
239239
})
240240
}

pkg/cmd/connect/connect.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewCmdConnect(t *terminal.Terminal, store connectStore) *cobra.Command {
3535

3636
func RunConnect(t *terminal.Terminal, _ []string, _ connectStore) error {
3737
t.Vprintf("Connect the AWS IAM user to create instances in your AWS account.\n")
38-
t.Vprintf(t.Yellow("\tFollow the guide here: %s", "https://onboarding.brev.dev/connect-aws\n\n"))
38+
t.Vprint(t.Yellow("\tFollow the guide here: %s", "https://onboarding.brev.dev/connect-aws\n\n"))
3939
// t.Vprintf(t.Yellow("Connect the AWS IAM user to create dev environments in your AWS account.\n\n"))
4040

4141
AccessKeyID := terminal.PromptGetInput(terminal.PromptContent{
@@ -49,9 +49,9 @@ func RunConnect(t *terminal.Terminal, _ []string, _ connectStore) error {
4949
Mask: '*',
5050
})
5151

52-
t.Vprintf("\n")
53-
t.Vprintf(AccessKeyID)
54-
t.Vprintf(SecretAccessKey)
52+
t.Vprint("\n")
53+
t.Vprint(AccessKeyID)
54+
t.Vprint(SecretAccessKey)
5555

5656
return nil
5757
}

pkg/cmd/sshkeys/sshkeys.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ func NewCmdSSHKeys(t *terminal.Terminal, sshKeyStore SSHKeyStore) *cobra.Command
4444
}
4545

4646
func DisplaySSHKeys(t *terminal.Terminal, publicKey string) {
47-
t.Vprintf(publicKey)
47+
t.Vprint(publicKey)
4848
t.Print("\n")
49-
t.Eprintf(t.Yellow("Copy 👆 and add it to your git provider:\n"))
50-
t.Eprintf(t.Yellow("\tGithub: https://github.com/settings/keys\n"))
51-
t.Eprintf(t.Yellow("\tGitlab: https://gitlab.com/-/profile/keys\n"))
52-
t.Eprintf(t.Yellow("Check authentication by starting a new instance\n"))
53-
t.Eprintf(t.Yellow("\tbrev start --empty --name test-ssh && brev delete test-ssh\n"))
49+
t.Eprint(t.Yellow("Copy 👆 and add it to your git provider:\n"))
50+
t.Eprint(t.Yellow("\tGithub: https://github.com/settings/keys\n"))
51+
t.Eprint(t.Yellow("\tGitlab: https://gitlab.com/-/profile/keys\n"))
52+
t.Eprint(t.Yellow("Check authentication by starting a new instance\n"))
53+
t.Eprint(t.Yellow("\tbrev start --empty --name test-ssh && brev delete test-ssh\n"))
5454
}

pkg/cmd/start/start.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ var (
3232
`
3333
)
3434

35+
const instanceSpinnerSuffix = " Creating your instance. Hang tight 🤙"
36+
3537
type StartStore interface {
3638
util.GetWorkspaceByNameOrIDErrStore
3739
GetWorkspaces(organizationID string, options *store.GetWorkspacesOptions) ([]entity.Workspace, error)
@@ -250,21 +252,21 @@ func maybeStartEmpty(t *terminal.Terminal, user *entity.User, options StartOptio
250252
func startWorkspaceFromPath(user *entity.User, t *terminal.Terminal, options StartOptions, startStore StartStore) error {
251253
pathExists := allutil.DoesPathExist(options.RepoOrPathOrNameOrID)
252254
if !pathExists {
253-
return fmt.Errorf(strings.Join([]string{"Path:", options.RepoOrPathOrNameOrID, "does not exist."}, " "))
255+
return fmt.Errorf("Path: %s does not exist.", options.RepoOrPathOrNameOrID)
254256
}
255257
var gitpath string
256258
if options.RepoOrPathOrNameOrID == "." {
257259
gitpath = filepath.Join(".git", "config")
258260
} else {
259261
gitpath = filepath.Join(options.RepoOrPathOrNameOrID, ".git", "config")
260262
}
261-
file, error := startStore.GetFileAsString(gitpath)
262-
if error != nil {
263-
return fmt.Errorf(strings.Join([]string{"Could not read .git/config at", options.RepoOrPathOrNameOrID}, " "))
263+
fileContents, readErr := startStore.GetFileAsString(gitpath)
264+
if readErr != nil {
265+
return fmt.Errorf("Could not read .git/config at %s", options.RepoOrPathOrNameOrID)
264266
}
265267
// Get GitUrl
266268
var gitURL string
267-
for _, v := range strings.Split(file, "\n") {
269+
for _, v := range strings.Split(fileContents, "\n") {
268270
if strings.Contains(v, "url") {
269271
gitURL = strings.Split(v, "= ")[1]
270272
}
@@ -365,7 +367,7 @@ func createEmptyWorkspace(user *entity.User, t *terminal.Terminal, options Start
365367
t.Vprintf("\tCloud %s\n\n", t.Green(cwOptions.WorkspaceGroupID))
366368

367369
s := t.NewSpinner()
368-
s.Suffix = " Creating your instance. Hang tight 🤙"
370+
s.Suffix = instanceSpinnerSuffix
369371
s.Start()
370372
w, err := startStore.CreateWorkspace(orgID, cwOptions)
371373
if err != nil {
@@ -471,7 +473,7 @@ func joinProjectWithNewWorkspace(t *terminal.Terminal, templateWorkspace entity.
471473
t.Vprintf("\tCloud %s\n", cwOptions.WorkspaceGroupID)
472474

473475
s := t.NewSpinner()
474-
s.Suffix = " Creating your instance. Hang tight 🤙"
476+
s.Suffix = instanceSpinnerSuffix
475477
s.Start()
476478
w, err := startStore.CreateWorkspace(orgID, cwOptions)
477479
if err != nil {
@@ -639,7 +641,7 @@ func createWorkspace(user *entity.User, t *terminal.Terminal, workspace NewWorks
639641
t.Vprintf("\tCloud %s\n", options.WorkspaceGroupID)
640642

641643
s := t.NewSpinner()
642-
s.Suffix = " Creating your instance. Hang tight 🤙"
644+
s.Suffix = instanceSpinnerSuffix
643645
s.Start()
644646
w, err := startStore.CreateWorkspace(orgID, options)
645647
if err != nil {

pkg/cmd/updatemodel/updatemodel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewCmdupdatemodel(t *terminal.Terminal, store updatemodelStore) *cobra.Comm
6262

6363
if params != nil && params.WorkspaceKeyPair != nil {
6464
keys := params.WorkspaceKeyPair
65-
pubkeys, err := ssh.NewPublicKeys("ubuntu", []byte(keys.PrivateKeyData), "") //nolint:govet //abc
65+
pubkeys, err := ssh.NewPublicKeys("ubuntu", []byte(keys.PrivateKeyData), "")
6666
if err != nil {
6767
return nil, breverrors.WrapAndTrace(err)
6868
}

pkg/files/files.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66
"io/ioutil"
7-
"os"
87
"os/exec"
98
"path/filepath"
109

@@ -186,7 +185,7 @@ func OverwriteJSON(fs afero.Fs, filepath string, v interface{}) error {
186185
if err != nil {
187186
return breverrors.WrapAndTrace(err)
188187
}
189-
err = ioutil.WriteFile(filepath, dataBytes, os.ModePerm)
188+
err = ioutil.WriteFile(filepath, dataBytes, 0o600)
190189
if err != nil {
191190
return breverrors.WrapAndTrace(err)
192191
}

pkg/mergeshells/mergeshells.go

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func WriteBrevFile(t *terminal.Terminal, deps []string, gitURL string, path stri
214214
t.Vprint(t.Yellow(strings.Join(deps, " \n")))
215215
shellString := GenerateShellScript(path)
216216
fmt.Println(GenerateLogs(shellString))
217-
mderr := os.MkdirAll(filepath.Join(path, ".brev"), os.ModePerm)
217+
mderr := os.MkdirAll(filepath.Join(path, ".brev"), 0o750)
218218
if mderr == nil {
219219
// generate a string that is the collections.Concatenation of dependency-ordering the contents of all the dependencies
220220
// found by cat'ing the directory generated from the deps string, using the translated ruby code with go generics
@@ -481,11 +481,8 @@ func nodeVersion(path string) *string {
481481
paths := recursivelyFindFile([]string{"package\\-lock\\.json$", "package\\.json$"}, path)
482482
retval := ""
483483
if len(paths) > 0 {
484-
485484
sort.Strings(paths)
486-
487485
i := len(paths) - 1
488-
489486
keypath := "engines.node"
490487
jsonstring, _ := files.CatFile(paths[i])
491488
value := gjson.Get(jsonstring, keypath)
@@ -503,20 +500,15 @@ func gatsbyVersion(path string) *string {
503500
retval := ""
504501
var foundGatsby bool
505502
if len(paths) > 0 {
506-
507503
sort.Strings(paths)
508504
for _, path := range paths {
509505
keypath := "dependencies.gatsby"
510-
jsonstring, err := files.CatFile(path)
506+
jsonstring, _ := files.CatFile(path)
511507
value := gjson.Get(jsonstring, keypath)
512508

513-
if err != nil {
514-
//
515-
}
516509
if value.String() != "" {
517510
foundGatsby = true
518511
}
519-
520512
}
521513
if foundGatsby {
522514
return &retval
@@ -530,17 +522,13 @@ func goVersion(path string) *string {
530522
paths := recursivelyFindFile([]string{"go\\.mod"}, path)
531523

532524
if len(paths) > 0 {
533-
534525
sort.Strings(paths)
535526
for _, path := range paths {
536527
fmt.Println(path)
537-
res, err := readGoMod(path)
538-
if err != nil {
539-
//
540-
}
528+
res, _ := readGoMod(path)
529+
541530
return &res
542531
}
543-
544532
}
545533
return nil
546534
}
@@ -564,24 +552,14 @@ func recursivelyFindFile(filenames []string, path string) []string {
564552
for _, f := range files {
565553
dir, err := os.Stat(appendPath(path, f.Name()))
566554
if err != nil {
567-
// fmt.Println(t.Red(err.Error()))
568555
} else {
569556
for _, filename := range filenames {
570557

571558
r, _ := regexp.Compile(filename)
572559
res := r.MatchString(f.Name())
573560

574561
if res {
575-
// t.Vprint(t.Yellow(filename) + "---" + t.Yellow(path+f.Name()))
576562
paths = append(paths, appendPath(path, f.Name()))
577-
578-
// fileContents, err := catFile(appendPath(path, f.Name()))
579-
// if err != nil {
580-
// //
581-
// }
582-
583-
// TODO: read
584-
// if file has json, read the json
585563
}
586564
}
587565

@@ -590,9 +568,7 @@ func recursivelyFindFile(filenames []string, path string) []string {
590568
}
591569
}
592570
}
593-
594571
// TODO: make the list collections.Unique
595-
596572
return paths
597573
}
598574

pkg/spark/parser_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"github.com/stretchr/testify/require"
88
)
99

10+
const testerHome = "/home/tester"
11+
1012
type staticLocator struct {
1113
path string
1214
}
@@ -39,7 +41,7 @@ Host spark-two
3941
err := afero.WriteFile(fs, configPath, []byte(config), 0o600)
4042
require.NoError(t, err)
4143

42-
resolver := NewSyncConfigResolver(fs, staticLocator{path: configPath}, func() (string, error) { return "/home/tester", nil })
44+
resolver := NewSyncConfigResolver(fs, staticLocator{path: configPath}, func() (string, error) { return testerHome, nil })
4345
hosts, err := resolver.ResolveHosts()
4446
require.NoError(t, err)
4547
require.Len(t, hosts, 3)
@@ -48,7 +50,7 @@ Host spark-two
4850
require.Equal(t, "spark-alt", hosts[1].Alias)
4951
require.Equal(t, "spark-two", hosts[2].Alias)
5052

51-
require.Equal(t, "/home/tester/.ssh/spark_one", hosts[0].IdentityFile)
53+
require.Equal(t, testerHome+"/.ssh/spark_one", hosts[0].IdentityFile)
5254
require.Equal(t, "spark-one.local", hosts[0].Hostname)
5355
require.Equal(t, 2222, hosts[0].Port)
5456
require.Equal(t, "ubuntu", hosts[0].User)
@@ -60,7 +62,7 @@ Host spark-two
6062

6163
func TestResolveHostsMissingFile(t *testing.T) {
6264
fs := afero.NewMemMapFs()
63-
resolver := NewSyncConfigResolver(fs, staticLocator{path: "/tmp/missing"}, func() (string, error) { return "/home/tester", nil })
65+
resolver := NewSyncConfigResolver(fs, staticLocator{path: "/tmp/missing"}, func() (string, error) { return testerHome, nil })
6466

6567
_, err := resolver.ResolveHosts()
6668
require.Error(t, err)
@@ -77,7 +79,7 @@ Host spark-one
7779
err := afero.WriteFile(fs, configPath, []byte(config), 0o600)
7880
require.NoError(t, err)
7981

80-
resolver := NewSyncConfigResolver(fs, staticLocator{path: configPath}, func() (string, error) { return "/home/tester", nil })
82+
resolver := NewSyncConfigResolver(fs, staticLocator{path: configPath}, func() (string, error) { return testerHome, nil })
8183
_, err = resolver.ResolveHosts()
8284
require.Error(t, err)
8385
require.ErrorContains(t, err, "Hostname")

0 commit comments

Comments
 (0)