Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more test to cover more use cases for G115 rule #1186

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ linters:
enable:
- asciicheck
- bodyclose
- copyloopvar
- dogsled
- durationcheck
- errcheck
- errorlint
- exportloopref
- gci
- ginkgolinter
- gochecknoinits
Expand Down Expand Up @@ -35,6 +35,11 @@ linters-settings:
- standard
- default
- prefix(github.com/securego)
staticcheck:
checks:
- all
- '-SA1019'

revive:
rules:
- name: dot-imports
Expand Down
45 changes: 45 additions & 0 deletions testutils/g115_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,36 @@ func main() {
`
package main

import (
"fmt"
)

func main() {
var a byte = '\xff'
b := int64(a)
fmt.Println(b)
}
`,
}, 0, gosec.NewConfig()},
{[]string{
`
package main

import (
"fmt"
)

func main() {
var a int8 = -1
b := int64(a)
fmt.Println(b)
}
`,
}, 0, gosec.NewConfig()},
{[]string{
`
package main

import (
"fmt"
"math"
Expand All @@ -187,6 +217,21 @@ func main() {
var a uint = math.MaxUint
b := CustomType(a)
fmt.Println(b)
}
`,
}, 1, gosec.NewConfig()},
{[]string{
`
package main

import (
"fmt"
)

func main() {
a := []int{1,2,3}
b := uint32(len(a))
fmt.Println(b)
}
`,
}, 1, gosec.NewConfig()},
Expand Down
Loading