Skip to content

Commit

Permalink
Enable golangci linter stylecheck (woodpecker-ci#3167)
Browse files Browse the repository at this point in the history
This PR only fixes error string formatting, log message strings are
still mixed upper/lowercase (see
woodpecker-ci#3161 (comment))
and I'm not aware of a linter to enforce it.
  • Loading branch information
xoxys authored and fernandrone committed Feb 1, 2024
1 parent 0702b1d commit 0d14019
Show file tree
Hide file tree
Showing 58 changed files with 126 additions and 129 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ linters:
- whitespace
- gocritic
- nolintlint
- stylecheck

run:
timeout: 15m
1 change: 0 additions & 1 deletion cli/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func FormatFlag(tmpl string, hidden ...bool) *cli.StringFlag {
}
}

// specify repository
var RepoFlag = &cli.StringFlag{
Name: "repository",
Aliases: []string{"repo"},
Expand Down
4 changes: 2 additions & 2 deletions cli/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func deploy(c *cli.Context) error {
}
}
if number == 0 {
return fmt.Errorf("Cannot deploy failure pipeline")
return fmt.Errorf("cannot deploy failure pipeline")
}
} else {
number, err = strconv.ParseInt(pipelineArg, 10, 64)
Expand All @@ -108,7 +108,7 @@ func deploy(c *cli.Context) error {

env := c.Args().Get(2)
if env == "" {
return fmt.Errorf("Please specify the target environment (ie production)")
return fmt.Errorf("please specify the target environment (i.e. production)")
}

params := internal.ParseKeyPair(c.StringSlice("param"))
Expand Down
2 changes: 1 addition & 1 deletion cli/user/user_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func userInfo(c *cli.Context) error {

login := c.Args().First()
if len(login) == 0 {
return fmt.Errorf("Missing or invalid user login")
return fmt.Errorf("missing or invalid user login")
}

user, err := client.User(login)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The local backend will execute the pipelines on the local system without any iso
:::

:::note
This backend is still pretty new and can not be treated as stable. Its
This backend is still pretty new and cannot be treated as stable. Its
implementation and configuration can change at any time.
:::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The SSH backend will execute the pipelines using SSH on a remote system without
:::

:::note
This backend is still pretty new and can not be treated as stable. Its implementation and configuration can change at any time.
This backend is still pretty new and cannot be treated as stable. Its implementation and configuration can change at any time.
:::
Since the code run directly on the SSH machine, a malicious pipeline could access and edit files the SSH user has access to and execute every command the remote user is allowed to use. Always restrict the user as far as possible!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The local backend will execute the pipelines on the local system without any iso
:::

:::note
This backend is still pretty new and can not be treated as stable. Its
This backend is still pretty new and cannot be treated as stable. Its
implementation and configuration can change at any time.
:::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The local backend will execute the pipelines on the local system without any iso
:::

:::note
This backend is still pretty new and can not be treated as stable. Its
This backend is still pretty new and cannot be treated as stable. Its
implementation and configuration can change at any time.
:::

Expand Down
2 changes: 1 addition & 1 deletion pipeline/backend/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string)
}

if isImagePullBackOffState(pod) {
return nil, fmt.Errorf("Could not pull image for pod %s", pod.Name)
return nil, fmt.Errorf("could not pull image for pod %s", pod.Name)
}

if len(pod.Status.ContainerStatuses) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion pipeline/backend/local/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"
)

