Skip to content

Commit fe5c3b2

Browse files
committed
[vet] Make implicit dep detection more accurate
1 parent cb49e6c commit fe5c3b2

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

pkg/vet/yarn.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package vet
22

33
import (
44
"bufio"
5-
"bytes"
65
"encoding/json"
76
"fmt"
87
"io"
98
"io/ioutil"
109
"os"
1110
"path/filepath"
11+
"regexp"
1212
"strings"
1313

1414
log "github.com/sirupsen/logrus"
@@ -115,14 +115,13 @@ func (c *checkImplicitTransitiveDependencies) getPkgJSON(pkg *leeway.Package) (*
115115
return &res, nil
116116
}
117117

118-
func (c *checkImplicitTransitiveDependencies) grepInFile(fn string, pat string) (contains bool, err error) {
118+
func (c *checkImplicitTransitiveDependencies) grepInFile(fn string, pat *regexp.Regexp) (contains bool, err error) {
119119
f, err := os.Open(fn)
120120
if err != nil {
121121
return
122122
}
123123
defer f.Close()
124124

125-
patb := []byte(pat)
126125
r := bufio.NewReader(f)
127126
for {
128127
bt, err := r.ReadBytes('\n')
@@ -133,7 +132,7 @@ func (c *checkImplicitTransitiveDependencies) grepInFile(fn string, pat string)
133132
return false, err
134133
}
135134

136-
if bytes.Contains(bt, patb) {
135+
if pat.Match(bt) {
137136
return true, nil
138137
}
139138
}
@@ -156,7 +155,8 @@ func (c *checkImplicitTransitiveDependencies) RunPkg(pkg *leeway.Package) ([]Fin
156155
}
157156

158157
for yarnpkg := range c.pkgs {
159-
ok, err := c.grepInFile(src, yarnpkg)
158+
r, _ := regexp.Compile(fmt.Sprintf("['\"]%s['\"/]", yarnpkg))
159+
ok, err := c.grepInFile(src, r)
160160
if err != nil {
161161
return nil, err
162162
}

0 commit comments

Comments
 (0)