Skip to content

Commit

Permalink
fix(swift): add ID field (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen authored Aug 23, 2023
1 parent e39b964 commit 40c1f85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/swift/swift/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package swift
import (
dio "github.com/aquasecurity/go-dep-parser/pkg/io"
"github.com/aquasecurity/go-dep-parser/pkg/types"
"github.com/aquasecurity/go-dep-parser/pkg/utils"
"github.com/liamg/jfather"
"golang.org/x/xerrors"
"io"
Expand Down Expand Up @@ -33,8 +34,10 @@ func (Parser) Parse(r dio.ReadSeekerAt) ([]types.Library, []types.Dependency, er
pins = lockFile.Pins
}
for _, pin := range pins {
name := libraryName(pin, lockFile.Version)
libs = append(libs, types.Library{
Name: libraryName(pin, lockFile.Version),
ID: utils.PackageID(name, pin.State.Version),
Name: name,
Version: pin.State.Version,
Locations: []types.Location{
{
Expand Down
7 changes: 7 additions & 0 deletions pkg/swift/swift/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ func TestParser_Parse(t *testing.T) {
inputFile: "testdata/happy-v1-Package.resolved",
want: []types.Library{
{
ID: "github.com/Quick/Nimble@9.2.1",
Name: "github.com/Quick/Nimble",
Version: "9.2.1",
Locations: []types.Location{{StartLine: 4, EndLine: 12}},
},
{
ID: "github.com/ReactiveCocoa/ReactiveSwift@7.1.1",
Name: "github.com/ReactiveCocoa/ReactiveSwift",
Version: "7.1.1",
Locations: []types.Location{{StartLine: 13, EndLine: 21}},
Expand All @@ -46,26 +48,31 @@ func TestParser_Parse(t *testing.T) {
inputFile: "testdata/happy-v2-Package.resolved",
want: []types.Library{
{
ID: "github.com/Quick/Nimble@9.2.1",
Name: "github.com/Quick/Nimble",
Version: "9.2.1",
Locations: []types.Location{{StartLine: 21, EndLine: 29}},
},
{
ID: "github.com/Quick/Quick@7.2.0",
Name: "github.com/Quick/Quick",
Version: "7.2.0",
Locations: []types.Location{{StartLine: 30, EndLine: 38}},
},
{
ID: "github.com/ReactiveCocoa/ReactiveSwift@7.1.1",
Name: "github.com/ReactiveCocoa/ReactiveSwift",
Version: "7.1.1",
Locations: []types.Location{{StartLine: 39, EndLine: 47}},
},
{
ID: "github.com/mattgallagher/CwlCatchException@2.1.2",
Name: "github.com/mattgallagher/CwlCatchException",
Version: "2.1.2",
Locations: []types.Location{{StartLine: 3, EndLine: 11}},
},
{
ID: "github.com/mattgallagher/CwlPreconditionTesting@2.1.2",
Name: "github.com/mattgallagher/CwlPreconditionTesting",
Version: "2.1.2",
Locations: []types.Location{{StartLine: 12, EndLine: 20}},
Expand Down

0 comments on commit 40c1f85

Please sign in to comment.