@@ -2,6 +2,7 @@ package rule
2
2
3
3
import (
4
4
"fmt"
5
+ "sort"
5
6
6
7
"github.com/conventionalcommit/commitlint/message"
7
8
)
@@ -26,7 +27,13 @@ func (r *ScopeEnumRule) Validate(msg *message.Commit) (string, bool) {
26
27
27
28
// SetAndCheckArgument sets the needed argument for the rule
28
29
func (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
30
37
}
31
38
32
39
// TypeEnumRule to validate types
@@ -49,5 +56,18 @@ func (r *TypeEnumRule) Validate(msg *message.Commit) (string, bool) {
49
56
50
57
// SetAndCheckArgument sets the needed argument for the rule
51
58
func (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
53
73
}
0 commit comments