Skip to content

Commit

Permalink
Merge pull request #1 from getkalido/feature/update-v1.6.0
Browse files Browse the repository at this point in the history
Update version of fork to latest on base repo.
  • Loading branch information
rjacobs31 authored May 18, 2022
2 parents 588a85e + 5ee4c54 commit 8e7847f
Show file tree
Hide file tree
Showing 26 changed files with 967 additions and 484 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
GO111MODULE: 'on'
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14
go-version: ^1.18
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
run: go build -v .
run: go build -v ./...

- name: Test
run: go test -v .
run: go test -v ./...
29 changes: 0 additions & 29 deletions .github/workflows/go3.yml

This file was deleted.

38 changes: 0 additions & 38 deletions .travis.yml

This file was deleted.

44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@ allows you to write `defer foo.Close()`.

## Why a fork

`defer h.Close()`
is idiomatic Go, which appears regularly in the standard library and text books.
`defer h.Close()` is idiomatic Go, which appears regularly in the standard library and text books.
If h is a read only descriptor, then nothing useful can be done if the Close fails.

This has been raised a number [of](https://github.com/kisielk/errcheck/issues/55) [times](https://github.com/kisielk/errcheck/issues/101)
upstream, but these issues have been closed, as the author
This has been raised a number [of](https://github.com/kisielk/errcheck/issues/55) [times](https://github.com/kisielk/errcheck/issues/101)
upstream, but these issues have been closed, as the author
believes that these errors should always be checked, and if necessary deferred calls to Close
should be wrapped in a lambda.
This [unecessarily complicates code](https://github.com/Marethyu12/gotube/pull/4/commits/8552c52ca02b81fd0a307784916bfe6393fcaa1e),
and means that the Go standard
library will fail errcheck.
should be wrapped in a lambda.

The Author is, of course, entitled to his opinion. But those who disagree with him have the right to fork and do otherwise.
This [unecessarily complicates code](https://github.com/Marethyu12/gotube/pull/4/commits/8552c52ca02b81fd0a307784916bfe6393fcaa1e),
and means that the Go standard library will fail errcheck.

The Author is, of course, entitled to his opinion. But those who disagree with him have the right to fork and do otherwise.

## Install

go get -u github.com/getkalido/errcheck
go install github.com/getkalido/errcheck@latest

errcheck requires Go 1.14 or newer and depends on the package go/packages from the golang.org/x/tools repository.

Expand Down Expand Up @@ -56,6 +54,14 @@ takes no arguments.
The `-blank` flag enables checking for assignments of errors to the
blank identifier. It takes no arguments.

### go/analysis

The package provides `Analyzer` instance that can be used with
[go/analysis](https://pkg.go.dev/golang.org/x/tools/go/analysis) API.

Currently supported flags are `blank`, `assert`, `exclude`, and `excludeonly`.
Just as the API itself, the analyzer is exprimental and may change in the
future.

## Excluding functions

Expand All @@ -75,10 +81,15 @@ An example of an exclude file is:
io/ioutil.ReadFile
io.Copy(*bytes.Buffer)
io.Copy(os.Stdout)

// Sometimes we don't care if a HTTP request fails.
(*net/http.Client).Do

The exclude list is combined with an internal list for functions in the Go standard library that
have an error return type but are documented to never return an error.
By default, the exclude list is combined with an internal list for functions in
the Go standard library that have an error return type but are documented to never
return an error. To disable the built-in exclude list, pass the `-excludeonly` flag.

Run errcheck in `-verbose` mode to see the resulting list of added excludes.

When using vendored dependencies, specify the full import path. For example:
* Your project's import path is `example.com/yourpkg`
Expand All @@ -90,6 +101,7 @@ In this case, add this line to your exclude file:
example.com/yourpkg/vendor/example.net/fmt2.Println
```

Empty lines and lines starting with `//` are ignored.

### The deprecated method

Expand Down Expand Up @@ -126,14 +138,6 @@ specified for it. To disable this, specify a regex that matches nothing:
The `-ignoretests` flag disables checking of `_test.go` files. It takes
no arguments.

## Cgo

Currently errcheck is unable to check packages that import "C" due to limitations in the importer when used with versions earlier than Go 1.11.

However, you can use errcheck on packages that depend on those which use cgo. In order for this to work you need to go install the cgo dependencies before running errcheck on the dependent packages.

See https://github.com/kisielk/errcheck/issues/16 for more details.

## Exit Codes

errcheck returns 1 if any problems were found in the checked files.
Expand Down
78 changes: 78 additions & 0 deletions errcheck/analyzer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package errcheck

import (
"fmt"
"go/ast"
"go/token"
"reflect"
"regexp"

"golang.org/x/tools/go/analysis"
)

var Analyzer = &analysis.Analyzer{
Name: "errcheck",
Doc: "check for unchecked errors",
Run: runAnalyzer,
ResultType: reflect.TypeOf(Result{}),
}

var (
argBlank bool
argAsserts bool
argExcludeFile string
argExcludeOnly bool
)

func init() {
Analyzer.Flags.BoolVar(&argBlank, "blank", false, "if true, check for errors assigned to blank identifier")
Analyzer.Flags.BoolVar(&argAsserts, "assert", false, "if true, check for ignored type assertion results")
Analyzer.Flags.StringVar(&argExcludeFile, "exclude", "", "Path to a file containing a list of functions to exclude from checking")
Analyzer.Flags.BoolVar(&argExcludeOnly, "excludeonly", false, "Use only excludes from exclude file")
}

func runAnalyzer(pass *analysis.Pass) (interface{}, error) {

exclude := map[string]bool{}
if !argExcludeOnly {
for _, name := range DefaultExcludedSymbols {
exclude[name] = true
}
}
if argExcludeFile != "" {
excludes, err := ReadExcludes(argExcludeFile)
if err != nil {
return nil, fmt.Errorf("Could not read exclude file: %v\n", err)
}
for _, name := range excludes {
exclude[name] = true
}
}

var allErrors []UncheckedError
for _, f := range pass.Files {
v := &visitor{
typesInfo: pass.TypesInfo,
fset: pass.Fset,
blank: argBlank,
asserts: argAsserts,
exclude: exclude,
ignore: map[string]*regexp.Regexp{}, // deprecated & not used
lines: make(map[string][]string),
errors: nil,
}

ast.Walk(v, f)

for _, err := range v.errors {
pass.Report(analysis.Diagnostic{
Pos: token.Pos(int(f.Pos()) + err.Pos.Offset),
Message: "unchecked error",
})
}

allErrors = append(allErrors, v.errors...)
}

return Result{UncheckedErrors: allErrors}, nil
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8e7847f

Please sign in to comment.