improve filter func comments (#3674)

#### Type of change

- [x] 🧹 Tech Debt/Cleanup
This commit is contained in:
Keepers 2023-06-27 11:23:30 -06:00 committed by GitHub
parent 6fd8cc54b2
commit a9f4a1b28d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -121,118 +121,121 @@ func Identity(id string) Filter {
} }
} }
// Equal creates a filter where Compare(v) is true if, for any target string, // Equal creates a filter f where f.Compare(v) is true if, for any target t in f,
// norm(target) == norm(v) // t == v
func Equal(target []string) Filter { func Equal(targets []string) Filter {
return newFilter(EqualTo, target, normAll(target), false) return newFilter(EqualTo, targets, normAll(targets), false)
} }
// NotEqual creates a filter where Compare(v) is true if, for any target string, // NotEqual creates a filter f where f.Compare(v) is true if, for any target t in f,
// target != v // t != v
func NotEqual(target []string) Filter { func NotEqual(targets []string) Filter {
return newFilter(EqualTo, target, normAll(target), true) return newFilter(EqualTo, targets, normAll(targets), true)
} }
// StrictEqual creates a filter where Compare(v) is true if, for any target string, // StrictEqual creates a filter f where f.Compare(v) is true if, for any target t in f,
// target === v. Target and v are not normalized for this comparison. The comparison // t === v.
// is case sensitive and ignores character folding. // t and v are not normalized for this comparison.
func StrictEqual(target []string) Filter { // The comparison is case sensitive and ignores character folding.
return newFilter(StrictEqualTo, target, normAll(target), false) func StrictEqual(targets []string) Filter {
return newFilter(StrictEqualTo, targets, normAll(targets), false)
} }
// NotStrictEqual creates a filter where Compare(v) is true if, for any target string, // NotStrictEqual creates a filter f where f.Compare(v) is true if, for any target t in f,
// target != v // t !== v.
func NotStrictEqual(target []string) Filter { // t and v are not normalized for this comparison.
return newFilter(StrictEqualTo, target, normAll(target), true) // The comparison is case sensitive and ignores character folding.
func NotStrictEqual(targets []string) Filter {
return newFilter(StrictEqualTo, targets, normAll(targets), true)
} }
// Greater creates a filter where Compare(v) is true if, for any target string, // Greater creates a filter f where f.Compare(v) is true if, for any target t in f,
// target > v // t > v
func Greater(target []string) Filter { func Greater(targets []string) Filter {
return newFilter(GreaterThan, target, normAll(target), false) return newFilter(GreaterThan, targets, normAll(targets), false)
} }
// NotGreater creates a filter where Compare(v) is true if, for any target string, // NotGreater creates a filter f where f.Compare(v) is true if, for any target t in f,
// target <= v // t <= v
func NotGreater(target []string) Filter { func NotGreater(targets []string) Filter {
return newFilter(GreaterThan, target, normAll(target), true) return newFilter(GreaterThan, targets, normAll(targets), true)
} }
// Less creates a filter where Compare(v) is true if, for any target string, // Less creates a filter f where f.Compare(v) is true if, for any target t in f,
// target < v // t < v
func Less(target []string) Filter { func Less(targets []string) Filter {
return newFilter(LessThan, target, normAll(target), false) return newFilter(LessThan, targets, normAll(targets), false)
} }
// NotLess creates a filter where Compare(v) is true if, for any target string, // NotLess creates a filter f where f.Compare(v) is true if, for any target t in f,
// target >= v // t >= v
func NotLess(target []string) Filter { func NotLess(targets []string) Filter {
return newFilter(LessThan, target, normAll(target), true) return newFilter(LessThan, targets, normAll(targets), true)
} }
// Contains creates a filter where Compare(v) is true if, for any target string, // Contains creates a filter f where f.Compare(v) is true if, for any target t in f,
// target.Contains(v) // t.Contains(v)
func Contains(target []string) Filter { func Contains(targets []string) Filter {
return newFilter(TargetContains, target, normAll(target), false) return newFilter(TargetContains, targets, normAll(targets), false)
} }
// NotContains creates a filter where Compare(v) is true if, for any target string, // NotContains creates a filter f where f.Compare(v) is true if, for any target t in f,
// !target.Contains(v) // !t.Contains(v)
func NotContains(target []string) Filter { func NotContains(targets []string) Filter {
return newFilter(TargetContains, target, normAll(target), true) return newFilter(TargetContains, targets, normAll(targets), true)
} }
// In creates a filter where Compare(v) is true if, for any target string, // In creates a filter f where f.Compare(v) is true if, for any target t in f,
// v.Contains(target) // v.Contains(t)
func In(target []string) Filter { func In(targets []string) Filter {
return newFilter(TargetIn, target, normAll(target), false) return newFilter(TargetIn, targets, normAll(targets), false)
} }
// NotIn creates a filter where Compare(v) is true if, for any target string, // NotIn creates a filter f where f.Compare(v) is true if, for any target t in f,
// !v.Contains(target) // !v.Contains(t)
func NotIn(target []string) Filter { func NotIn(targets []string) Filter {
return newFilter(TargetIn, target, normAll(target), true) return newFilter(TargetIn, targets, normAll(targets), true)
} }
// Pass creates a filter where Compare(v) always returns true // Pass creates a filter f where f.Compare(v) always returns true
func Pass() Filter { func Pass() Filter {
return newFilter(Passes, []string{"*"}, nil, false) return newFilter(Passes, []string{"*"}, nil, false)
} }
// Fail creates a filter where Compare(v) always returns false // Fail creates a filter f where f.Compare(v) always returns false
func Fail() Filter { func Fail() Filter {
return newFilter(Fails, []string{""}, nil, false) return newFilter(Fails, []string{""}, nil, false)
} }
// Prefix creates a filter where Compare(v) is true if, for any target string, // Prefix creates a filter f where f.Compare(v) is true if, for any target t in f,
// target.Prefix(v) // t.Prefix(v)
func Prefix(target []string) Filter { func Prefix(targets []string) Filter {
return newFilter(TargetPrefixes, target, normAll(target), false) return newFilter(TargetPrefixes, targets, normAll(targets), false)
} }
// NotPrefix creates a filter where Compare(v) is true if, for any target string, // NotPrefix creates a filter f where f.Compare(v) is true if, for any target t in f,
// !target.Prefix(v) // !t.Prefix(v)
func NotPrefix(target []string) Filter { func NotPrefix(targets []string) Filter {
return newFilter(TargetPrefixes, target, normAll(target), true) return newFilter(TargetPrefixes, targets, normAll(targets), true)
} }
// Suffix creates a filter where Compare(v) is true if, for any target string, // Suffix creates a filter f where f.Compare(v) is true if, for any target t in f,
// target.Suffix(v) // t.Suffix(v)
func Suffix(target []string) Filter { func Suffix(targets []string) Filter {
return newFilter(TargetSuffixes, target, normAll(target), false) return newFilter(TargetSuffixes, targets, normAll(targets), false)
} }
// NotSuffix creates a filter where Compare(v) is true if, for any target string, // NotSuffix creates a filter f where f.Compare(v) is true if, for any target t in f,
// !target.Suffix(v) // !t.Suffix(v)
func NotSuffix(target []string) Filter { func NotSuffix(targets []string) Filter {
return newFilter(TargetSuffixes, target, normAll(target), true) return newFilter(TargetSuffixes, targets, normAll(targets), true)
} }
// PathPrefix creates a filter where Compare(v) is true if, for any target string, // PathPrefix creates a filter f where f.Compare(v) is true if, for any target t in f,
// target.Prefix(v) && // t.Prefix(v) &&
// split(target)[i].Equals(split(v)[i]) for _all_ i in 0..len(target)-1 // split(t)[i].Equals(split(v)[i]) for _all_ i in 0..len(t)-1
// ex: target "/foo/bar" returns true for input "/foo/bar/baz", // ex: t="/foo/bar" returns true for v="/foo/bar/baz",
// but false for "/foo/barbaz" // but false for v="/foo/barbaz"
func PathPrefix(targets []string) Filter { func PathPrefix(targets []string) Filter {
tgts := make([]string, len(targets)) tgts := make([]string, len(targets))
for i := range targets { for i := range targets {
@ -242,11 +245,11 @@ func PathPrefix(targets []string) Filter {
return newFilter(TargetPathPrefix, targets, tgts, false) return newFilter(TargetPathPrefix, targets, tgts, false)
} }
// NotPathPrefix creates a filter where Compare(v) is true if, for any target string, // NotPathPrefix creates a filter f where f.Compare(v) is true if, for any target t in f,
// !target.Prefix(v) || // !t.Prefix(v) ||
// !split(target)[i].Equals(split(v)[i]) for _any_ i in 0..len(target)-1 // !split(t)[i].Equals(split(v)[i]) for _any_ i in 0..len(t)-1
// ex: target "/foo/bar" returns false for input "/foo/bar/baz", // ex: t="/foo/bar" returns false for v="/foo/bar/baz",
// but true for "/foo/barbaz" // but true for v="/foo/barbaz"
func NotPathPrefix(targets []string) Filter { func NotPathPrefix(targets []string) Filter {
tgts := make([]string, len(targets)) tgts := make([]string, len(targets))
for i := range targets { for i := range targets {
@ -256,13 +259,13 @@ func NotPathPrefix(targets []string) Filter {
return newFilter(TargetPathPrefix, targets, tgts, true) return newFilter(TargetPathPrefix, targets, tgts, true)
} }
// PathContains creates a filter where Compare(v) is true if, for any target string, // PathContains creates a filter f where f.Compare(v) is true if, for any target t in f,
// for _any_ elem e in split(v), target.Equals(e) || // for _any_ elem e in split(v), t.Equals(e) ||
// for _any_ sequence of elems in split(v), target.Equals(path.Join(e[n:m])) // for _any_ sequence of elems in split(v), t.Equals(path.Join(e[n:m]))
// ex: target "foo" returns true for input "/baz/foo/bar", // ex: t="foo" returns true for v="/baz/foo/bar",
// but false for "/baz/foobar" // but false for v="/baz/foobar"
// ex: target "baz/foo" returns true for input "/baz/foo/bar", // ex: t="baz/foo" returns true for v="/baz/foo/bar",
// but false for "/baz/foobar" // but false for v="/baz/foobar"
func PathContains(targets []string) Filter { func PathContains(targets []string) Filter {
tgts := make([]string, len(targets)) tgts := make([]string, len(targets))
for i := range targets { for i := range targets {
@ -272,13 +275,13 @@ func PathContains(targets []string) Filter {
return newFilter(TargetPathContains, targets, tgts, false) return newFilter(TargetPathContains, targets, tgts, false)
} }
// NotPathContains creates a filter where Compare(v) is true if, for any target string, // NotPathContains creates a filter f where f.Compare(v) is true if, for any target t in f,
// for _every_ elem e in split(v), !target.Equals(e) || // for _every_ elem e in split(v), !t.Equals(e) ||
// for _every_ sequence of elems in split(v), !target.Equals(path.Join(e[n:m])) // for _every_ sequence of elems in split(v), !t.Equals(path.Join(e[n:m]))
// ex: target "foo" returns false for input "/baz/foo/bar", // ex: t="foo" returns false for v="/baz/foo/bar",
// but true for "/baz/foobar" // but true for v="/baz/foobar"
// ex: target "baz/foo" returns false for input "/baz/foo/bar", // ex: t="baz/foo" returns false for v="/baz/foo/bar",
// but true for "/baz/foobar" // but true for v="/baz/foobar"
func NotPathContains(targets []string) Filter { func NotPathContains(targets []string) Filter {
tgts := make([]string, len(targets)) tgts := make([]string, len(targets))
for i := range targets { for i := range targets {
@ -288,11 +291,11 @@ func NotPathContains(targets []string) Filter {
return newFilter(TargetPathContains, targets, tgts, true) return newFilter(TargetPathContains, targets, tgts, true)
} }
// PathSuffix creates a filter where Compare(v) is true if, for any target string, // PathSuffix creates a filter f where f.Compare(v) is true if, for any target t in f,
// target.Suffix(v) && // t.Suffix(v) &&
// split(target)[i].Equals(split(v)[i]) for _all_ i in 0..len(target)-1 // split(t)[i].Equals(split(v)[i]) for _all_ i in 0..len(t)-1
// ex: target "/bar/baz" returns true for input "/foo/bar/baz", // ex: t="/bar/baz" returns true for v="/foo/bar/baz",
// but false for "/foobar/baz" // but false for v="/foobar/baz"
func PathSuffix(targets []string) Filter { func PathSuffix(targets []string) Filter {
tgts := make([]string, len(targets)) tgts := make([]string, len(targets))
for i := range targets { for i := range targets {
@ -302,11 +305,11 @@ func PathSuffix(targets []string) Filter {
return newFilter(TargetPathSuffix, targets, tgts, false) return newFilter(TargetPathSuffix, targets, tgts, false)
} }
// NotPathSuffix creates a filter where Compare(v) is true if // NotPathSuffix creates a filter f where f.Compare(v) is true if, for any target t in f,
// !target.Suffix(v) || // !t.Suffix(v) ||
// !split(target)[i].Equals(split(v)[i]) for _any_ i in 0..len(target)-1 // !split(t)[i].Equals(split(v)[i]) for _any_ i in 0..len(t)-1
// ex: target "/bar/baz" returns false for input "/foo/bar/baz", // ex: t="/bar/baz" returns false for v="/foo/bar/baz",
// but true for "/foobar/baz" // but true for v="/foobar/baz"
func NotPathSuffix(targets []string) Filter { func NotPathSuffix(targets []string) Filter {
tgts := make([]string, len(targets)) tgts := make([]string, len(targets))
for i := range targets { for i := range targets {
@ -316,11 +319,11 @@ func NotPathSuffix(targets []string) Filter {
return newFilter(TargetPathSuffix, targets, tgts, true) return newFilter(TargetPathSuffix, targets, tgts, true)
} }
// PathEquals creates a filter where Compare(v) is true if, for any target string, // PathEquals creates a filter f where f.Compare(v) is true if, for any target t in f,
// target.Equals(v) && // t.Equals(v) &&
// split(target)[i].Equals(split(v)[i]) for _all_ i in 0..len(target)-1 // split(t)[i].Equals(split(v)[i]) for _all_ i in 0..len(t)-1
// ex: target "foo" returns true for inputs "/foo/", "/foo", and "foo/" // ex: t="foo" returns true for v="/foo/", v="/foo", and v="foo/"
// but false for "/foo/bar", "bar/foo/", and "/foobar/" // but false for v="/foo/bar", v="bar/foo/", and v="/foobar/"
func PathEquals(targets []string) Filter { func PathEquals(targets []string) Filter {
tgts := make([]string, len(targets)) tgts := make([]string, len(targets))
for i := range targets { for i := range targets {
@ -330,11 +333,11 @@ func PathEquals(targets []string) Filter {
return newFilter(TargetPathEquals, targets, tgts, false) return newFilter(TargetPathEquals, targets, tgts, false)
} }
// NotPathEquals creates a filter where Compare(v) is true if, for any target string, // NotPathEquals creates a filter f where f.Compare(v) is true if, for any target t in f,
// !target.Equals(v) || // !t.Equals(v) ||
// !split(target)[i].Equals(split(v)[i]) for _all_ i in 0..len(target)-1 // !split(t)[i].Equals(split(v)[i]) for _all_ i in 0..len(t)-1
// ex: target "foo" returns true "/foo/bar", "bar/foo/", and "/foobar/" // ex: t="foo" returns true v="/foo/bar", v="bar/foo/", and v="/foobar/"
// but false for for inputs "/foo/", "/foo", and "foo/" // but false for for v="/foo/", v="/foo", and v="foo/"
func NotPathEquals(targets []string) Filter { func NotPathEquals(targets []string) Filter {
tgts := make([]string, len(targets)) tgts := make([]string, len(targets))
for i := range targets { for i := range targets {