forked from amnonbc/errcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from getkalido/feature/update-v1.6.0
Update version of fork to latest on base repo.
- Loading branch information
Showing
26 changed files
with
967 additions
and
484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.