Skip to content

Commit

Permalink
cocoapods-audit
Browse files Browse the repository at this point in the history
  • Loading branch information
barv-jfrog committed Oct 1, 2024
1 parent 4763b35 commit 17d8b80
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions commands/audit/sca/cocoapods/cocoapods.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ func GetTechDependencyLocation(directDependencyName, directDependencyVersion str
lines := strings.Split(string(data), "\n")
var startLine, startCol, endLine, endCol int
foundDependency := false
var tempIndex int
for i, line := range lines {
if strings.Contains(line, directDependencyName) {
startLine = i
startCol = strings.Index(line, directDependencyName)
foundDependency = true
tempIndex = i
}
if foundDependency && strings.Contains(line, directDependencyVersion) {
// This means we are in a new dependency (we cannot find dependency name and version together)
if i > tempIndex && foundDependency && strings.Contains(line, "pod") {
foundDependency = false
} else if foundDependency && strings.Contains(line, directDependencyVersion) {
endLine = i
endCol = len(line)
var snippet string
Expand Down Expand Up @@ -89,11 +94,16 @@ func FixTechDependency(dependencyName, dependencyVersion, fixVersion string, des
}
lines := strings.Split(string(data), "\n")
foundDependency := false
for _, line := range lines {
var tempIndex int
for index, line := range lines {
if strings.Contains(line, dependencyName) {
foundDependency = true
tempIndex = index
}
if foundDependency && strings.Contains(line, dependencyVersion) {
// This means we are in a new dependency (we cannot find dependency name and version together)
if index > tempIndex && foundDependency && strings.Contains(line, "pod") {

Check failure on line 104 in commands/audit/sca/cocoapods/cocoapods.go

View workflow job for this annotation

GitHub Actions / Static-Check

ifElseChain: rewrite if-else to switch statement (gocritic)
foundDependency = false
} else if foundDependency && strings.Contains(line, dependencyVersion) {
newLine := strings.Replace(line, dependencyVersion, fixVersion, 1)
newLines = append(newLines, newLine)
foundDependency = false
Expand Down

0 comments on commit 17d8b80

Please sign in to comment.