// notAllowedEnvVarOverwrites are all env vars that can not be overwritten by step config
// notAllowedEnvVarOverwrites are all env vars that cannot be overwritten by step config
var notAllowedEnvVarOverwrites = []string{
"CI_NETRC_MACHINE",
"CI_NETRC_USERNAME",
Expand Down
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/constraint/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (c *List) UnmarshalYAML(value *yaml.Node) error {

if err1 != nil && err2 != nil {
y, _ := yaml.Marshal(value)
return fmt.Errorf("Could not parse condition: %s: %w", y, multierr.Append(err1, err2))
return fmt.Errorf("could not parse condition: %s: %w", y, multierr.Append(err1, err2))
}

return nil
Expand Down Expand Up @@ -342,7 +342,7 @@ func (c *Path) UnmarshalYAML(value *yaml.Node) error {

if err1 != nil && err2 != nil {
y, _ := yaml.Marshal(value)
return fmt.Errorf("Could not parse condition: %s", y)
return fmt.Errorf("could not parse condition: %s", y)
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions pipeline/frontend/yaml/linter/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ func Lint(r io.Reader) ([]gojsonschema.ResultError, error) {
// read yaml config
rBytes, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("Failed to load yml file %w", err)
return nil, fmt.Errorf("failed to load yml file %w", err)
}

// resolve sequence merges
yamlDoc := new(yaml.Node)
if err := xyaml.Unmarshal(rBytes, yamlDoc); err != nil {
return nil, fmt.Errorf("Failed to parse yml file %w", err)
return nil, fmt.Errorf("failed to parse yml file %w", err)
}

// convert to json
jsonDoc, err := yaml2json.ConvertNode(yamlDoc)
if err != nil {
return nil, fmt.Errorf("Failed to convert yaml %w", err)
return nil, fmt.Errorf("failed to convert yaml %w", err)
}

documentLoader := gojsonschema.NewBytesLoader(jsonDoc)
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil {
return nil, fmt.Errorf("Validation failed %w", err)
return nil, fmt.Errorf("validation failed %w", err)
}

if !result.Valid() {
return result.Errors(), fmt.Errorf("Config not valid")
return result.Errors(), fmt.Errorf("config not valid")
}

return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion pipeline/frontend/yaml/types/base/base_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ bars: []
func TestUnmarshalSliceOrMap(t *testing.T) {
s := StructSliceorMap{}
err := yaml.Unmarshal([]byte(sampleStructSliceorMap), &s)
assert.Equal(t, fmt.Errorf("Cannot unmarshal 'true' of type bool into a string value"), err)
assert.Equal(t, fmt.Errorf("cannot unmarshal 'true' of type bool into a string value"), err)
}

func TestStr2SliceOrMapPtrMap(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/types/base/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *StringOrInt) UnmarshalYAML(unmarshal func(any) error) error {
return nil
}

return errors.New("Failed to unmarshal StringOrInt")
return errors.New("failed to unmarshal StringOrInt")
}

// MemStringOrInt represents a string or an integer
Expand All @@ -67,5 +67,5 @@ func (s *MemStringOrInt) UnmarshalYAML(unmarshal func(any) error) error {
return nil
}

return errors.New("Failed to unmarshal MemStringOrInt")
return errors.New("failed to unmarshal MemStringOrInt")
}
8 changes: 4 additions & 4 deletions pipeline/frontend/yaml/types/base/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *SliceOrMap) UnmarshalYAML(unmarshal func(any) error) error {
}
parts[key] = val
} else {
return fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", s, s)
return fmt.Errorf("cannot unmarshal '%v' of type %T into a string value", s, s)
}
}
*s = parts
Expand All @@ -55,15 +55,15 @@ func (s *SliceOrMap) UnmarshalYAML(unmarshal func(any) error) error {
if sv, ok := v.(string); ok {
parts[sk] = sv
} else {
return fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", v, v)
return fmt.Errorf("cannot unmarshal '%v' of type %T into a string value", v, v)
}
} else {
return fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", k, k)
return fmt.Errorf("cannot unmarshal '%v' of type %T into a string value", k, k)
}
}
*s = parts
return nil
}

return errors.New("Failed to unmarshal SliceOrMap")
return errors.New("failed to unmarshal SliceOrMap")
}
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/types/base/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *StringOrSlice) UnmarshalYAML(unmarshal func(any) error) error {
return nil
}

return errors.New("Failed to unmarshal StringOrSlice")
return errors.New("failed to unmarshal StringOrSlice")
}

