forked from securego/gosec
-
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.
Report for Golang errors (securego#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>
- Loading branch information
Showing
6 changed files
with
117 additions
and
18 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 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
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,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 | ||
}) | ||
} | ||
} |
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