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

Add golangci and fix errors#154

Merged
cmoog merged 1 commit intomasterfrommore-linting
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions.github/workflows/test.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,17 +19,12 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: lint
uses: ./ci/image
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
args: ./ci/steps/lint.sh
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.29
test:
runs-on: ubuntu-latest
steps:
Expand Down
17 changes: 17 additions & 0 deletions.golangci.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
# See https://golangci-lint.run/usage/configuration/
linters-settings:
goconst:
min-len: 4
min-occurrences: 3
gocognit:
min-complexity: 46
nestif:
min-complexity: 10
golint:
govet:
settings:
printf:
funcs: # Run `go tool vet help printf` to see available settings for `printf` analyzer.
- (cdr.dev/coder-cli/internal/clog).Tipf
- (cdr.dev/coder-cli/internal/clog).Hintf
- (cdr.dev/coder-cli/internal/clog).Causef
3 changes: 1 addition & 2 deletionsci/image/Dockerfile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,5 +4,4 @@ ENV GOFLAGS="-mod=readonly"
ENV CI=true

RUN go get golang.org/x/tools/cmd/goimports
RUN go get golang.org/x/lint/golint
RUN go get github.com/mattn/goveralls
RUN go get github.com/mattn/goveralls
7 changes: 5 additions & 2 deletionsci/steps/lint.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,5 +4,8 @@ set -euo pipefail

echo "Linting..."

go vet ./...
golint -set_exit_status ./...
cd "$(dirname "$0")"
cd ../../

echo "--- golangci-lint"
golangci-lint run -c .golangci.yml
12 changes: 6 additions & 6 deletionsinternal/clog/error.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,18 +112,18 @@ func Bold(a string) string {
return color.New(color.Bold).Sprint(a)
}

//Tip formats according to the given format specifier and prepends a bolded "tip: " header.
funcTip(format string, a ...interface{}) string {
//Tipf formats according to the given format specifier and prepends a bolded "tip: " header.
funcTipf(format string, a ...interface{}) string {
return fmt.Sprintf("%s %s", Bold("tip:"), fmt.Sprintf(format, a...))
}

//Hint formats according to the given format specifier and prepends a bolded "hint: " header.
funcHint(format string, a ...interface{}) string {
//Hintf formats according to the given format specifier and prepends a bolded "hint: " header.
funcHintf(format string, a ...interface{}) string {
return fmt.Sprintf("%s %s", Bold("hint:"), fmt.Sprintf(format, a...))
}

//Cause formats according to the given format specifier and prepends a bolded "cause: " header.
funcCause(format string, a ...interface{}) string {
//Causef formats according to the given format specifier and prepends a bolded "cause: " header.
funcCausef(format string, a ...interface{}) string {
return fmt.Sprintf("%s %s", Bold("cause:"), fmt.Sprintf(format, a...))
}

Expand Down
2 changes: 1 addition & 1 deletioninternal/cmd/auth.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ import (

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

func newClient() (*coder.Client, error) {
Expand Down
11 changes: 1 addition & 10 deletionsinternal/cmd/ceapi.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,15 +78,6 @@ func findEnv(ctx context.Context, client *coder.Client, envName, userEmail strin
"failed to find environment",
fmt.Sprintf("environment %q not found in %q", envName, found),
clog.BlankLine,
clog.Tip("run \"coder envs ls\" to view your environments"),
clog.Tipf("run \"coder envs ls\" to view your environments"),
)
}

type notFoundButDidFind struct {
needle string
haystack []string
}

func (n notFoundButDidFind) Error() string {
return fmt.Sprintf("\"%s\" not found in %q: %v", n.needle, n.haystack, coder.ErrNotFound)
}
10 changes: 5 additions & 5 deletionsinternal/cmd/envs.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -117,8 +117,8 @@ coder envs --user charlie@coder.com ls -o json \
if err = client.StopEnvironment(cmd.Context(), env.ID); err != nil {
atomic.AddInt32(&fails, 1)
err = clog.Fatal(fmt.Sprintf("stop environment %q", env.Name),
clog.Cause(err.Error()), clog.BlankLine,
clog.Hint("current environment status is %q", env.LatestStat.ContainerStatus),
clog.Causef(err.Error()), clog.BlankLine,
clog.Hintf("current environment status is %q", env.LatestStat.ContainerStatus),
)
clog.Log(err)
return err
Expand DownExpand Up@@ -186,7 +186,7 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
clog.LogSuccess(
"creating environment...",
clog.BlankLine,
clog.Tip(`run "coder envs watch-build %q" to trail the build logs`, args[0]),
clog.Tipf(`run "coder envs watch-build %q" to trail the build logs`, args[0]),
)

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

Expand DownExpand Up@@ -296,7 +296,7 @@ coder envs edit back-end-env --disk 20`,
clog.LogSuccess(
"applied changes to the environment, rebuilding...",
clog.BlankLine,
clog.Tip(`run "coder envs watch-build %q" to trail the build logs`, envName),
clog.Tipf(`run "coder envs watch-build %q" to trail the build logs`, envName),
)
return nil
},
Expand Down
2 changes: 1 addition & 1 deletioninternal/cmd/login.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ func makeLoginCmd() *cobra.Command {
// Don't return errors as it would print the usage.

if err := login(cmd, u, config.URL, config.Session); err != nil {
return xerrors.Errorf("Login error", err)
return xerrors.Errorf("login error: %w", err)
}
return nil
},
Expand Down
3 changes: 1 addition & 2 deletionsinternal/cmd/rebuild.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,7 @@ coder envs rebuild backend-env --force`,
} else {
clog.LogSuccess(
"successfully started rebuild",
clog.Tip("run \"coder envs watch-build %s\" to follow the build logs", env.Name),
clog.Tipf("run \"coder envs watch-build %s\" to follow the build logs", env.Name),
)
}
return nil
Expand All@@ -75,7 +75,6 @@ coder envs rebuild backend-env --force`,
func trailBuildLogs(ctx context.Context, client *coder.Client, envID string) error {
const check = "✅"
const failure = "❌"
const loading = "⌛"

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

Expand Down
4 changes: 3 additions & 1 deletioninternal/cmd/resourcemanager.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -214,7 +214,7 @@ func printResourceTop(writer io.Writer, groups []groupable, labeler envLabeler,
if len(userResources) == 0 {
clog.LogInfo(
"no groups for the given filters exist with active environments",
clog.Tip("run \"--show-empty\" to see groups with no resources."),
clog.Tipf("run \"--show-empty\" to see groups with no resources."),
)
}
return nil
Expand DownExpand Up@@ -318,13 +318,15 @@ func (a resources) String() string {
// )
}

//nolint:unused
func (a resources) cpuUtilPercentage() string {
if a.cpuAllocation == 0 {
return "N/A"
}
return fmt.Sprintf("%.1f%%", a.cpuUtilization/a.cpuAllocation*100)
}

//nolint:unused
func (a resources) memUtilPercentage() string {
if a.memAllocation == 0 {
return "N/A"
Expand Down
2 changes: 1 addition & 1 deletioninternal/cmd/shell.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,7 +201,7 @@ func networkErr(client *coder.Client, env *coder.Environment) error {
fmt.Sprintf("environment %q is not running", env.Name),
fmt.Sprintf("its current status is %q", env.LatestStat.ContainerStatus),
clog.BlankLine,
clog.Tip("run \"coder envs rebuild %s --follow\" to start the environment", env.Name),
clog.Tipf("run \"coder envs rebuild %s --follow\" to start the environment", env.Name),
)
}
return xerrors.Errorf("network error, is %q online?", env.Name)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp