Skip to content

Commit 3af4ae9

Browse files
ccojocarCosmin Cojocar
authored andcommitted
Fix some lint warnings
Signed-off-by: Cosmin Cojocar <[email protected]>
1 parent bac6f0f commit 3af4ae9

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

analyzer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ func (gosec *Analyzer) ignore(n ast.Node) ([]string, bool) {
231231
gosec.stats.NumNosec++
232232

233233
// Pull out the specific rules that are listed to be ignored.
234-
re := regexp.MustCompile("(G\\d{3})")
234+
re := regexp.MustCompile(`(G\d{3})`)
235235
matches := re.FindAllStringSubmatch(group.Text(), -1)
236236

237237
// If no specific rules were given, ignore everything.
238-
if matches == nil || len(matches) == 0 {
238+
if len(matches) == 0 {
239239
return nil, true
240240
}
241241

@@ -269,7 +269,7 @@ func (gosec *Analyzer) Visit(n ast.Node) ast.Visitor {
269269
}
270270

271271
// Now create the union of exclusions.
272-
ignores := make(map[string]bool, 0)
272+
ignores := map[string]bool{}
273273
if len(gosec.context.Ignores) > 0 {
274274
for k, v := range gosec.context.Ignores[0] {
275275
ignores[k] = v

issue.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ func codeSnippet(file *os.File, start int64, end int64, n ast.Node) (string, err
7777
return "", fmt.Errorf("Invalid AST node provided")
7878
}
7979

80-
size := (int)(end - start) // Go bug, os.File.Read should return int64 ...
81-
file.Seek(start, 0) // #nosec
80+
size := (int)(end - start) // Go bug, os.File.Read should return int64 ...
81+
_, err := file.Seek(start, 0) // #nosec
82+
if err != nil {
83+
return "", fmt.Errorf("move to the beginning of file: %v", err)
84+
}
8285

8386
buf := make([]byte, size)
8487
if nread, err := file.Read(buf); err != nil || nread != size {

rules/fileperms.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ func (r *filePermissions) ID() string {
3636
func getConfiguredMode(conf map[string]interface{}, configKey string, defaultMode int64) int64 {
3737
var mode = defaultMode
3838
if value, ok := conf[configKey]; ok {
39-
switch value.(type) {
39+
switch value := value.(type) {
4040
case int64:
41-
mode = value.(int64)
41+
mode = value
4242
case string:
43-
if m, e := strconv.ParseInt(value.(string), 0, 64); e != nil {
43+
if m, e := strconv.ParseInt(value, 0, 64); e != nil {
4444
mode = defaultMode
4545
} else {
4646
mode = m

testutils/pkg.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ type TestPackage struct {
3030
// NewTestPackage will create a new and empty package. Must call Close() to cleanup
3131
// auxiliary files
3232
func NewTestPackage() *TestPackage {
33-
goPath := os.Getenv("GOPATH")
34-
// if user did not set GOPATH, set to the default
35-
if goPath == "" {
36-
goPath = build.Default.GOPATH
37-
}
38-
3933
workingDir, err := ioutil.TempDir("", "gosecs_test")
4034
if err != nil {
4135
return nil

0 commit comments

Comments
 (0)