Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit b3a91b7

Browse files
authored
Add golangci and fix errors (#154)
1 parent 924ebad commit b3a91b7

File tree

12 files changed

+47
-41
lines changed

12 files changed

+47
-41
lines changed

.github/workflows/test.yaml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,12 @@ jobs:
1919
lint:
2020
runs-on: ubuntu-latest
2121
steps:
22-
- uses: actions/checkout@v1
23-
- uses: actions/cache@v1
24-
with:
25-
path: ~/go/pkg/mod
26-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27-
restore-keys: |
28-
${{ runner.os }}-go-
29-
- name: lint
30-
uses: ./ci/image
22+
- uses: actions/checkout@v2
23+
- name: golangci-lint
24+
uses: golangci/golangci-lint-action@v2
3125
with:
32-
args: ./ci/steps/lint.sh
26+
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
27+
version: v1.29
3328
test:
3429
runs-on: ubuntu-latest
3530
steps:

.golangci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# See https://golangci-lint.run/usage/configuration/
2+
linters-settings:
3+
goconst:
4+
min-len: 4
5+
min-occurrences: 3
6+
gocognit:
7+
min-complexity: 46
8+
nestif:
9+
min-complexity: 10
10+
golint:
11+
govet:
12+
settings:
13+
printf:
14+
funcs: # Run `go tool vet help printf` to see available settings for `printf` analyzer.
15+
- (cdr.dev/coder-cli/internal/clog).Tipf
16+
- (cdr.dev/coder-cli/internal/clog).Hintf
17+
- (cdr.dev/coder-cli/internal/clog).Causef

ci/image/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ ENV GOFLAGS="-mod=readonly"
44
ENV CI=true
55

66
RUN go get golang.org/x/tools/cmd/goimports
7-
RUN go get golang.org/x/lint/golint
8-
RUN go get github.com/mattn/goveralls
7+
RUN go get github.com/mattn/goveralls

ci/steps/lint.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ set -euo pipefail
44

55
echo "Linting..."
66

7-
go vet ./...
8-
golint -set_exit_status ./...
7+
cd "$(dirname "$0")"
8+
cd ../../
9+
10+
echo "--- golangci-lint"
11+
golangci-lint run -c .golangci.yml

internal/clog/error.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,18 @@ func Bold(a string) string {
112112
return color.New(color.Bold).Sprint(a)
113113
}
114114

115-
// Tip formats according to the given format specifier and prepends a bolded "tip: " header.
116-
func Tip(format string, a ...interface{}) string {
115+
// Tipf formats according to the given format specifier and prepends a bolded "tip: " header.
116+
func Tipf(format string, a ...interface{}) string {
117117
return fmt.Sprintf("%s %s", Bold("tip:"), fmt.Sprintf(format, a...))
118118
}
119119

120-
// Hint formats according to the given format specifier and prepends a bolded "hint: " header.
121-
func Hint(format string, a ...interface{}) string {
120+
// Hintf formats according to the given format specifier and prepends a bolded "hint: " header.
121+
func Hintf(format string, a ...interface{}) string {
122122
return fmt.Sprintf("%s %s", Bold("hint:"), fmt.Sprintf(format, a...))
123123
}
124124

125-
// Cause formats according to the given format specifier and prepends a bolded "cause: " header.
126-
func Cause(format string, a ...interface{}) string {
125+
// Causef formats according to the given format specifier and prepends a bolded "cause: " header.
126+
func Causef(format string, a ...interface{}) string {
127127
return fmt.Sprintf("%s %s", Bold("cause:"), fmt.Sprintf(format, a...))
128128
}
129129

internal/cmd/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
var errNeedLogin = clog.Fatal(
1616
"failed to read session credentials",
17-
clog.Hint(`did you run "coder login [https://coder.domain.com]"?`),
17+
clog.Hintf(`did you run "coder login [https://coder.domain.com]"?`),
1818
)
1919

2020
func newClient() (*coder.Client, error) {

internal/cmd/ceapi.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,6 @@ func findEnv(ctx context.Context, client *coder.Client, envName, userEmail strin
7878
"failed to find environment",
7979
fmt.Sprintf("environment %q not found in %q", envName, found),
8080
clog.BlankLine,
81-
clog.Tip("run \"coder envs ls\" to view your environments"),
81+
clog.Tipf("run \"coder envs ls\" to view your environments"),
8282
)
8383
}
84-
85-
type notFoundButDidFind struct {
86-
needle string
87-
haystack []string
88-
}
89-
90-
func (n notFoundButDidFind) Error() string {
91-
return fmt.Sprintf("\"%s\" not found in %q: %v", n.needle, n.haystack, coder.ErrNotFound)
92-
}

internal/cmd/envs.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ coder envs --user charlie@coder.com ls -o json \
117117
if err = client.StopEnvironment(cmd.Context(), env.ID); err != nil {
118118
atomic.AddInt32(&fails, 1)
119119
err = clog.Fatal(fmt.Sprintf("stop environment %q", env.Name),
120-
clog.Cause(err.Error()), clog.BlankLine,
121-
clog.Hint("current environment status is %q", env.LatestStat.ContainerStatus),
120+
clog.Causef(err.Error()), clog.BlankLine,
121+
clog.Hintf("current environment status is %q", env.LatestStat.ContainerStatus),
122122
)
123123
clog.Log(err)
124124
return err
@@ -186,7 +186,7 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
186186
clog.LogSuccess(
187187
"creating environment...",
188188
clog.BlankLine,
189-
clog.Tip(`run "coder envs watch-build %q" to trail the build logs`, args[0]),
189+
clog.Tipf(`run "coder envs watch-build %q" to trail the build logs`, args[0]),
190190
)
191191

192192
if follow {
@@ -205,7 +205,7 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
205205
cmd.Flags().IntP("gpus", "g", defaultGPUs, "number GPUs an environment should be provisioned with.")
206206
cmd.Flags().StringVarP(&img, "image", "i", "", "ID of the image to base the environment off of.")
207207
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild")
208-
cmd.MarkFlagRequired("image")
208+
_ = cmd.MarkFlagRequired("image")
209209
return cmd
210210
}
211211

@@ -296,7 +296,7 @@ coder envs edit back-end-env --disk 20`,
296296
clog.LogSuccess(
297297
"applied changes to the environment, rebuilding...",
298298
clog.BlankLine,
299-
clog.Tip(`run "coder envs watch-build %q" to trail the build logs`, envName),
299+
clog.Tipf(`run "coder envs watch-build %q" to trail the build logs`, envName),
300300
)
301301
return nil
302302
},

internal/cmd/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func makeLoginCmd() *cobra.Command {
4040
// Don't return errors as it would print the usage.
4141

4242
if err := login(cmd, u, config.URL, config.Session); err != nil {
43-
return xerrors.Errorf("Login error", err)
43+
return xerrors.Errorf("login error: %w", err)
4444
}
4545
return nil
4646
},

internal/cmd/rebuild.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ coder envs rebuild backend-env --force`,
5858
} else {
5959
clog.LogSuccess(
6060
"successfully started rebuild",
61-
clog.Tip("run \"coder envs watch-build %s\" to follow the build logs", env.Name),
61+
clog.Tipf("run \"coder envs watch-build %s\" to follow the build logs", env.Name),
6262
)
6363
}
6464
return nil
@@ -75,7 +75,6 @@ coder envs rebuild backend-env --force`,
7575
func trailBuildLogs(ctx context.Context, client *coder.Client, envID string) error {
7676
const check = "✅"
7777
const failure = "❌"
78-
const loading = "⌛"
7978

8079
newSpinner := func() *spinner.Spinner { return spinner.New(spinner.CharSets[11], 100*time.Millisecond) }
8180

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy