Skip to content

Commit 344ccfc

Browse files
Lint issue
1 parent 43622d6 commit 344ccfc

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

internal/commands/scan.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,7 +3292,7 @@ func getGitignorePatterns(directoryPath, zipFilePath string) ([]string, error) {
32923292
for _, line := range lines {
32933293
line = strings.TrimSpace(line)
32943294

3295-
//This condition skips lines that are empty, comments.
3295+
// This condition skips lines that are empty, comments.
32963296
// Excluding the lines that contain negotiation characters like !, which are used to negate patterns
32973297
if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, "!") {
32983298
continue
@@ -3336,20 +3336,28 @@ func readGitIgnoreFromZip(zipPath string) ([]byte, error) {
33363336
expectedGitignorePath := rootFolder + "/.gitignore"
33373337

33383338
for _, f := range r.File {
3339-
if f.Name == expectedGitignorePath {
3340-
rc, err := f.Open()
3341-
if err != nil {
3342-
return []byte(""), fmt.Errorf("failed to open .gitignore inside zip: %w", err)
3343-
}
3344-
defer rc.Close()
3339+
if f.Name != expectedGitignorePath {
3340+
continue
3341+
}
3342+
rc, err := f.Open()
3343+
if err != nil {
3344+
return []byte(""), fmt.Errorf("failed to open .gitignore inside zip: %w", err)
3345+
}
33453346

3346-
// Read file content
3347-
data, err := io.ReadAll(rc)
3347+
// Read file content
3348+
data, err := io.ReadAll(rc)
3349+
if err != nil {
3350+
err := rc.Close()
33483351
if err != nil {
3349-
return []byte(""), fmt.Errorf("failed to read .gitignore content inside zip : %w", err)
3352+
return nil, err
33503353
}
3351-
return data, nil
3354+
return []byte(""), fmt.Errorf("failed to read .gitignore content inside zip : %w", err)
3355+
}
3356+
// Close with error handling
3357+
if err := rc.Close(); err != nil {
3358+
logger.PrintfIfVerbose("Error closing .gitignore reader: %v", err)
33523359
}
3360+
return data, nil
33533361
}
33543362
return []byte(""), fmt.Errorf(".gitignore not found in zip: %s", zipPath)
33553363
}

internal/commands/scan_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,9 +2579,8 @@ func TestGetGitignorePatterns_ZipPath_GitIgnore_EmptyPatternList(t *testing.T) {
25792579
return
25802580
}
25812581

2582-
gitIgnoreFilter, err := getGitignorePatterns("", zipPath)
2582+
gitIgnoreFilter, _ := getGitignorePatterns("", zipPath)
25832583
assert.Assert(t, len(gitIgnoreFilter) == 0, "Expected no patterns from empty .gitignore file")
2584-
25852584
}
25862585

25872586
func TestGetGitignorePatterns_ZipPath_GitIgnore_PatternList(t *testing.T) {
@@ -2631,9 +2630,8 @@ a*cation-jira.yml`
26312630
return
26322631
}
26332632

2634-
gitIgnoreFilter, err := getGitignorePatterns("", zipPath)
2633+
gitIgnoreFilter, _ := getGitignorePatterns("", zipPath)
26352634
assert.Assert(t, len(gitIgnoreFilter) > 0, "Expected patterns from .gitignore file")
2636-
26372635
}
26382636

26392637
func TestGetGitignorePatterns_ZipPath_GitIgnore_PermissionDenied(t *testing.T) {

internal/params/flags.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ const (
169169
LogFileUsage = "Saves logs to the specified file path only"
170170
LogFileConsoleFlag = "log-file-console"
171171
LogFileConsoleUsage = "Saves logs to the specified file path as well as to the console"
172-
GitIgnoreFileFilterFlag = "gitignore-file-filter"
173-
GitIgnoreFileFilterUsage = "Exclude files and directories listed in the .gitignore file"
172+
GitIgnoreFileFilterFlag = "use-gitignore"
173+
GitIgnoreFileFilterUsage = "Exclude files and directories from the scan based on the patterns defined in the directory's .gitignore file"
174174
// INDIVIDUAL FILTER FLAGS
175175
SastFilterFlag = "sast-filter"
176176
SastFilterUsage = "SAST filter"

0 commit comments

Comments
 (0)