1
0
mirror of https://github.com/securego/gosec.git synced 2025-06-14 23:45:03 +02:00

Report for Golang errors (#284)

* Report for Golang errors

Right now if you use Gosec to scan invalid go file and if you report the result in a text, JSON, CSV or another file format you will always receive 0 issues.
The reason for that is that Gosec can't parse the AST of invalid go files and thus will not report anything.

The real problem here is that the user will never know about the issue if he generates the output in a file.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
This commit is contained in:
Martin Vrachev
2019-02-27 00:24:06 +02:00
committed by Grant Murphy
parent 9cdfec40ca
commit 62b5195dd9
6 changed files with 117 additions and 18 deletions

34
errors.go Normal file
View File

@ -0,0 +1,34 @@
package gosec
import (
"sort"
)
// Error is used when there are golang errors while parsing the AST
type Error struct {
Line int `json:"line"`
Column int `json:"column"`
Err string `json:"error"`
}
// NewError creates Error object
func NewError(line, column int, err string) *Error {
return &Error{
Line: line,
Column: column,
Err: err,
}
}
// sortErros sorts the golang erros by line
func sortErrors(allErrors map[string][]Error) {
for _, errors := range allErrors {
sort.Slice(errors, func(i, j int) bool {
if errors[i].Line == errors[j].Line {
return errors[i].Column <= errors[j].Column
}
return errors[i].Line < errors[j].Line
})
}
}