Skip to content

Commit 65e9e51

Browse files
authored
refactor: update YAML library to v3 (#252)
This upgrades us to use the latest v3 version of the YAML library along with updating our unmarshal functions to use the new interface. While this annoyingly adds ~20kb to the binary, it gives us access to more stuff like information about comments and line numbers when unmarshalling and the ability to write indented output (which will be used for #248) - ultimately, we might as well just get the upgrade over with.
1 parent e04029c commit 65e9e51

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/fatih/color v1.16.0
88
github.com/google/go-cmp v0.6.0
99
golang.org/x/mod v0.14.0
10-
gopkg.in/yaml.v2 v2.4.0
10+
gopkg.in/yaml.v3 v3.0.1
1111
)
1212

1313
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
1717
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1818
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1919
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
20-
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
21-
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
20+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
21+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/configer/load.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/g-rath/osv-detector/internal/reporter"
1212
"github.com/g-rath/osv-detector/pkg/database"
13-
"gopkg.in/yaml.v2"
13+
"gopkg.in/yaml.v3"
1414
)
1515

1616
type rawDatabaseConfig struct {
@@ -21,7 +21,7 @@ type rawDatabaseConfig struct {
2121
}
2222

2323
type rawConfig struct {
24-
FilePath string
24+
FilePath string `yaml:"-"`
2525
Ignore []string `yaml:"ignore"`
2626
Databases []rawDatabaseConfig `yaml:"extra-databases"`
2727
}

pkg/lockfile/parse-pnpm-lock.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88

99
"github.com/g-rath/osv-detector/internal/cachedregexp"
10-
"gopkg.in/yaml.v2"
10+
"gopkg.in/yaml.v3"
1111
)
1212

1313
type PnpmLockPackageResolution struct {
@@ -33,11 +33,11 @@ type pnpmLockfileV6 struct {
3333
Packages map[string]PnpmLockPackage `yaml:"packages,omitempty"`
3434
}
3535

36-
func (l *PnpmLockfile) UnmarshalYAML(unmarshal func(any) error) error {
36+
func (l *PnpmLockfile) UnmarshalYAML(value *yaml.Node) error {
3737
var lockfileV6 pnpmLockfileV6
3838

39-
if err := unmarshal(&lockfileV6); err != nil {
40-
return err
39+
if err := value.Decode(&lockfileV6); err != nil {
40+
return fmt.Errorf("%w", err)
4141
}
4242

4343
parsedVersion, err := strconv.ParseFloat(lockfileV6.Version, 64)

pkg/lockfile/parse-pubspec-lock.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"os"
66

7-
"gopkg.in/yaml.v2"
7+
"gopkg.in/yaml.v3"
88
)
99

1010
type PubspecLockDescription struct {
@@ -14,17 +14,15 @@ type PubspecLockDescription struct {
1414
Ref string `yaml:"resolved-ref"`
1515
}
1616

17-
var _ yaml.Unmarshaler = &PubspecLockDescription{}
18-
19-
func (pld *PubspecLockDescription) UnmarshalYAML(unmarshal func(any) error) error {
17+
func (pld *PubspecLockDescription) UnmarshalYAML(value *yaml.Node) error {
2018
var m struct {
2119
Name string `yaml:"name"`
2220
URL string `yaml:"url"`
2321
Path string `yaml:"path"`
2422
Ref string `yaml:"resolved-ref"`
2523
}
2624

27-
err := unmarshal(&m)
25+
err := value.Decode(&m)
2826

2927
if err == nil {
3028
pld.Name = m.Name
@@ -37,10 +35,10 @@ func (pld *PubspecLockDescription) UnmarshalYAML(unmarshal func(any) error) erro
3735

3836
var str *string
3937

40-
err = unmarshal(&str)
38+
err = value.Decode(&str)
4139

4240
if err != nil {
43-
return err
41+
return fmt.Errorf("%w", err)
4442
}
4543

4644
pld.Path = *str

0 commit comments

Comments
 (0)