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

Commit 82282b1

Browse files
authored
Enable more linting rules (#176)
1 parent 89b4b36 commit 82282b1

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
var binpath string
1818

19-
// initialize integration tests by building the coder-cli binary
19+
// initialize integration tests by building the coder-cli binary.
2020
func init() {
2121
cwd, err := os.Getwd()
2222
if err != 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
func build(path string) error {
3535
tar := "coder-cli-linux-amd64.tar.gz"
3636
dir := filepath.Dir(path)
@@ -48,7 +48,7 @@ func build(path string) error {
4848
return nil
4949
}
5050

51-
// write session tokens to the given container runner
51+
// write session tokens to the given container runner.
5252
func headlessLogin(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
func main() {
1919
ctx, cancel := context.WithCancel(context.Background())
20-
defer cancel()
2120

2221
// If requested, spin up the pprof webserver.
2322
if os.Getenv("PPROF") != "" {
@@ -29,18 +28,23 @@ func main() {
2928
stdoutState, err := xterminal.MakeOutputRaw(os.Stdout.Fd())
3029
if err != nil {
3130
clog.Log(clog.Fatal(fmt.Sprintf("set output to raw: %s", err)))
31+
cancel()
3232
os.Exit(1)
3333
}
34-
defer func() {
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
if err := 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
const Me = "me"
1111

12-
// Client wraps the Coder HTTP API
12+
// Client wraps the Coder HTTP API.
1313
type Client struct {
1414
BaseURL *url.URL
1515
Token string

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
type AuthProviderType string
910

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

18+
// ConfigAuth describes the authentication configuration for a Coder Enterprise deployment.
1719
type ConfigAuth struct {
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
type ConfigOIDC struct {
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
type ConfigSAML struct {
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
type ConfigOAuthBitbucketServer struct {
3843
BaseURL string `json:"base_url" diff:"oauth.bitbucket_server.base_url"`
3944
}
4045

46+
// ConfigOAuthGitHub describes the Github integration configuration for a Coder Enterprise deployment.
4147
type ConfigOAuthGitHub struct {
4248
BaseURL string `json:"base_url"`
4349
ClientID string `json:"client_id"`
4450
ClientSecret string `json:"client_secret"`
4551
}
4652

53+
// ConfigOAuthGitLab describes the GitLab integration configuration for a Coder Enterprise deployment.
4754
type ConfigOAuthGitLab struct {
4855
BaseURL string `json:"base_url"`
4956
ClientID string `json:"client_id" `
5057
ClientSecret string `json:"client_secret"`
5158
}
5259

60+
// ConfigOAuth describes the aggregate git integration configuration for a Coder Enterprise deployment.
5361
type ConfigOAuth struct {
5462
BitbucketServer ConfigOAuthBitbucketServer `json:"bitbucket_server"`
5563
GitHub ConfigOAuthGitHub `json:"github"`
5664
GitLab ConfigOAuthGitLab `json:"gitlab"`
5765
}
5866

67+
// SiteConfigAuth fetches the sitewide authentication configuration.
5968
func (c Client) SiteConfigAuth(ctx context.Context) (*ConfigAuth, error) {
6069
var conf ConfigAuth
6170
if err := 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 (c Client) PutSiteConfigAuth(ctx context.Context, req ConfigAuth) error {
6878
return c.requestBody(ctx, http.MethodPut, "/api/auth/config", req, nil)
6979
}
7080

81+
// SiteConfigOAuth fetches the sitewide git provider OAuth configuration.
7182
func (c Client) SiteConfigOAuth(ctx context.Context) (*ConfigOAuth, error) {
7283
var conf ConfigOAuth
7384
if err := 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 (c Client) PutSiteConfigOAuth(ctx context.Context, req ConfigOAuth) error {
8092
return c.requestBody(ctx, http.MethodPut, "/api/oauth/config", req, nil)
8193
}
@@ -84,6 +96,7 @@ type configSetupMode struct {
8496
SetupMode bool `json:"setup_mode"`
8597
}
8698

99+
// SiteSetupModeEnabled fetches the current setup_mode state of a Coder Enterprise deployment.
87100
func (c Client) SiteSetupModeEnabled(ctx context.Context) (bool, error) {
88101
var conf configSetupMode
89102
if err := 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
return conf.SetupMode, nil
93106
}
94107

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

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

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

121+
// ConfigExtensionMarketplace describes the sitewide extension marketplace configuration.
106122
type ConfigExtensionMarketplace struct {
107123
URL string `json:"url"`
108124
Type ExtensionMarketplaceType `json:"type"`
109125
}
110126

127+
// SiteConfigExtensionMarketplace fetches the extension marketplace configuration.
111128
func (c Client) SiteConfigExtensionMarketplace(ctx context.Context) (*ConfigExtensionMarketplace, error) {
112129
var conf ConfigExtensionMarketplace
113130
if err := 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 (c Client) PutSiteConfigExtensionMarketplace(ctx context.Context, req ConfigExtensionMarketplace) error {
120138
return c.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
type Environment struct {
1515
ID string `json:"id" table:"-"`
1616
Name string `json:"name" table:"Name"`
@@ -40,7 +40,7 @@ type RebuildMessage struct {
4040
AutoOffThreshold Duration `json:"auto_off_threshold"`
4141
}
4242

43-
// EnvironmentStat represents the state of an environment
43+
// EnvironmentStat represents the state of an environment.
4444
type EnvironmentStat struct {
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
type EnvironmentStatus string
6060

61-
// The following represent the possible environment container states
61+
// The following represent the possible environment container states.
6262
const (
6363
EnvironmentCreating EnvironmentStatus = "CREATING"
6464
EnvironmentOff EnvironmentStatus = "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 performance issues
92+
// TODO: add the filter options, explore performance issue.
9393
func (c Client) Environments(ctx context.Context) ([]Environment, error) {
9494
var envs []Environment
9595
if err := 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
return c.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 (c Client) DialIDEStatus(ctx context.Context, envID string) (*websocket.Conn, error) {
151151
return c.dialWebsocket(ctx, "/proxy/environments/"+envID+"/ide/api/status")
152152
}
@@ -204,7 +204,7 @@ func (c Client) DialEnvironmentStats(ctx context.Context, envID string) (*websoc
204204
return c.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 (c Client) DialResourceLoad(ctx context.Context, envID string) (*websocket.Conn, error) {
209209
return c.dialWebsocket(ctx, "/api/environments/"+envID+"/watch-resource-load")
210210
}
@@ -233,7 +233,7 @@ type buildLogMsg struct {
233233
Type BuildLogType `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 (c Client) WaitForEnvironmentReady(ctx context.Context, env *Environment) error {
238238
conn, err := c.DialEnvironmentBuildLog(ctx, env.ID)
239239
if err != 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-
var ErrNotFound = xerrors.Errorf("resource not found")
12+
// ErrNotFound describes an error case in which the requested resource could not be found.
13+
var ErrNotFound = 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+
var ErrPermissions = xerrors.New("insufficient permissions")
17+
18+
// ErrAuthentication describes the error case in which the requester has invalid authentication.
19+
var ErrAuthentication = xerrors.New("invalid authentication")
1420

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

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
type Image struct {
1010
ID string `json:"id"`
1111
OrganizationID string `json:"organization_id"`
@@ -18,15 +18,15 @@ type Image struct {
1818
Deprecated bool `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
type NewRegistryRequest struct {
2323
FriendlyName string `json:"friendly_name"`
2424
Registry string `json:"registry"`
2525
Username string `json:"username"`
2626
Password string `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
type ImportImageReq struct {
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
URL string `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 (c Client) ImportImage(ctx context.Context, orgID string, req ImportImageReq) (*Image, error) {
4444
var img Image
4545
if err := c.requestBody(ctx, http.MethodPost, "/api/orgs/"+orgID+"/images", req, &img); err != nil {

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