@@ -2,6 +2,7 @@ package rule
22
33import (
44 "fmt"
5+ "sort"
56
67 "github.com/conventionalcommit/commitlint/message"
78)
@@ -26,7 +27,13 @@ func (r *ScopeEnumRule) Validate(msg *message.Commit) (string, bool) {
2627
2728// SetAndCheckArgument sets the needed argument for the rule
2829func (r * ScopeEnumRule ) SetAndCheckArgument (arg interface {}) error {
29- return setStringArrArg (& r .Scopes , arg , r .Name ())
30+ err := setStringArrArg (& r .Scopes , arg , r .Name ())
31+ if err != nil {
32+ return err
33+ }
34+ // sorting the string elements for binary search
35+ sort .Strings (r .Scopes )
36+ return nil
3037}
3138
3239// TypeEnumRule to validate types
@@ -49,5 +56,18 @@ func (r *TypeEnumRule) Validate(msg *message.Commit) (string, bool) {
4956
5057// SetAndCheckArgument sets the needed argument for the rule
5158func (r * TypeEnumRule ) SetAndCheckArgument (arg interface {}) error {
52- return setStringArrArg (& r .Types , arg , r .Name ())
59+ err := setStringArrArg (& r .Types , arg , r .Name ())
60+ if err != nil {
61+ return err
62+ }
63+ // sorting the string elements for binary search
64+ sort .Strings (r .Types )
65+ return nil
66+ }
67+
68+ func search (arr []string , toFind string ) bool {
69+ ind := sort .Search (len (arr ), func (i int ) bool {
70+ return toFind <= arr [i ]
71+ })
72+ return ind < len (arr ) && arr [ind ] == toFind
5373}
0 commit comments