Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commitb3a91b7

Browse files
authored
Add golangci and fix errors (#154)
1 parent924ebad commitb3a91b7

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
returncolor.New(color.Bold).Sprint(a)
113113
}
114114

115-
//Tip formats according to the given format specifier and prepends a bolded "tip: " header.
116-
funcTip(formatstring,a...interface{})string {
115+
//Tipf formats according to the given format specifier and prepends a bolded "tip: " header.
116+
funcTipf(formatstring,a...interface{})string {
117117
returnfmt.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-
funcHint(formatstring,a...interface{})string {
120+
//Hintf formats according to the given format specifier and prepends a bolded "hint: " header.
121+
funcHintf(formatstring,a...interface{})string {
122122
returnfmt.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-
funcCause(formatstring,a...interface{})string {
125+
//Causef formats according to the given format specifier and prepends a bolded "cause: " header.
126+
funcCausef(formatstring,a...interface{})string {
127127
returnfmt.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
varerrNeedLogin=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
funcnewClient() (*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-
typenotFoundButDidFindstruct {
86-
needlestring
87-
haystack []string
88-
}
89-
90-
func (nnotFoundButDidFind)Error()string {
91-
returnfmt.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
iferr=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
returnerr
@@ -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
iffollow {
@@ -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
returncmd
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
returnnil
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
iferr:=login(cmd,u,config.URL,config.Session);err!=nil {
43-
returnxerrors.Errorf("Login error",err)
43+
returnxerrors.Errorf("login error: %w",err)
4444
}
4545
returnnil
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
returnnil
@@ -75,7 +75,6 @@ coder envs rebuild backend-env --force`,
7575
functrailBuildLogs(ctx context.Context,client*coder.Client,envIDstring)error {
7676
constcheck="✅"
7777
constfailure="❌"
78-
constloading="⌛"
7978

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

‎internal/cmd/resourcemanager.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func printResourceTop(writer io.Writer, groups []groupable, labeler envLabeler,
214214
iflen(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
returnnil
@@ -318,13 +318,15 @@ func (a resources) String() string {
318318
// )
319319
}
320320

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

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

‎internal/cmd/shell.go

Lines changed: 1 addition & 1 deletion
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
returnxerrors.Errorf("network error, is %q online?",env.Name)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp