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

Commit82282b1

Browse files
authored
Enable more linting rules (#176)
1 parent89b4b36 commit82282b1

File tree

28 files changed

+170
-89
lines changed

28 files changed

+170
-89
lines changed

‎.golangci.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ linters-settings:
77
min-complexity:46
88
nestif:
99
min-complexity:10
10-
golint:
1110
govet:
1211
settings:
1312
printf:
@@ -17,6 +16,7 @@ linters-settings:
1716
-(cdr.dev/coder-cli/pkg/clog).Causef
1817
linters:
1918
disable-all:true
19+
exclude-use-default:false
2020
enable:
2121
-megacheck
2222
-govet
@@ -44,3 +44,29 @@ linters:
4444
-rowserrcheck
4545
-scopelint
4646
-goprintffuncname
47+
-gofmt
48+
-godot
49+
-ineffassign
50+
-gocritic
51+
52+
issues:
53+
exclude-use-default:false
54+
exclude:
55+
# errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
56+
-Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked
57+
# golint: False positive when tests are defined in package 'test'
58+
-func name will be used as test\.Test.* by other packages, and that stutters; consider calling this
59+
# govet: Common false positives
60+
-(possible misuse of unsafe.Pointer|should have signature)
61+
# staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
62+
-ineffective break statement. Did you mean to break out of the outer loop
63+
# gosec: Too many false-positives on 'unsafe' usage
64+
-Use of unsafe calls should be audited
65+
# gosec: Too many false-positives for parametrized shell calls
66+
-Subprocess launch(ed with variable|ing should be audited)
67+
# gosec: Duplicated errcheck checks
68+
-G104
69+
# gosec: Too many issues in popular repos
70+
-(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
71+
# gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'
72+
-Potential file inclusion via variable

‎ci/integration/setup_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
"golang.org/x/xerrors"
1414
)
1515

16-
// binpath is populated during package initialization with a path to the coder binary
16+
// binpath is populated during package initialization with a path to the coder binary.
1717
varbinpathstring
1818

19-
// initialize integration tests by building the coder-cli binary
19+
// initialize integration tests by building the coder-cli binary.
2020
funcinit() {
2121
cwd,err:=os.Getwd()
2222
iferr!=nil {
@@ -30,7 +30,7 @@ func init() {
3030
}
3131
}
3232

33-
// build the coder-cli binary and move to the integration testing bin directory
33+
// build the coder-cli binary and move to the integration testing bin directory.
3434
funcbuild(pathstring)error {
3535
tar:="coder-cli-linux-amd64.tar.gz"
3636
dir:=filepath.Dir(path)
@@ -48,7 +48,7 @@ func build(path string) error {
4848
returnnil
4949
}
5050

51-
// write session tokens to the given container runner
51+
// write session tokens to the given container runner.
5252
funcheadlessLogin(ctx context.Context,t*testing.T,runner*tcli.ContainerRunner) {
5353
creds:=login(ctx,t)
5454
cmd:=exec.CommandContext(ctx,"sh","-c","mkdir -p $HOME/.config/coder && cat > $HOME/.config/coder/session")

‎cmd/coder/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
funcmain() {
1919
ctx,cancel:=context.WithCancel(context.Background())
20-
defercancel()
2120

2221
// If requested, spin up the pprof webserver.
2322
ifos.Getenv("PPROF")!="" {
@@ -29,18 +28,23 @@ func main() {
2928
stdoutState,err:=xterminal.MakeOutputRaw(os.Stdout.Fd())
3029
iferr!=nil {
3130
clog.Log(clog.Fatal(fmt.Sprintf("set output to raw: %s",err)))
31+
cancel()
3232
os.Exit(1)
3333
}
34-
deferfunc() {
34+
restoreTerminal:=func() {
3535
// Best effort. Would result in broken terminal on window but nothing we can do about it.
3636
_=xterminal.Restore(os.Stdout.Fd(),stdoutState)
37-
}()
37+
}
3838

3939
app:=cmd.Make()
4040
app.Version=fmt.Sprintf("%s %s %s/%s",version.Version,runtime.Version(),runtime.GOOS,runtime.GOARCH)
4141

4242
iferr:=app.ExecuteContext(ctx);err!=nil {
4343
clog.Log(err)
44+
cancel()
45+
restoreTerminal()
4446
os.Exit(1)
4547
}
48+
cancel()
49+
restoreTerminal()
4650
}

‎coder-sdk/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"net/url"
77
)
88

9-
// Me is the route param to access resources of the authenticated user
9+
// Me is the route param to access resources of the authenticated user.
1010
constMe="me"
1111

12-
// Client wraps the Coder HTTP API
12+
// Client wraps the Coder HTTP API.
1313
typeClientstruct {
1414
BaseURL*url.URL
1515
Tokenstring

‎coder-sdk/config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
)
77

8+
// AuthProviderType is an enum of each valid auth provider.
89
typeAuthProviderTypestring
910

1011
// AuthProviderType enum.
@@ -14,18 +15,21 @@ const (
1415
AuthProviderOIDCAuthProviderType="oidc"
1516
)
1617

18+
// ConfigAuth describes the authentication configuration for a Coder Enterprise deployment.
1719
typeConfigAuthstruct {
1820
ProviderType*AuthProviderType`json:"provider_type"`
1921
OIDC*ConfigOIDC`json:"oidc"`
2022
SAML*ConfigSAML`json:"saml"`
2123
}
2224

25+
// ConfigOIDC describes the OIDC configuration for single-signon support in Coder Enterprise.
2326
typeConfigOIDCstruct {
2427
ClientID*string`json:"client_id"`
2528
ClientSecret*string`json:"client_secret"`
2629
Issuer*string`json:"issuer"`
2730
}
2831

32+
// ConfigSAML describes the SAML configuration values.
2933
typeConfigSAMLstruct {
3034
IdentityProviderMetadataURL*string`json:"idp_metadata_url"`
3135
SignatureAlgorithm*string`json:"signature_algorithm"`
@@ -34,28 +38,33 @@ type ConfigSAML struct {
3438
PublicKeyCertificate*string`json:"public_key_certificate"`
3539
}
3640

41+
// ConfigOAuthBitbucketServer describes the Bitbucket integration configuration for a Coder Enterprise deployment.
3742
typeConfigOAuthBitbucketServerstruct {
3843
BaseURLstring`json:"base_url" diff:"oauth.bitbucket_server.base_url"`
3944
}
4045

46+
// ConfigOAuthGitHub describes the Github integration configuration for a Coder Enterprise deployment.
4147
typeConfigOAuthGitHubstruct {
4248
BaseURLstring`json:"base_url"`
4349
ClientIDstring`json:"client_id"`
4450
ClientSecretstring`json:"client_secret"`
4551
}
4652

53+
// ConfigOAuthGitLab describes the GitLab integration configuration for a Coder Enterprise deployment.
4754
typeConfigOAuthGitLabstruct {
4855
BaseURLstring`json:"base_url"`
4956
ClientIDstring`json:"client_id" `
5057
ClientSecretstring`json:"client_secret"`
5158
}
5259

60+
// ConfigOAuth describes the aggregate git integration configuration for a Coder Enterprise deployment.
5361
typeConfigOAuthstruct {
5462
BitbucketServerConfigOAuthBitbucketServer`json:"bitbucket_server"`
5563
GitHubConfigOAuthGitHub`json:"github"`
5664
GitLabConfigOAuthGitLab`json:"gitlab"`
5765
}
5866

67+
// SiteConfigAuth fetches the sitewide authentication configuration.
5968
func (cClient)SiteConfigAuth(ctx context.Context) (*ConfigAuth,error) {
6069
varconfConfigAuth
6170
iferr:=c.requestBody(ctx,http.MethodGet,"/api/auth/config",nil,&conf);err!=nil {
@@ -64,10 +73,12 @@ func (c Client) SiteConfigAuth(ctx context.Context) (*ConfigAuth, error) {
6473
return&conf,nil
6574
}
6675

76+
// PutSiteConfigAuth sets the sitewide authentication configuration.
6777
func (cClient)PutSiteConfigAuth(ctx context.Context,reqConfigAuth)error {
6878
returnc.requestBody(ctx,http.MethodPut,"/api/auth/config",req,nil)
6979
}
7080

81+
// SiteConfigOAuth fetches the sitewide git provider OAuth configuration.
7182
func (cClient)SiteConfigOAuth(ctx context.Context) (*ConfigOAuth,error) {
7283
varconfConfigOAuth
7384
iferr:=c.requestBody(ctx,http.MethodGet,"/api/oauth/config",nil,&conf);err!=nil {
@@ -76,6 +87,7 @@ func (c Client) SiteConfigOAuth(ctx context.Context) (*ConfigOAuth, error) {
7687
return&conf,nil
7788
}
7889

90+
// PutSiteConfigOAuth sets the sitewide git provider OAuth configuration.
7991
func (cClient)PutSiteConfigOAuth(ctx context.Context,reqConfigOAuth)error {
8092
returnc.requestBody(ctx,http.MethodPut,"/api/oauth/config",req,nil)
8193
}
@@ -84,6 +96,7 @@ type configSetupMode struct {
8496
SetupModebool`json:"setup_mode"`
8597
}
8698

99+
// SiteSetupModeEnabled fetches the current setup_mode state of a Coder Enterprise deployment.
87100
func (cClient)SiteSetupModeEnabled(ctx context.Context) (bool,error) {
88101
varconfconfigSetupMode
89102
iferr:=c.requestBody(ctx,http.MethodGet,"/api/config/setup-mode",nil,&conf);err!=nil {
@@ -92,6 +105,7 @@ func (c Client) SiteSetupModeEnabled(ctx context.Context) (bool, error) {
92105
returnconf.SetupMode,nil
93106
}
94107

108+
// ExtensionMarketplaceType is an enum of the valid extension marketplace configurations.
95109
typeExtensionMarketplaceTypestring
96110

97111
// ExtensionMarketplaceType enum.
@@ -101,13 +115,16 @@ const (
101115
ExtensionMarketplacePublicExtensionMarketplaceType="public"
102116
)
103117

118+
// MarketplaceExtensionPublicURL is the URL of the coder.com public marketplace that serves open source Code OSS extensions.
104119
constMarketplaceExtensionPublicURL="https://extensions.coder.com/api"
105120

121+
// ConfigExtensionMarketplace describes the sitewide extension marketplace configuration.
106122
typeConfigExtensionMarketplacestruct {
107123
URLstring`json:"url"`
108124
TypeExtensionMarketplaceType`json:"type"`
109125
}
110126

127+
// SiteConfigExtensionMarketplace fetches the extension marketplace configuration.
111128
func (cClient)SiteConfigExtensionMarketplace(ctx context.Context) (*ConfigExtensionMarketplace,error) {
112129
varconfConfigExtensionMarketplace
113130
iferr:=c.requestBody(ctx,http.MethodGet,"/api/extensions/config",nil,&conf);err!=nil {
@@ -116,6 +133,7 @@ func (c Client) SiteConfigExtensionMarketplace(ctx context.Context) (*ConfigExte
116133
return&conf,nil
117134
}
118135

136+
// PutSiteConfigExtensionMarketplace sets the extension marketplace configuration.
119137
func (cClient)PutSiteConfigExtensionMarketplace(ctx context.Context,reqConfigExtensionMarketplace)error {
120138
returnc.requestBody(ctx,http.MethodPut,"/api/extensions/config",req,nil)
121139
}

‎coder-sdk/env.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"nhooyr.io/websocket/wsjson"
1111
)
1212

13-
// Environment describes a Coder environment
13+
// Environment describes a Coder environment.
1414
typeEnvironmentstruct {
1515
IDstring`json:"id" table:"-"`
1616
Namestring`json:"name" table:"Name"`
@@ -40,7 +40,7 @@ type RebuildMessage struct {
4040
AutoOffThresholdDuration`json:"auto_off_threshold"`
4141
}
4242

43-
// EnvironmentStat represents the state of an environment
43+
// EnvironmentStat represents the state of an environment.
4444
typeEnvironmentStatstruct {
4545
Time time.Time`json:"time"`
4646
LastOnline time.Time`json:"last_online"`
@@ -58,7 +58,7 @@ func (e EnvironmentStat) String() string { return string(e.ContainerStatus) }
5858
// EnvironmentStatus refers to the states of an environment.
5959
typeEnvironmentStatusstring
6060

61-
// The following represent the possible environment container states
61+
// The following represent the possible environment container states.
6262
const (
6363
EnvironmentCreatingEnvironmentStatus="CREATING"
6464
EnvironmentOffEnvironmentStatus="OFF"
@@ -89,7 +89,7 @@ func (c Client) CreateEnvironment(ctx context.Context, orgID string, req CreateE
8989
}
9090

9191
// Environments lists environments returned by the given filter.
92-
// TODO: add the filter options, explore performanceissues
92+
// TODO: add the filter options, explore performanceissue.
9393
func (cClient)Environments(ctx context.Context) ([]Environment,error) {
9494
varenvs []Environment
9595
iferr:=c.requestBody(ctx,http.MethodGet,"/api/environments",nil,&envs);err!=nil {
@@ -146,7 +146,7 @@ func (c Client) DialWsep(ctx context.Context, env *Environment) (*websocket.Conn
146146
returnc.dialWebsocket(ctx,"/proxy/environments/"+env.ID+"/wsep")
147147
}
148148

149-
// DialIDEStatus opens a websocket connection for cpu load metrics on the environment
149+
// DialIDEStatus opens a websocket connection for cpu load metrics on the environment.
150150
func (cClient)DialIDEStatus(ctx context.Context,envIDstring) (*websocket.Conn,error) {
151151
returnc.dialWebsocket(ctx,"/proxy/environments/"+envID+"/ide/api/status")
152152
}
@@ -204,7 +204,7 @@ func (c Client) DialEnvironmentStats(ctx context.Context, envID string) (*websoc
204204
returnc.dialWebsocket(ctx,"/api/environments/"+envID+"/watch-stats")
205205
}
206206

207-
// DialResourceLoad opens a websocket connection for cpu load metrics on the environment
207+
// DialResourceLoad opens a websocket connection for cpu load metrics on the environment.
208208
func (cClient)DialResourceLoad(ctx context.Context,envIDstring) (*websocket.Conn,error) {
209209
returnc.dialWebsocket(ctx,"/api/environments/"+envID+"/watch-resource-load")
210210
}
@@ -233,7 +233,7 @@ type buildLogMsg struct {
233233
TypeBuildLogType`json:"type"`
234234
}
235235

236-
// WaitForEnvironmentReady will watch the build log and return when done
236+
// WaitForEnvironmentReady will watch the build log and return when done.
237237
func (cClient)WaitForEnvironmentReady(ctx context.Context,env*Environment)error {
238238
conn,err:=c.DialEnvironmentBuildLog(ctx,env.ID)
239239
iferr!=nil {

‎coder-sdk/error.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ import (
99
"golang.org/x/xerrors"
1010
)
1111

12-
// ErrNotFound describes an error case in which the requested resource could not be found
13-
varErrNotFound=xerrors.Errorf("resource not found")
12+
// ErrNotFound describes an error case in which the requested resource could not be found.
13+
varErrNotFound=xerrors.New("resource not found")
14+
15+
// ErrPermissions describes an error case in which the requester has insufficient permissions to access the requested resource.
16+
varErrPermissions=xerrors.New("insufficient permissions")
17+
18+
// ErrAuthentication describes the error case in which the requester has invalid authentication.
19+
varErrAuthentication=xerrors.New("invalid authentication")
1420

1521
// APIError is the expected payload format for our errors.
1622
typeAPIErrorstruct {

‎coder-sdk/image.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"net/http"
66
)
77

8-
// Image describes a Coder Image
8+
// Image describes a Coder Image.
99
typeImagestruct {
1010
IDstring`json:"id"`
1111
OrganizationIDstring`json:"organization_id"`
@@ -18,15 +18,15 @@ type Image struct {
1818
Deprecatedbool`json:"deprecated"`
1919
}
2020

21-
// NewRegistryRequest describes a docker registry used in importing an image
21+
// NewRegistryRequest describes a docker registry used in importing an image.
2222
typeNewRegistryRequeststruct {
2323
FriendlyNamestring`json:"friendly_name"`
2424
Registrystring`json:"registry"`
2525
Usernamestring`json:"username"`
2626
Passwordstring`json:"password"`
2727
}
2828

29-
// ImportImageReq is used to import new images and registries into Coder
29+
// ImportImageReq is used to import new images and registries into Coder.
3030
typeImportImageReqstruct {
3131
RegistryID*string`json:"registry_id"`// Used to import images to existing registries.
3232
NewRegistry*NewRegistryRequest`json:"new_registry"`// Used when adding a new registry.
@@ -39,7 +39,7 @@ type ImportImageReq struct {
3939
URLstring`json:"url"`
4040
}
4141

42-
// ImportImage creates a new image and optionally a new registry
42+
// ImportImage creates a new image and optionally a new registry.
4343
func (cClient)ImportImage(ctx context.Context,orgIDstring,reqImportImageReq) (*Image,error) {
4444
varimgImage
4545
iferr:=c.requestBody(ctx,http.MethodPost,"/api/orgs/"+orgID+"/images",req,&img);err!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp