Skip to content

Commit 6f691eb

Browse files
committed
lint(errcheck): Fix trivial warnings and nolint refactor targets
Signed-off-by: Stephen Augustus <[email protected]>
1 parent 1cca8a7 commit 6f691eb

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

pkg/kepctl/create.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ limitations under the License.
1717
package kepctl
1818

1919
import (
20-
"errors"
2120
"fmt"
2221
"io/ioutil"
2322
"os"
2423
"path/filepath"
2524
"strings"
2625
"time"
2726

27+
"github.com/pkg/errors"
28+
2829
"k8s.io/enhancements/api"
2930
)
3031

@@ -47,9 +48,11 @@ func (c *CreateOpts) Validate(args []string) error {
4748
if err != nil {
4849
return err
4950
}
51+
5052
if len(c.PRRApprovers) == 0 {
5153
return errors.New("must provide at least one PRR Approver")
5254
}
55+
5356
return nil
5457
}
5558

@@ -157,7 +160,9 @@ func (c *Client) createKEP(kep *api.Proposal, opts *CreateOpts) error {
157160
}
158161

159162
newPath := filepath.Join(path, "keps", opts.SIG, opts.Name, "README.md")
160-
ioutil.WriteFile(newPath, b, os.ModePerm)
163+
if writeErr := ioutil.WriteFile(newPath, b, os.ModePerm); writeErr != nil {
164+
return errors.Wrapf(writeErr, "writing KEP data to file")
165+
}
161166

162167
return nil
163168
}

pkg/kepctl/kepctl.go

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

3333
"github.com/google/go-github/v32/github"
3434
"github.com/olekukonko/tablewriter"
35+
"github.com/pkg/errors"
3536
"golang.org/x/oauth2"
3637
"gopkg.in/yaml.v2"
3738

@@ -122,8 +123,10 @@ func (c *Client) SetGitHubToken(opts *CommonArgs) error {
122123
if err != nil {
123124
return err
124125
}
126+
125127
c.Token = strings.Trim(string(token), "\n\r")
126128
}
129+
127130
return nil
128131
}
129132

@@ -152,7 +155,6 @@ func (c *Client) getReadmeTemplate(repoPath string) ([]byte, error) {
152155
}
153156

