Skip to content

Commit 429ac07

Browse files
committed
Change the exclude syntax to be a part of #nosec
1 parent 7bb6f00 commit 429ac07

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

analyzer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,16 @@ func (gas *Analyzer) ignore(n ast.Node) ([]string, bool) {
154154
for _, group := range groups {
155155
if strings.Contains(group.Text(), "#nosec") {
156156
gas.stats.NumNosec++
157-
return nil, true
158-
}
159-
160-
if strings.Contains(group.Text(), "#exclude") {
161-
gas.stats.NumNosec++
162157

163158
// Pull out the specific rules that are listed to be ignored.
164-
re := regexp.MustCompile("!(G\\d{3})")
159+
re := regexp.MustCompile("(G\\d{3})")
165160
matches := re.FindAllStringSubmatch(group.Text(), -1)
166161

162+
// If no specific rules were given, ignore everything.
163+
if matches == nil || len(matches) == 0 {
164+
return nil, true
165+
}
166+
167167
// Find the rule IDs to ignore.
168168
var ignores []string
169169
for _, v := range matches {

analyzer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ var _ = Describe("Analyzer", func() {
135135

136136
nosecPackage := testutils.NewTestPackage()
137137
defer nosecPackage.Close()
138-
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #exclude !G401", 1)
138+
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #nosec G401", 1)
139139
nosecPackage.AddFile("md5.go", nosecSource)
140140
nosecPackage.Build()
141141

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

153153
nosecPackage := testutils.NewTestPackage()
154154
defer nosecPackage.Close()
155-
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #exclude !G301", 1)
155+
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #nosec G301", 1)
156156
nosecPackage.AddFile("md5.go", nosecSource)
157157
nosecPackage.Build()
158158

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

170170
nosecPackage := testutils.NewTestPackage()
171171
defer nosecPackage.Close()
172-
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #exclude !G301 !G401", 1)
172+
nosecSource := strings.Replace(source, "h := md5.New()", "h := md5.New() // #nosec G301 G401", 1)
173173
nosecPackage.AddFile("md5.go", nosecSource)
174174
nosecPackage.Build()
175175

0 commit comments

Comments
 (0)