Skip to content

Commit 7e88a28

Browse files
Lint issue
1 parent a4d1c04 commit 7e88a28

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
@@ -3299,7 +3299,7 @@ func getGitignorePatterns(directoryPath, zipFilePath string) ([]string, error) {
32993299
for _, line := range lines {
33003300
line = strings.TrimSpace(line)
33013301

3302-
//This condition skips lines that are empty, comments.
3302+
// This condition skips lines that are empty, comments.
33033303
// Excluding the lines that contain negotiation characters like !, which are used to negate patterns
33043304
if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, "!") {
33053305
continue
@@ -3343,20 +3343,28 @@ func readGitIgnoreFromZip(zipPath string) ([]byte, error) {
33433343
expectedGitignorePath := rootFolder + "/.gitignore"
33443344

33453345
for _, f := range r.File {
3346-
if f.Name == expectedGitignorePath {
3347-
rc, err := f.Open()
3348-
if err != nil {
3349-
return []byte(""), fmt.Errorf("failed to open .gitignore inside zip: %w", err)
3350-
}
3351-
defer rc.Close()
3346+
if f.Name != expectedGitignorePath {
3347+
continue
3348+
}
3349+
rc, err := f.Open()
3350+
if err != nil {
3351+
return []byte(""), fmt.Errorf("failed to open .gitignore inside zip: %w", err)
3352+
}
33523353

3353-
// Read file content
3354-
data, err := io.ReadAll(rc)
3354+
// Read file content
3355+
data, err := io.ReadAll(rc)
3356+
if err != nil {
3357+
err := rc.Close()
33553358
if err != nil {
3356-
return []byte(""), fmt.Errorf("failed to read .gitignore content inside zip : %w", err)
3359+
return nil, err
33573360
}
3358-
return data, nil
3361+
return []byte(""), fmt.Errorf("failed to read .gitignore content inside zip : %w", err)
3362+
}
3363+
// Close with error handling
3364+
if err := rc.Close(); err != nil {
3365+
logger.PrintfIfVerbose("Error closing .gitignore reader: %v", err)
33593366
}
3367+
return data, nil
33603368
}
33613369
return []byte(""), fmt.Errorf(".gitignore not found in zip: %s", zipPath)
33623370
}

internal/commands/scan_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,9 +2681,8 @@ func TestGetGitignorePatterns_ZipPath_GitIgnore_EmptyPatternList(t *testing.T) {
26812681
return
26822682
}
26832683

2684-
gitIgnoreFilter, err := getGitignorePatterns("", zipPath)
2684+
gitIgnoreFilter, _ := getGitignorePatterns("", zipPath)
26852685
assert.Assert(t, len(gitIgnoreFilter) == 0, "Expected no patterns from empty .gitignore file")
2686-
26872686
}
26882687

26892688
func TestGetGitignorePatterns_ZipPath_GitIgnore_PatternList(t *testing.T) {
@@ -2733,9 +2732,8 @@ a*cation-jira.yml`
27332732
return
27342733
}
27352734

2736-
gitIgnoreFilter, err := getGitignorePatterns("", zipPath)
2735+
gitIgnoreFilter, _ := getGitignorePatterns("", zipPath)
27372736
assert.Assert(t, len(gitIgnoreFilter) > 0, "Expected patterns from .gitignore file")
2738-
27392737
}
27402738

27412739
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)