Skip to content

Commit

Permalink
Change the exclude syntax to be a part of #nosec
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmcclintock committed Mar 8, 2018
1 parent 7bb6f00 commit 429ac07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ func (gas *Analyzer) ignore(n ast.Node) ([]string, bool) {
for _, group := range groups {
if strings.Contains(group.Text(), "#nosec") {
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.
re := regexp.MustCompile("!(G\\d{3})")
re := regexp.MustCompile("(G\\d{3})")
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.
var ignores []string
for _, v := range matches {
Expand Down
6 changes: 3 additions & 3 deletions analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var _ = Describe("Analyzer", func() {

nosecPackage := testutils.NewTestPackage()
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.Build()

Expand All @@ -152,7 +152,7 @@ var _ = Describe("Analyzer", func() {

nosecPackage := testutils.NewTestPackage()
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.Build()

Expand All @@ -169,7 +169,7 @@ var _ = Describe("Analyzer", func() {

nosecPackage := testutils.NewTestPackage()
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.Build()

Expand Down

0 comments on commit 429ac07

Please sign in to comment.