Skip to content

Commit

Permalink
Merge pull request #713 from wyardley/wyardley/golangci-lint
Browse files Browse the repository at this point in the history
ci: use golangci-lint docker image directly
  • Loading branch information
li3n3 authored Jul 1, 2022
2 parents 19748d2 + 8fdf669 commit 859abf9
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 112 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ jobs:
- run: ./.circleci/deploy-gh-pages.sh

lint:
executor: go
docker:
- image: golangci/golangci-lint:v1.46-alpine
resource_class: large
steps:
- checkout
- run: make install-lint
- run: make build
- run: make lint
- run: golangci-lint run

deploy-test:
executor: go
Expand Down
15 changes: 0 additions & 15 deletions .circleci/install-lint.sh

This file was deleted.

14 changes: 0 additions & 14 deletions .circleci/lint.sh

This file was deleted.

36 changes: 36 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
service:
golangci-lint-version: 1.46.x

linters:
enable:
- deadcode
- errcheck
- goconst
- gofmt
- goimports
# - gosec
- gosimple
- govet
- ineffassign
- megacheck
- misspell
- nakedret
# - revive
- staticcheck
- structcheck
- typecheck
- unconvert
# - unparam
- unused
- varcheck
- vet
- vetshadow

# Instead of disabling tests entirely, just ignore goconst, which is the only
# one with issues there currently.
issues:
exclude-rules:
- path: (.+)_test.go
linters:
- goconst
38 changes: 0 additions & 38 deletions .gometalinter.json

This file was deleted.

7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ cover:

.PHONY: lint
lint:
bash .circleci/lint.sh
golangci-lint run

.PHONY: doc
doc:
godoc -http=:6060

.PHONY: install-lint
install-lint:
bash .circleci/install-lint.sh


.PHONY: always
always:
2 changes: 1 addition & 1 deletion api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestFollowProject(t *testing.T) {
expErr: "invalid character '/'",
},
{
label: "returns a followed project succesfully",
label: "returns a followed project successfully",
transportFn: func(r *http.Request) (*http.Response, error) {
if r.URL.String() != "https://circleci.com/api/v1.1/project/github/test-user/test-project/follow" {
panic(fmt.Sprintf("unexpected url: %s", r.URL.String()))
Expand Down
4 changes: 2 additions & 2 deletions api/context_graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (c *GraphQLContextClient) DeleteEnvironmentVariable(contextId, variableName
}

err := cl.Run(request, &response)
return errors.Wrap(improveVcsTypeError(err), "failed to delete environment varaible")
return errors.Wrap(improveVcsTypeError(err), "failed to delete environment variable")
}

// CreateEnvironmentVariable creates a new environment variable in the given
Expand Down Expand Up @@ -343,7 +343,7 @@ func (c *GraphQLContextClient) CreateEnvironmentVariable(contextId, variableName
}

if err := cl.Run(request, &response); err != nil {
return errors.Wrap(improveVcsTypeError(err), "failed to store environment varaible in context")
return errors.Wrap(improveVcsTypeError(err), "failed to store environment variable in context")
}

if response.StoreEnvironmentVariable.Error.Type != "" {
Expand Down
2 changes: 1 addition & 1 deletion api/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var _ = ginkgo.Describe("API", func() {

list.Organization.Id = "C3D79A95-6BD5-40B4-9958-AB6BDC4CAD50"
list.Organization.Contexts.Edges = []struct{ Node circleCIContext }{
struct{ Node circleCIContext }{
{
Node: ctx,
},
}
Expand Down
4 changes: 2 additions & 2 deletions api/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func (c *Client) DoRequest(req *http.Request, resp interface{}) (statusCode int,
}

type HTTPError struct {
Code int
Message string
Code int
Message string
}

func (e *HTTPError) Error() string {
Expand Down
8 changes: 4 additions & 4 deletions api/rest/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestClient_DoRequest(t *testing.T) {
defer cleanup()

t.Run("Check result", func(t *testing.T) {
r, err := c.NewRequest("GET", &url.URL{Path: "my/error/endpoint"}, nil)
r, err := c.NewRequest(http.MethodGet, &url.URL{Path: "my/error/endpoint"}, nil)
assert.NilError(t, err)

resp := make(map[string]interface{})
Expand All @@ -73,7 +73,7 @@ func TestClient_DoRequest(t *testing.T) {

t.Run("Check request", func(t *testing.T) {
assert.Check(t, cmp.Equal(fix.URL(), url.URL{Path: "/api/v2/my/error/endpoint"}))
assert.Check(t, cmp.Equal(fix.Method(), "GET"))
assert.Check(t, cmp.Equal(fix.Method(), http.MethodGet))
assert.Check(t, cmp.DeepEqual(fix.Header(), http.Header{
"Accept-Encoding": {"gzip"},
"Accept-Type": {"application/json"},
Expand All @@ -90,7 +90,7 @@ func TestClient_DoRequest(t *testing.T) {
defer cleanup()

t.Run("Check result", func(t *testing.T) {
r, err := c.NewRequest("GET", &url.URL{Path: "path"}, nil)
r, err := c.NewRequest(http.MethodGet, &url.URL{Path: "path"}, nil)
assert.NilError(t, err)

resp := make(map[string]interface{})
Expand All @@ -105,7 +105,7 @@ func TestClient_DoRequest(t *testing.T) {

t.Run("Check request", func(t *testing.T) {
assert.Check(t, cmp.Equal(fix.URL(), url.URL{Path: "/api/v2/path"}))
assert.Check(t, cmp.Equal(fix.Method(), "GET"))
assert.Check(t, cmp.Equal(fix.Method(), http.MethodGet))
assert.Check(t, cmp.DeepEqual(fix.Header(), http.Header{
"Accept-Encoding": {"gzip"},
"Accept-Type": {"application/json"},
Expand Down
8 changes: 4 additions & 4 deletions api/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestRunner_GetResourceClassByName(t *testing.T) {

t.Run("Check request", func(t *testing.T) {
assert.Check(t, cmp.Equal(fix.URL(), url.URL{Path: "/api/v2/runner/resource", RawQuery: "namespace=the-namespace"}))
assert.Check(t, cmp.Equal(fix.method, "GET"))
assert.Check(t, cmp.Equal(fix.method, http.MethodGet))
assert.Check(t, cmp.DeepEqual(fix.Header(), http.Header{
"Accept-Encoding": {"gzip"},
"Accept-Type": {"application/json"},
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestRunner_GetResourceClassesByNamespace(t *testing.T) {

t.Run("Check request", func(t *testing.T) {
assert.Check(t, cmp.Equal(fix.URL(), url.URL{Path: "/api/v2/runner/resource", RawQuery: "namespace=the-namespace"}))
assert.Check(t, cmp.Equal(fix.method, "GET"))
assert.Check(t, cmp.Equal(fix.method, http.MethodGet))
assert.Check(t, cmp.DeepEqual(fix.Header(), http.Header{
"Accept-Encoding": {"gzip"},
"Accept-Type": {"application/json"},
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestRunner_GetRunnerTokensByResourceClass(t *testing.T) {

t.Run("Check request", func(t *testing.T) {
assert.Check(t, cmp.Equal(fix.URL(), url.URL{Path: "/api/v2/runner/token", RawQuery: "resource-class=the-namespace%2Fthe-resource-class"}))
assert.Check(t, cmp.Equal(fix.method, "GET"))
assert.Check(t, cmp.Equal(fix.method, http.MethodGet))
assert.Check(t, cmp.DeepEqual(fix.Header(), http.Header{
"Accept-Encoding": {"gzip"},
"Accept-Type": {"application/json"},
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestRunner_GetRunnerInstances_ByNamespace(t *testing.T) {

t.Run("Check request", func(t *testing.T) {
assert.Check(t, cmp.Equal(fix.URL(), url.URL{Path: "/api/v2/runner", RawQuery: "namespace=the-namespace"}))
assert.Check(t, cmp.Equal(fix.method, "GET"))
assert.Check(t, cmp.Equal(fix.method, http.MethodGet))
assert.Check(t, cmp.DeepEqual(fix.Header(), http.Header{
"Accept-Encoding": {"gzip"},
"Accept-Type": {"application/json"},
Expand Down
6 changes: 3 additions & 3 deletions api/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestSchedules(t *testing.T) {
if r.URL.String() != "https://circleci.com/api/v2/project/github/test-org/test-project/schedule" {
panic(fmt.Sprintf("unexpected url: %s", r.URL.String()))
}
if r.Method != "GET" {
if r.Method != http.MethodGet {
panic(fmt.Sprintf("unexpected method: %s", r.Method))
}
return mock.NewHTTPResponse(200, formatListResponse([]Schedule{mockSchedule()})), nil
Expand All @@ -90,7 +90,7 @@ func TestScheduleByID(t *testing.T) {
if r.URL.String() != "https://circleci.com/api/v2/schedule/07f08dea-de06-48d4-9b47-9639229b7d24" {
panic(fmt.Sprintf("unexpected url: %s", r.URL.String()))
}
if r.Method != "GET" {
if r.Method != http.MethodGet {
panic(fmt.Sprintf("unexpected method: %s", r.Method))
}
return mock.NewHTTPResponse(200, mockScheduleString()), nil
Expand All @@ -114,7 +114,7 @@ func TestScheduleByName(t *testing.T) {
if r.URL.String() != "https://circleci.com/api/v2/project/github/test-org/test-project/schedule" {
panic(fmt.Sprintf("unexpected url: %s", r.URL.String()))
}
if r.Method != "GET" {
if r.Method != http.MethodGet {
panic(fmt.Sprintf("unexpected method: %s", r.Method))
}
return mock.NewHTTPResponse(200, formatListResponse([]Schedule{mockSchedule()})), nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var _ = Describe("Check", func() {

tempSettings.TestServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/repos/CircleCI-Public/circleci-cli/releases"),
ghttp.VerifyRequest(http.MethodGet, "/repos/CircleCI-Public/circleci-cli/releases"),
ghttp.RespondWith(http.StatusOK, response),
),
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func processConfig(opts configOptions, flags *pflag.FlagSet) error {
var err error

if len(paramsYaml) > 0 {
// The 'src' value can be a filepath, or a yaml string. If the file cannot be read sucessfully,
// The 'src' value can be a filepath, or a yaml string. If the file cannot be read successfully,
// proceed with the assumption that the value is already valid yaml.
raw, err := ioutil.ReadFile(paramsYaml)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions cmd/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type namespaceOptions struct {

// Allows user to skip y/n confirm when creating a namespace
noPrompt bool
orgID *string
orgID *string
// This lets us pass in our own interface for testing
tty createNamespaceUserInterface
// Linked with --integration-testing flag for stubbing UI in gexec tests
Expand Down Expand Up @@ -57,7 +57,7 @@ func newNamespaceCommand(config *settings.Config) *cobra.Command {
}

createCmd := &cobra.Command{
Use: "create <name> [<vcs-type>] [<org-name>]",
Use: "create <name> [<vcs-type>] [<org-name>]",
Short: "Create a namespace",
Long: `Create a namespace.
Please note that at this time all namespaces created in the registry are world-readable.`,
Expand All @@ -76,7 +76,7 @@ Please note that at this time all namespaces created in the registry are world-r

return createNamespace(cmd, opts)
},
Args: cobra.RangeArgs(1, 3),
Args: cobra.RangeArgs(1, 3),
Annotations: make(map[string]string),
Example: ` circleci namespace create NamespaceName github OrgName
circleci namespace create NamespaceName --org-id "your-org-id-here"`,
Expand Down Expand Up @@ -157,17 +157,17 @@ To change the namespace, you will have to contact CircleCI customer support.
return nil
}

func createNamespace(cmd *cobra.Command,opts namespaceOptions) error {
func createNamespace(cmd *cobra.Command, opts namespaceOptions) error {
namespaceName := opts.args[0]
//skip if no orgid provided
if opts.orgID != nil && strings.TrimSpace(*opts.orgID) != ""{
if opts.orgID != nil && strings.TrimSpace(*opts.orgID) != "" {
_, err := uuid.Parse(*opts.orgID)
if err == nil {
return createNamespaceWithOrgId(opts, namespaceName, *opts.orgID)
}

//skip if no vcs type and org name provided
} else if len(opts.args) == 3{
//skip if no vcs type and org name provided
} else if len(opts.args) == 3 {
return createNamespaceWithVcsTypeAndOrgName(opts, namespaceName, opts.args[1], opts.args[2])
}
return cmd.Help()
Expand Down
7 changes: 3 additions & 4 deletions cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type createOrbTestUI struct {

type orbProtectTemplateRelease struct {
ZipUrl string `json:"zipball_url"`
Name string `json:"name"`
Name string `json:"name"`
}

func (ui createOrbTestUI) askUserToConfirm(message string) bool {
Expand Down Expand Up @@ -1086,7 +1086,6 @@ func initOrb(opts orbOptions) error {
}
}


latestRelease := releaseTags[0]
resp, err := http.Get(latestRelease.ZipUrl)
if err != nil {
Expand Down Expand Up @@ -1342,7 +1341,7 @@ func initOrb(opts orbOptions) error {
return err
}

orbRoot, err := ioutil.ReadFile(path.Join(orbPath, "src", "@orb.yml"))
orbRoot, err := ioutil.ReadFile(path.Join(orbPath, "src", "@orb.yml"))
if err != nil {
return err
}
Expand Down Expand Up @@ -1521,7 +1520,7 @@ func unzipToOrbPath(src, dest string) error {
}
}()

// This is neccesary because the zip downloaded from GitHub will have a
// This is necessary because the zip downloaded from GitHub will have a
// directory with the actual template, rather than the template being
// top-level.
pathParts := strings.Split(f.Name, "/")
Expand Down
2 changes: 1 addition & 1 deletion cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func newUpdateCommand(config *settings.Config) *cobra.Command {
update.AddCommand(&cobra.Command{
Use: "build-agent",
Hidden: true,
Short: "This command has no effect, and is kept for backwards compatiblity",
Short: "This command has no effect, and is kept for backwards compatibility",
PersistentPreRun: func(_ *cobra.Command, _ []string) {
opts.cfg.SkipUpdateCheck = true
},
Expand Down
Loading

0 comments on commit 859abf9

Please sign in to comment.