diff --git a/.golangci.yml b/.golangci.yml index ec8d731..30c32ab 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -18,6 +18,9 @@ linters-settings: - tests misspell: locale: US + revive: + rules: + - name: exported staticcheck: checks: ["all", "-ST1000", "-ST1005"] @@ -31,6 +34,7 @@ linters: - govet - ineffassign - misspell + - revive - staticcheck - typecheck - unused diff --git a/decode.go b/decode.go index f02fc05..58d929f 100644 --- a/decode.go +++ b/decode.go @@ -924,7 +924,7 @@ func (d *Decoder) decodeByUnmarshaler(ctx context.Context, dst reflect.Value, sr if err != nil { return err } - jsonBytes, err := YAMLToJSON(b) + jsonBytes, err := ToJSON(b) if err != nil { return err } diff --git a/encode.go b/encode.go index 97c1fa5..cc93981 100644 --- a/encode.go +++ b/encode.go @@ -410,7 +410,7 @@ func (e *Encoder) encodeByMarshaler(ctx context.Context, v reflect.Value, column if err != nil { return nil, err } - doc, err := JSONToYAML(jsonBytes) + doc, err := FromJSON(jsonBytes) if err != nil { return nil, err } diff --git a/yaml.go b/yaml.go index ec2103b..09facfa 100644 --- a/yaml.go +++ b/yaml.go @@ -220,8 +220,8 @@ func FormatError(e error, colored, inclSource bool) string { return e.Error() } -// YAMLToJSON convert YAML bytes to JSON. -func YAMLToJSON(bytes []byte) ([]byte, error) { +// ToJSON converts YAML bytes to JSON. +func ToJSON(bytes []byte) ([]byte, error) { var v interface{} if err := UnmarshalWithOptions(bytes, &v, UseOrderedMap()); err != nil { return nil, err @@ -233,8 +233,8 @@ func YAMLToJSON(bytes []byte) ([]byte, error) { return out, nil } -// JSONToYAML convert JSON bytes to YAML. -func JSONToYAML(bytes []byte) ([]byte, error) { +// FromJSON converts JSON bytes to YAML. +func FromJSON(bytes []byte) ([]byte, error) { var v interface{} if err := UnmarshalWithOptions(bytes, &v, UseOrderedMap()); err != nil { return nil, err @@ -246,6 +246,20 @@ func JSONToYAML(bytes []byte) ([]byte, error) { return out, nil } +// YAMLToJSON converts YAML bytes to JSON. +// +// Deprecated: Use ToJSON instead. +func YAMLToJSON(bytes []byte) ([]byte, error) { //nolint:revive // exported + return ToJSON(bytes) +} + +// JSONToYAML convert JSON bytes to YAML. +// +// Deprecated: Use FromJSON instead. +func JSONToYAML(bytes []byte) ([]byte, error) { + return FromJSON(bytes) +} + var ( globalCustomMarshalerMu sync.Mutex globalCustomUnmarshalerMu sync.Mutex