mirror of
https://github.com/securego/gosec.git
synced 2024-12-25 20:15:54 +00:00
Change the exclude syntax to be a part of #nosec
This commit is contained in:
parent
7bb6f004ae
commit
429ac07bbd
2 changed files with 9 additions and 9 deletions
12
analyzer.go
12
analyzer.go
|
@ -154,16 +154,16 @@ func (gas *Analyzer) ignore(n ast.Node) ([]string, bool) {
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
if strings.Contains(group.Text(), "#nosec") {
|
if strings.Contains(group.Text(), "#nosec") {
|
||||||
gas.stats.NumNosec++
|
gas.stats.NumNosec++
|
||||||
return nil, true
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.Contains(group.Text(), "#exclude") {
|
|
||||||
gas.stats.NumNosec++
|
|
||||||
|
|
||||||
// Pull out the specific rules that are listed to be ignored.
|
// Pull out the specific rules that are listed to be ignored.
|
||||||
re := regexp.MustCompile("!(G\\d{3})")
|
re := regexp.MustCompile("(G\\d{3})")
|
||||||
matches := re.FindAllStringSubmatch(group.Text(), -1)
|
matches := re.FindAllStringSubmatch(group.Text(), -1)
|
||||||
|
|
||||||
|
// If no specific rules were given, ignore everything.
|
||||||
|
if matches == nil || len(matches) == 0 {
|
||||||
|
return nil, true
|
||||||
|
}
|
||||||
|
|
||||||
// Find the rule IDs to ignore.
|
// Find the rule IDs to ignore.
|
||||||
var ignores []string
|
var ignores []string
|
||||||
for _, v := range matches {
|
for _, v := range matches {
|
||||||
|
|
|
@ -135,7 +135,7 @@ var _ = Describe("Analyzer", func() {
|
||||||
|
|
||||||
nosecPackage := testutils.NewTestPackage()
|
nosecPackage := testutils.NewTestPackage()
|
||||||
defer nosecPackage.Close()
|
defer nosecPackage.Close()
|
||||||
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #exclude !G401", 1)
|
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #nosec G401", 1)
|
||||||
nosecPackage.AddFile("md5.go", nosecSource)
|
nosecPackage.AddFile("md5.go", nosecSource)
|
||||||
nosecPackage.Build()
|
nosecPackage.Build()
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ var _ = Describe("Analyzer", func() {
|
||||||
|
|
||||||
nosecPackage := testutils.NewTestPackage()
|
nosecPackage := testutils.NewTestPackage()
|
||||||
defer nosecPackage.Close()
|
defer nosecPackage.Close()
|
||||||
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #exclude !G301", 1)
|
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #nosec G301", 1)
|
||||||
nosecPackage.AddFile("md5.go", nosecSource)
|
nosecPackage.AddFile("md5.go", nosecSource)
|
||||||
nosecPackage.Build()
|
nosecPackage.Build()
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ var _ = Describe("Analyzer", func() {
|
||||||
|
|
||||||
nosecPackage := testutils.NewTestPackage()
|
nosecPackage := testutils.NewTestPackage()
|
||||||
defer nosecPackage.Close()
|
defer nosecPackage.Close()
|
||||||
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #exclude !G301 !G401", 1)
|
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #nosec G301 G401", 1)
|
||||||
nosecPackage.AddFile("md5.go", nosecSource)
|
nosecPackage.AddFile("md5.go", nosecSource)
|
||||||
nosecPackage.Build()
|
nosecPackage.Build()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue