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

Diff for: .github/workflows/test.yaml

+5-10
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:

Diff for: .golangci.yml

+17
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

Diff for: ci/image/Dockerfile

+1-2
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

Diff for: ci/steps/lint.sh

+5-2
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

Diff for: internal/clog/error.go

+6-6
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

Diff for: internal/cmd/auth.go

+1-1
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) {

Diff for: internal/cmd/ceapi.go

+1-10
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-
}

Diff for: internal/cmd/envs.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ coder envs --user [email protected] 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
},

Diff for: internal/cmd/login.go

+1-1
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
},

Diff for: internal/cmd/rebuild.go

+1-2
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

Diff for: internal/cmd/resourcemanager.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func printResourceTop(writer io.Writer, groups []groupable, labeler envLabeler,
214214
if len(userResources) == 0 {
215215
clog.LogInfo(
216216
"no groups for the given filters exist with active environments",
217-
clog.Tip("run \"--show-empty\" to see groups with no resources."),
217+
clog.Tipf("run \"--show-empty\" to see groups with no resources."),
218218
)
219219
}
220220
return nil
@@ -318,13 +318,15 @@ func (a resources) String() string {
318318
// )
319319
}
320320

321+
//nolint:unused
321322
func (a resources) cpuUtilPercentage() string {
322323
if a.cpuAllocation == 0 {
323324
return "N/A"
324325
}
325326
return fmt.Sprintf("%.1f%%", a.cpuUtilization/a.cpuAllocation*100)
326327
}
327328

329+
//nolint:unused
328330
func (a resources) memUtilPercentage() string {
329331
if a.memAllocation == 0 {
330332
return "N/A"

Diff for: internal/cmd/shell.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func networkErr(client *coder.Client, env *coder.Environment) error {
201201
fmt.Sprintf("environment %q is not running", env.Name),
202202
fmt.Sprintf("its current status is %q", env.LatestStat.ContainerStatus),
203203
clog.BlankLine,
204-
clog.Tip("run \"coder envs rebuild %s --follow\" to start the environment", env.Name),
204+
clog.Tipf("run \"coder envs rebuild %s --follow\" to start the environment", env.Name),
205205
)
206206
}
207207
return xerrors.Errorf("network error, is %q online?", env.Name)

0 commit comments

Comments
 (0)