func toStrings(s []any) ([]string, error) {
Expand All @@ -53,7 +53,7 @@ func toStrings(s []any) ([]string, error) {
if sv, ok := v.(string); ok {
r[k] = sv
} else {
return nil, fmt.Errorf("Cannot unmarshal '%v' of type %T into a string value", v, v)
return nil, fmt.Errorf("cannot unmarshal '%v' of type %T into a string value", v, v)
}
}
return r, nil
Expand Down
10 changes: 5 additions & 5 deletions pipeline/frontend/yaml/types/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (n *Networks) UnmarshalYAML(unmarshal func(any) error) error {
for _, network := range sliceType {
name, ok := network.(string)
if !ok {
return fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name)
return fmt.Errorf("cannot unmarshal '%v' to type %T into a string value", name, name)
}
n.Networks = append(n.Networks, &Network{
Name: name,
Expand All @@ -65,7 +65,7 @@ func (n *Networks) UnmarshalYAML(unmarshal func(any) error) error {
for mapKey, mapValue := range mapType {
name, ok := mapKey.(string)
if !ok {
return fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name)
return fmt.Errorf("cannot unmarshal '%v' to type %T into a string value", name, name)
}
network, err := handleNetwork(name, mapValue)
if err != nil {
Expand All @@ -76,7 +76,7 @@ func (n *Networks) UnmarshalYAML(unmarshal func(any) error) error {
return nil
}

return errors.New("Failed to unmarshal Networks")
return errors.New("failed to unmarshal Networks")
}

func handleNetwork(name string, value any) (*Network, error) {
Expand All @@ -95,7 +95,7 @@ func handleNetwork(name string, value any) (*Network, error) {
case "aliases":
aliases, ok := mapValue.([]any)
if !ok {
return &Network{}, fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", aliases, aliases)
return &Network{}, fmt.Errorf("cannot unmarshal '%v' to type %T into a string value", aliases, aliases)
}
network.Aliases = []string{}
for _, alias := range aliases {
Expand All @@ -112,6 +112,6 @@ func handleNetwork(name string, value any) (*Network, error) {
}
return network, nil
default:
return &Network{}, fmt.Errorf("Failed to unmarshal Network: %#v", value)
return &Network{}, fmt.Errorf("failed to unmarshal Network: %#v", value)
}
}
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/types/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (v *Volumes) UnmarshalYAML(unmarshal func(any) error) error {
for _, volume := range sliceType {
name, ok := volume.(string)
if !ok {
return fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", name, name)
return fmt.Errorf("cannot unmarshal '%v' to type %T into a string value", name, name)
}
elts := strings.SplitN(name, ":", 3)
var vol *Volume
Expand Down Expand Up @@ -93,5 +93,5 @@ func (v *Volumes) UnmarshalYAML(unmarshal func(any) error) error {
return nil
}

return errors.New("Failed to unmarshal Volumes")
return errors.New("failed to unmarshal Volumes")
}
8 changes: 4 additions & 4 deletions server/api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func GetAgent(c *gin.Context) {

agent, err := store.FromContext(c).AgentFind(agentID)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
c.JSON(http.StatusOK, agent)
Expand All @@ -89,7 +89,7 @@ func GetAgentTasks(c *gin.Context) {

agent, err := store.FromContext(c).AgentFind(agentID)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}

Expand Down Expand Up @@ -132,7 +132,7 @@ func PatchAgent(c *gin.Context) {

agent, err := _store.AgentFind(agentID)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
agent.Name = in.Name
Expand Down Expand Up @@ -201,7 +201,7 @@ func DeleteAgent(c *gin.Context) {

agent, err := _store.AgentFind(agentID)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
if err = _store.AgentDelete(agent); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions server/api/badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func GetBadge(c *gin.Context) {
}

if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func GetCC(c *gin.Context) {
}

if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}

Expand Down
8 changes: 4 additions & 4 deletions server/api/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func GetCron(c *gin.Context) {

cron, err := store.FromContext(c).CronFind(repo, id)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
c.JSON(http.StatusOK, cron)
Expand All @@ -76,7 +76,7 @@ func RunCron(c *gin.Context) {

cron, err := _store.CronFind(repo, id)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}

Expand Down Expand Up @@ -183,7 +183,7 @@ func PatchCron(c *gin.Context) {

cron, err := _store.CronFind(repo, id)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
if in.Branch != "" {
Expand Down Expand Up @@ -259,7 +259,7 @@ func DeleteCron(c *gin.Context) {
return
}
if err := store.FromContext(c).CronDelete(repo, id); err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
c.Status(http.StatusNoContent)
Expand Down
6 changes: 3 additions & 3 deletions server/api/global_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func GetGlobalSecret(c *gin.Context) {
name := c.Param("secret")
secret, err := server.Config.Services.Secrets.GlobalSecretFind(name)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
c.JSON(http.StatusOK, secret.Copy())
Expand Down Expand Up @@ -122,7 +122,7 @@ func PatchGlobalSecret(c *gin.Context) {

secret, err := server.Config.Services.Secrets.GlobalSecretFind(name)
if err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
if in.Value != "" {
Expand Down Expand Up @@ -158,7 +158,7 @@ func PatchGlobalSecret(c *gin.Context) {
func DeleteGlobalSecret(c *gin.Context) {
name := c.Param("secret")
if err := server.Config.Services.Secrets.GlobalSecretDelete(name); err != nil {
handleDbError(c, err)
handleDBError(c, err)
return
}
c.Status(http.StatusNoContent)
Expand Down
Loading

0 comments on commit 0d14019

Please sign in to comment.