Skip to content

Commit

Permalink
Fix multifile ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera authored and ccojocar committed Jul 15, 2024
1 parent 2f1b81b commit 0076267
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
1 change: 0 additions & 1 deletion analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ func (gosec *Analyzer) CheckRules(pkg *packages.Package) {
gosec.context.PkgFiles = pkg.Syntax
gosec.context.Imports = NewImportTracker()
gosec.context.PassedValues = make(map[string]interface{})
gosec.context.Ignores = newIgnores()
gosec.updateIgnores()
ast.Walk(gosec, file)
gosec.stats.NumFiles++
Expand Down
39 changes: 39 additions & 0 deletions testutils/g115_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,43 @@ func main() {
fmt.Println(b)
}
`}, 1, gosec.NewConfig()},
{[]string{
`
package main
import (
"fmt"
"math"
)
func main() {
var a uint = math.MaxUint
// #nosec G115
b := int64(a)
fmt.Println(b)
}
`,
}, 0, gosec.NewConfig()},
{[]string{
`
package main
import (
"fmt"
"math"
)
func main() {
var a uint = math.MaxUint
// #nosec G115
b := int64(a)
fmt.Println(b)
}
`, `
package main
func ExampleFunction() {
}
`,
}, 0, gosec.NewConfig()},
}

0 comments on commit 0076267

Please sign in to comment.