154157
// TODO: Unused?
155-
//golint:deadcode,unused
156158
func validateKEP(p *api.Proposal) error {
157159
b, err := yaml.Marshal(p)
158160
if err != nil {
@@ -446,15 +448,17 @@ func (c *Client) writeKEP(kep *api.Proposal, opts *CommonArgs) error {
446448
return fmt.Errorf("KEP is invalid: %s", err)
447449
}
448450

449-
os.MkdirAll(
451+
if mkErr := os.MkdirAll(
450452
filepath.Join(
451453
path,
452454
"keps",
453455
opts.SIG,
454456
opts.Name,
455457
),
456458
os.ModePerm,
457-
)
459+
); mkErr != nil {
460+
return errors.Wrapf(mkErr, "creating KEP directory")
461+
}
458462

459463
newPath := filepath.Join(path, "keps", opts.SIG, opts.Name, "kep.yaml")
460464
fmt.Fprintf(c.Out, "writing KEP to %s\n", newPath)

pkg/kepctl/kepctl_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ func TestFindLocalKEPs(t *testing.T) {
7878
},
7979
}
8080

81-
c, _ := New("testdata")
81+
c, clientErr := New("testdata")
82+
require.Nil(t, clientErr)
83+
8284
for i, tc := range testcases {
8385
k := c.loadLocalKEPs("testdata", tc.sig)
8486
if len(k) != len(tc.keps) {

pkg/kepctl/query.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ func (c *Client) Query(opts *QueryOpts) error {
103103
return errors.Wrap(err, "unable to search KEPs")
104104
}
105105

106-
c.SetGitHubToken(&opts.CommonArgs)
106+
if tokenErr := c.SetGitHubToken(&opts.CommonArgs); tokenErr != nil {
107+
return errors.Wrapf(tokenErr, "setting GitHub token")
108+
}
107109

108110
allKEPs := make([]*api.Proposal, 10)
109111
// load the KEPs for each listed SIG

pkg/kepval/keps/validations/yaml.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func ValidateStructure(parsed map[interface{}]interface{}) error {
5959
return util.NewValueMustBeString(k, v)
6060
}
6161

62+
// TODO(lint): Error return value is not checked (errcheck)
63+
//nolint:errcheck
6264
v, _ := value.(string)
6365
if !reStatus.Match([]byte(v)) {
6466
return util.NewValueMustBeOneOf(k, v, statuses)
@@ -70,6 +72,8 @@ func ValidateStructure(parsed map[interface{}]interface{}) error {
7072
return util.NewValueMustBeString(k, v)
7173
}
7274

75+
// TODO(lint): Error return value is not checked (errcheck)
76+
//nolint:errcheck
7377
v, _ := value.(string)
7478
if !reStages.Match([]byte(v)) {
7579
return util.NewValueMustBeOneOf(k, v, stages)
@@ -81,6 +85,8 @@ func ValidateStructure(parsed map[interface{}]interface{}) error {
8185
return util.NewValueMustBeString(k, v)
8286
}
8387

88+
// TODO(lint): Error return value is not checked (errcheck)
89+
//nolint:errcheck
8490
v, _ := value.(string)
8591
index := sort.SearchStrings(listGroups, v)
8692
if index >= len(listGroups) || listGroups[index] != v {
@@ -136,6 +142,8 @@ func ValidateStructure(parsed map[interface{}]interface{}) error {
136142

137143
if strings.EqualFold(k, "participating-sigs") {
138144
for _, value := range values {
145+
// TODO(lint): Error return value is not checked (errcheck)
146+
//nolint:errcheck
139147
v := value.(string)
140148
index := sort.SearchStrings(listGroups, v)
141149
if index >= len(listGroups) || listGroups[index] != v {
@@ -154,6 +162,8 @@ func ValidateStructure(parsed map[interface{}]interface{}) error {
154162
// prrApprovers must be sorted to use SearchStrings down below...
155163
sort.Strings(prrApprovers)
156164
for _, value := range values {
165+
// TODO(lint): Error return value is not checked (errcheck)
166+
//nolint:errcheck
157167
v := value.(string)
158168
if len(v) > 0 && v[0] == '@' {
159169
// If "@" is appeneded at the beginning, remove it.
@@ -175,6 +185,9 @@ func ValidateStructure(parsed map[interface{}]interface{}) error {
175185
case []interface{}:
176186
return util.NewValueMustBeString(k, v)
177187
}
188+
189+
// TODO(lint): Error return value is not checked (errcheck)
190+
//nolint:errcheck
178191
v, _ := value.(string)
179192
if !reMilestone.Match([]byte(v)) {
180193
return util.NewValueMustBeMilestone(k, v)
@@ -192,6 +205,7 @@ func ValidateStructure(parsed map[interface{}]interface{}) error {
192205
}
193206
}
194207
}
208+
195209
return nil
196210
}
197211

@@ -210,6 +224,8 @@ func validateMilestone(parsed map[interface{}]interface{}) error {
210224
return util.NewValueMustBeString(k, v)
211225
}
212226

227+
// TODO(lint): Error return value is not checked (errcheck)
228+
//nolint:errcheck
213229
v, _ := value.(string)
214230
if !reMilestone.Match([]byte(v)) {
215231
return util.NewValueMustBeMilestone(k, v)

pkg/kepval/prrs/validations/yaml.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ func validateMilestone(parsed map[interface{}]interface{}) error {
7575
case []interface{}:
7676
return util.NewValueMustBeString(k, v)
7777
}
78+
79+
// TODO(lint): Error return value is not checked (errcheck)
80+
//nolint:errcheck
7881
v, _ := value.(string)
7982
if len(v) > 0 && v[0] == '@' {
80-
// If "@" is appeneded at the beginning, remove it.
83+
// If "@" is appended at the beginning, remove it.
8184
v = v[1:]
8285
}
86+
8387
index := sort.SearchStrings(prrApprovers, v)
8488
if index >= len(prrApprovers) || prrApprovers[index] != v {
8589
return util.NewValueMustBeOneOf(k, v, prrApprovers)

0 commit comments

Comments
 (0)