Skip to content

Commit

Permalink
Linter review (#276)
Browse files Browse the repository at this point in the history
I reviewed the available linters in golangci-lint and added the ones
that I thought useful.
  • Loading branch information
EduardGomezEscandell authored Sep 15, 2023
2 parents 2108e8e + 53c6de8 commit 0c9d09f
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ linters:
# linters to run in addition to default ones
enable:
- dupl
- dupword
- durationcheck
- errname
- errorlint
- exportloopref
- forbidigo
- forcetypeassert
- gci
- gocheckcompilerdirectives
- godot
- gofmt
- gosec
Expand All @@ -23,6 +25,7 @@ linters:
- tparallel
- unconvert
- unparam
- usestdlibvars
- whitespace

run:
Expand Down
2 changes: 1 addition & 1 deletion agentapi/generator_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package agentapi

//go:generate wsl -- bash -c "source ~/.profile && ./generate.sh"

// Sourcing.profile because wsl -- <SCRIPT> does not not do it automatically
// Sourcing.profile because wsl -- <SCRIPT> does not do it automatically
2 changes: 1 addition & 1 deletion windows-agent/generate/generate-locales.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build: tools
//go:build tools

// Package generate generates the i18n files
package generate
Expand Down
2 changes: 1 addition & 1 deletion windows-agent/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func TestFetchMicrosoftStoreSubscription(t *testing.T) {
}
}

// is is a convenience function to check if a registryState matches a certain state.
// is defines equality between flags. It is convenience function to check if a registryState matches a certain state.
func (state registryState) is(flag registryState) bool {
return state&flag == flag
}
Expand Down
8 changes: 4 additions & 4 deletions windows-agent/internal/contracts/contractclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *Client) GetServerAccessToken(ctx context.Context) (token string, err er
}

defer res.Body.Close()
if res.StatusCode != 200 {
if res.StatusCode != http.StatusOK {
body, err := io.ReadAll(res.Body)
if err != nil {
return "", fmt.Errorf("server replied with an error: Code %d, %v", res.StatusCode, err)
Expand Down Expand Up @@ -109,17 +109,17 @@ func (c *Client) GetProToken(ctx context.Context, userJWT string) (token string,

defer res.Body.Close()
switch res.StatusCode { // add other error codes as CS team documents them.
case 401:
case http.StatusUnauthorized:
return "", fmt.Errorf("bad user ID key: %v", userJWT)
case 500:
case http.StatusInternalServerError:
return "", errors.New("couldn't validate the user entitlement against MS Store")
default:
body, err := io.ReadAll(res.Body)
if err != nil {
return "", fmt.Errorf("unknown error from the contracts server: Code %d, %v", res.StatusCode, err)
}
return "", fmt.Errorf("unknown error from the contracts server: Code %d, %s", res.StatusCode, body)
case 200:
case http.StatusOK:
}

var data map[string]string
Expand Down
4 changes: 2 additions & 2 deletions windows-agent/internal/distros/worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestTaskProcessing(t *testing.T) {
time.Sleep(clientTickPeriod)
}

// Testing task with with active connection
// Testing task with active connection
w.SetConnection(conn)

if !tc.wantExecuteCalled {
Expand Down Expand Up @@ -470,7 +470,7 @@ func TestTaskDeferral(t *testing.T) {
queuedTask := emptyTask{ID: uuid.NewString()}
deferredTask := emptyTask{ID: uuid.NewString()}

// Testing task with with active connection
// Testing task with active connection
wslInstanceService := newTestService(t)
conn := wslInstanceService.newClientConnection(t)
w.SetConnection(conn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func CreateUser(ctx context.Context, d gowsl.Distro, userName string, userFullNa
}

if valid := UsernameIsValid(userName); !valid {
return 0, errors.New("username is is not valid")
return 0, errors.New("username is not valid")
}

// strip any punctuation or any math symbols, currency signs, dingbats, box-drawing characters, etc
Expand Down
2 changes: 1 addition & 1 deletion windows-agent/internal/proservices/ui/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestGetSubscriptionInfo(t *testing.T) {
"Success with a store subscription": {config: mockConfig{source: config.SubscriptionMicrosoftStore}, wantType: store},
"Success with a read-only store subscription": {config: mockConfig{source: config.SubscriptionMicrosoftStore, registryReadOnly: true}, wantType: store, wantImmutable: true},

"Error when the the read-only check fails": {config: mockConfig{isReadOnlyErr: true}, wantErr: true},
"Error when the read-only check fails": {config: mockConfig{isReadOnlyErr: true}, wantErr: true},
"Error when the subscription cannot be retreived": {config: mockConfig{subscriptionErr: true}, wantErr: true},
}

Expand Down
2 changes: 1 addition & 1 deletion wsl-pro-service/generate/generate-locales.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build: tools
//go:build tools

// Package generate generates the i18n files
package generate
Expand Down
4 changes: 2 additions & 2 deletions wsl-pro-service/internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func connectToControlStream(ctx context.Context, agentPortFilePath string, s sys

func getControlStreamAddress(agentPortFilePath string, s system.System) (string, error) {
/*
We parse the the port from the file written by the windows agent.
We parse the port from the file written by the windows agent.
*/
addr, err := os.ReadFile(agentPortFilePath)
if err != nil {
Expand All @@ -171,7 +171,7 @@ func getControlStreamAddress(agentPortFilePath string, s system.System) (string,

/*
We parse the IP address of the Windows host /etc/resolv.conf to know. We cannot use localhost
because WSL localhost forwarding only works for for Linux-side servers.
because WSL localhost forwarding only works for Linux-side servers.
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
Expand Down

0 comments on commit 0c9d09f

Please sign in to comment.