Skip to content

Commit

Permalink
Enable errcheck linter and fix lints
Browse files Browse the repository at this point in the history
We also err an `.errcheck-excludes` configuration file which excludes
the logging error messages for now.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
  • Loading branch information
saschagrunert committed Dec 10, 2019
1 parent 471139d commit 8dd8fde
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions .errcheck-excludes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(github.com/go-kit/kit/log.Logger).Log
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ linters:
- depguard
- dogsled
- dupl
- errcheck
- goconst
- gocritic
- gocyclo
Expand All @@ -34,7 +35,6 @@ linters:
- unused
- varcheck
- whitespace
# - errcheck
# - funlen
# - gochecknoglobals
# - gochecknoinits
Expand All @@ -47,6 +47,7 @@ linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
exclude: .errcheck-excludes
gocritic:
enabled-checks:
# Diagnostic
Expand Down
2 changes: 1 addition & 1 deletion cmd/krel/cmd/ff.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func runFf(opts *ffOptions) error {

cleanup := rootOpts.cleanup
if cleanup {
defer repo.Cleanup() //nolint: errcheck
defer repo.Cleanup() // nolint: errcheck
}

log.Printf("Finding merge base between %q and %q", master, branch)
Expand Down
13 changes: 10 additions & 3 deletions cmd/release-notes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ func (o *options) WriteReleaseNotes(releaseNotes notes.ReleaseNotes, history not
// Contextualized release notes can be printed in a variety of formats
switch o.format {
case "json":
byteValue, _ := ioutil.ReadAll(output)
byteValue, err := ioutil.ReadAll(output)
if err != nil {
return err
}

if len(byteValue) > 0 {
if err := json.Unmarshal(byteValue, &existingNotes); err != nil {
Expand All @@ -254,8 +257,12 @@ func (o *options) WriteReleaseNotes(releaseNotes notes.ReleaseNotes, history not
}

if len(existingNotes) > 0 {
output.Truncate(0)
output.Seek(0, 0)
if err := output.Truncate(0); err != nil {
return err
}
if _, err := output.Seek(0, 0); err != nil {
return err
}

for i := 0; i < len(existingNotes); i++ {
_, ok := releaseNotes[existingNotes[i].PrNumber]
Expand Down
3 changes: 2 additions & 1 deletion pkg/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ func TestSuccessWithWorkingDir(t *testing.T) {
}

func TestFailureWithWrongWorkingDir(t *testing.T) {
_, err := NewWithWorkDir("/should/not/exist", "ls", "-1").Run()
res, err := NewWithWorkDir("/should/not/exist", "ls", "-1").Run()
require.NotNil(t, err)
require.Nil(t, res)
}

func TestSuccessSilent(t *testing.T) {
Expand Down
10 changes: 7 additions & 3 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ func (r *Repo) Cleanup() error {
// RevParse parses a git revision and returns a SHA1 on success, otherwise an
// error.
func (r *Repo) RevParse(rev string) (string, error) {
// Prefix all non-tags the default remote "origin"
if isVersion, _ := regexp.MatchString(`v\d+\.\d+\.\d+.*`, rev); !isVersion {
matched, err := regexp.MatchString(`v\d+\.\d+\.\d+.*`, rev)
if err != nil {
return "", err
}
if !matched {
// Prefix all non-tags the default remote "origin"
rev = Remotify(rev)
}

Expand Down Expand Up @@ -234,7 +238,7 @@ func (r *Repo) latestNonPatchFinalVersion() (semver.Version, error) {
}

found := false
_ = tags.ForEach(func(t *plumbing.Reference) error {
_ = tags.ForEach(func(t *plumbing.Reference) error { // nolint: errcheck
tag := strings.TrimPrefix(t.Name().Short(), "v")
ver, err := semver.Make(tag)

Expand Down

0 comments on commit 8dd8fde

Please sign in to comment.