Skip to content

Commit

Permalink
policy: fix some code style
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed Jan 22, 2025
1 parent 9c14102 commit 7ae65e7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions pkg/policy/policytest/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package policytest

import (
"github.com/ipld/go-ipld-prime"

"github.com/ucan-wg/go-ucan/pkg/args"
"github.com/ucan-wg/go-ucan/pkg/policy"
"github.com/ucan-wg/go-ucan/pkg/policy/literal"
Expand All @@ -10,9 +11,8 @@ import (
// EmptyPolicy provides a Policy with no statements.
var EmptyPolicy = policy.Policy{}

// ExampleValidationPolicy provides a instantiated SpecPolicy containing the
// statements that are included in the second code block of the [Validation]
// section of the delegation specification.
// SpecPolicy provides a valid Policy containing the statements that are included
// in the second code block of the [Validation] section of the delegation specification.
//
// [Validation]: https://github.com/ucan-wg/delegation/tree/v1_ipld#validation
var SpecPolicy = policy.MustConstruct(
Expand All @@ -24,8 +24,8 @@ var SpecPolicy = policy.MustConstruct(
// specification has been finished/merged.

// SpecValidArguments provides valid, instantiated Arguments containing
// the key/value pairs that are included in portion of the the second code
// block of the [Validation] section of the delegation specification.
// the key/value pairs that are included in portion of the second code block
// of the [Validation] section of the delegation specification.
//
// [Validation]: https://github.com/ucan-wg/delegation/tree/v1_ipld#validation
var SpecValidArguments = args.NewBuilder().
Expand All @@ -41,8 +41,8 @@ var SpecValidArguments = args.NewBuilder().
var specValidArgumentsIPLD = mustIPLD(SpecValidArguments)

// SpecInvalidArguments provides invalid, instantiated Arguments containing
// the key/value pairs that are included in portion of the the second code
// block of the [Validation] section of the delegation specification.
// the key/value pairs that are included in portion of the second code block
// of the [Validation] section of the delegation specification.
//
// [Validation]: https://github.com/ucan-wg/delegation/tree/v1_ipld#validation
var SpecInvalidArguments = args.NewBuilder().
Expand Down
16 changes: 8 additions & 8 deletions pkg/policy/selector/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,37 +173,37 @@ func tokenize(str string) []string {
return toks
}

type parseerr struct {
type parseErr struct {
msg string
src string
col int
tok string
}

func (p parseerr) Name() string {
func (p parseErr) Name() string {
return "ParseError"
}

func (p parseerr) Message() string {
func (p parseErr) Message() string {
return p.msg
}

func (p parseerr) Column() int {
func (p parseErr) Column() int {
return p.col
}

func (p parseerr) Error() string {
func (p parseErr) Error() string {
return p.msg
}

func (p parseerr) Source() string {
func (p parseErr) Source() string {
return p.src
}

func (p parseerr) Token() string {
func (p parseErr) Token() string {
return p.tok
}

func newParseError(message string, source string, column int, token string) error {
return parseerr{message, source, column, token}
return parseErr{message, source, column, token}
}
14 changes: 7 additions & 7 deletions pkg/policy/selector/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Selector []segment
// Select perform the selection described by the selector on the input IPLD DAG.
// Select can return:
// - exactly one matched IPLD node
// - a resolutionerr error if not being able to resolve to a node
// - a resolutionErr error if not being able to resolve to a node
// - nil and no errors, if the selector couldn't match on an optional segment (with ?).
func (s Selector) Select(subject ipld.Node) (ipld.Node, error) {
return resolve(s, subject, nil)
Expand Down Expand Up @@ -316,27 +316,27 @@ func kindString(n datamodel.Node) string {
return n.Kind().String()
}

type resolutionerr struct {
type resolutionErr struct {
msg string
at []string
}

func (r resolutionerr) Name() string {
func (r resolutionErr) Name() string {
return "ResolutionError"
}

func (r resolutionerr) Message() string {
func (r resolutionErr) Message() string {
return fmt.Sprintf("can not resolve path: .%s", strings.Join(r.at, "."))
}

func (r resolutionerr) At() []string {
func (r resolutionErr) At() []string {
return r.at
}

func (r resolutionerr) Error() string {
func (r resolutionErr) Error() string {
return r.Message()
}

func newResolutionError(message string, at []string) error {
return resolutionerr{message, at}
return resolutionErr{message, at}
}
4 changes: 2 additions & 2 deletions pkg/policy/selector/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestSelect(t *testing.T) {
require.Error(t, err)
require.Empty(t, res)

require.ErrorAs(t, err, &resolutionerr{}, "error should be a resolution error")
require.ErrorAs(t, err, &resolutionErr{}, "error should be a resolution error")
})

t.Run("optional not exists", func(t *testing.T) {
Expand Down Expand Up @@ -351,7 +351,7 @@ func FuzzParseAndSelect(f *testing.F) {

// look for panic()
_, err = sel.Select(node)
if err != nil && !errors.As(err, &resolutionerr{}) {
if err != nil && !errors.As(err, &resolutionErr{}) {
// not normal, we should only have resolution errors
t.Fatal(err)
}
Expand Down

0 comments on commit 7ae65e7

Please sign in to comment.