Make API less pointery. Get rid of error interface.
Signed-off-by: Eric Chlebek <eric@sensu.io>
diff --git a/errcheck/errcheck.go b/errcheck/errcheck.go
index 010c849..74bfaf0 100644
--- a/errcheck/errcheck.go
+++ b/errcheck/errcheck.go
@@ -114,7 +114,7 @@
}
// Append appends errors to e. Append does not do any duplicate checking.
-func (r *Result) Append(other *Result) {
+func (r *Result) Append(other Result) {
r.UncheckedErrors = append(r.UncheckedErrors, other.UncheckedErrors...)
}
@@ -122,7 +122,7 @@
// when a file containing an unchecked error belongs to > 1 package.
//
// The method receiver remains unmodified after the call to Unique.
-func (r *Result) Unique() *Result {
+func (r Result) Unique() Result {
result := make([]UncheckedError, len(r.UncheckedErrors))
copy(result, r.UncheckedErrors)
sort.Sort((byName)(result))
@@ -132,11 +132,7 @@
uniq = append(uniq, err)
}
}
- return &Result{UncheckedErrors: uniq}
-}
-
-func (r *Result) Error() string {
- return fmt.Sprintf("%d unchecked errors", len(r.UncheckedErrors))
+ return Result{UncheckedErrors: uniq}
}
// Exclusions define symbols and language elements that will be not checked
@@ -232,7 +228,7 @@
//
// It will exclude specific errors from analysis if the user has configured
// exclusions.
-func (c *Checker) CheckPackage(pkg *packages.Package) *Result {
+func (c *Checker) CheckPackage(pkg *packages.Package) Result {
excludedSymbols := map[string]bool{}
for _, sym := range c.Exclusions.Symbols {
excludedSymbols[sym] = true
@@ -268,7 +264,7 @@
}
ast.Walk(v, astFile)
}
- return &Result{UncheckedErrors: v.errors}
+ return Result{UncheckedErrors: v.errors}
}
// visitor implements the errcheck algorithm
diff --git a/errcheck/errcheck_test.go b/errcheck/errcheck_test.go
index bc9422d..472c023 100644
--- a/errcheck/errcheck_test.go
+++ b/errcheck/errcheck_test.go
@@ -188,7 +188,7 @@
for _, pkg := range packages {
uerr.Append(checker.CheckPackage(pkg))
}
- uerr = uerr.Unique()
+ *uerr = uerr.Unique()
if test.numExpectedErrs == 0 {
if len(uerr.UncheckedErrors) != 0 {
t.Errorf("expected no errors, but got: %v", uerr)
@@ -297,7 +297,7 @@
for _, pkg := range packages {
uerr.Append(checker.CheckPackage(pkg))
}
- uerr = uerr.Unique()
+ *uerr = uerr.Unique()
if test.numExpectedErrs == 0 {
if len(uerr.UncheckedErrors) != 0 {
@@ -393,7 +393,7 @@
if err != nil {
t.Fatal(err)
}
- uerr := &Result{}
+ uerr := Result{}
for _, pkg := range packages {
uerr.Append(checker.CheckPackage(pkg))
}
@@ -429,7 +429,7 @@
if err != nil {
t.Fatal(err)
}
- uerr := &Result{}
+ uerr := Result{}
numErrors := len(uncheckedMarkers)
if blank {
numErrors += len(blankMarkers)
diff --git a/main.go b/main.go
index f29b183..6369927 100644
--- a/main.go
+++ b/main.go
@@ -87,7 +87,7 @@
return nil
}
-func reportResult(e *errcheck.Result) {
+func reportResult(e errcheck.Result) {
wd, err := os.Getwd()
if err != nil {
wd = ""
@@ -138,16 +138,16 @@
return exitCodeOk
}
-func checkPaths(c *errcheck.Checker, paths ...string) (*errcheck.Result, error) {
+func checkPaths(c *errcheck.Checker, paths ...string) (errcheck.Result, error) {
pkgs, err := c.LoadPackages(paths...)
if err != nil {
- return nil, err
+ return errcheck.Result{}, err
}
// Check for errors in the initial packages.
work := make(chan *packages.Package, len(pkgs))
for _, pkg := range pkgs {
if len(pkg.Errors) > 0 {
- return nil, fmt.Errorf("errors while loading package %s: %v", pkg.ID, pkg.Errors)
+ return errcheck.Result{}, fmt.Errorf("errors while loading package %s: %v", pkg.ID, pkg.Errors)
}
work <- pkg
}