diff --git a/go.mod b/go.mod index 5a69621e..41cffc30 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/quasilyte/go-ruleguard/dsl v0.3.15 github.com/quasilyte/go-ruleguard/rules v0.0.0-20211022131956-028d6511ab71 github.com/quasilyte/gogrep v0.0.0-20220120141003-628d8b3623b5 + github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 golang.org/x/tools v0.1.9-0.20211228192929-ee1ca4ffc4da ) diff --git a/go.sum b/go.sum index fb667d06..84d076f7 100644 --- a/go.sum +++ b/go.sum @@ -10,19 +10,15 @@ github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/quasilyte/go-ruleguard v0.3.1-0.20210203134552-1b5a410e1cc8/go.mod h1:KsAh3x0e7Fkpgs+Q9pNLS5XpFSvYCEVl5gP9Pp1xp30= github.com/quasilyte/go-ruleguard/dsl v0.3.0/go.mod h1:KeCP03KrjuSO0H1kTuZQCWlQPulDV6YMIXmpQss17rU= -github.com/quasilyte/go-ruleguard/dsl v0.3.13 h1:WmtzUkp28TMarzfBCogPf7plyI/2gsNsj8CgZ9ihPCM= -github.com/quasilyte/go-ruleguard/dsl v0.3.13/go.mod h1:KeCP03KrjuSO0H1kTuZQCWlQPulDV6YMIXmpQss17rU= -github.com/quasilyte/go-ruleguard/dsl v0.3.14 h1:diesHrFHZ6rxuFltuwiW7NRQaqUIypuSSmUulRCNuqM= -github.com/quasilyte/go-ruleguard/dsl v0.3.14/go.mod h1:KeCP03KrjuSO0H1kTuZQCWlQPulDV6YMIXmpQss17rU= github.com/quasilyte/go-ruleguard/dsl v0.3.15 h1:rClYn6lk8wUV5kXnQG4JVsRQjZhSetaNtwml5wkFp5g= github.com/quasilyte/go-ruleguard/dsl v0.3.15/go.mod h1:KeCP03KrjuSO0H1kTuZQCWlQPulDV6YMIXmpQss17rU= github.com/quasilyte/go-ruleguard/rules v0.0.0-20201231183845-9e62ed36efe1/go.mod h1:7JTjp89EGyU1d6XfBiXihJNG37wB2VRkd125Q1u7Plc= github.com/quasilyte/go-ruleguard/rules v0.0.0-20211022131956-028d6511ab71 h1:CNooiryw5aisadVfzneSZPswRWvnVW8hF1bS/vo8ReI= github.com/quasilyte/go-ruleguard/rules v0.0.0-20211022131956-028d6511ab71/go.mod h1:4cgAphtvu7Ftv7vOT2ZOYhC6CvBxZixcasr8qIOTA50= -github.com/quasilyte/gogrep v0.0.0-20220104185649-039753a3dd32 h1:fJhpG5LYGnHZqUIDULZkvQKJfdtAefNrkoiGCezlr7g= -github.com/quasilyte/gogrep v0.0.0-20220104185649-039753a3dd32/go.mod h1:wSEyW6O61xRV6zb6My3HxrQ5/8ke7NE2OayqCHa3xRM= github.com/quasilyte/gogrep v0.0.0-20220120141003-628d8b3623b5 h1:PDWGei+Rf2bBiuZIbZmM20J2ftEy9IeUCHA8HbQqed8= github.com/quasilyte/gogrep v0.0.0-20220120141003-628d8b3623b5/go.mod h1:wSEyW6O61xRV6zb6My3HxrQ5/8ke7NE2OayqCHa3xRM= +github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 h1:M8mH9eK4OUR4lu7Gd+PU1fV2/qnDNfzT635KRSObncs= +github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567/go.mod h1:DWNGW8A4Y+GyBgPuaQJuWiy0XYftx4Xm/y5Jqk9I6VQ= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= diff --git a/internal/stdinfo/stdinfo.go b/internal/stdinfo/stdinfo.go deleted file mode 100644 index f00d66d4..00000000 --- a/internal/stdinfo/stdinfo.go +++ /dev/null @@ -1,151 +0,0 @@ -package stdinfo - -var Packages = map[string]string{ - "adler32": "hash/adler32", - "aes": "crypto/aes", - "ascii85": "encoding/ascii85", - "asn1": "encoding/asn1", - "ast": "go/ast", - "atomic": "sync/atomic", - "base32": "encoding/base32", - "base64": "encoding/base64", - "big": "math/big", - "binary": "encoding/binary", - "bits": "math/bits", - "bufio": "bufio", - "build": "go/build", - "bytes": "bytes", - "bzip2": "compress/bzip2", - "cgi": "net/http/cgi", - "cgo": "runtime/cgo", - "cipher": "crypto/cipher", - "cmplx": "math/cmplx", - "color": "image/color", - "constant": "go/constant", - "constraint": "go/build/constraint", - "context": "context", - "cookiejar": "net/http/cookiejar", - "crc32": "hash/crc32", - "crc64": "hash/crc64", - "crypto": "crypto", - "csv": "encoding/csv", - "debug": "runtime/debug", - "des": "crypto/des", - "doc": "go/doc", - "draw": "image/draw", - "driver": "database/sql/driver", - "dsa": "crypto/dsa", - "dwarf": "debug/dwarf", - "ecdsa": "crypto/ecdsa", - "ed25519": "crypto/ed25519", - "elf": "debug/elf", - "elliptic": "crypto/elliptic", - "embed": "embed", - "encoding": "encoding", - "errors": "errors", - "exec": "os/exec", - "expvar": "expvar", - "fcgi": "net/http/fcgi", - "filepath": "path/filepath", - "flag": "flag", - "flate": "compress/flate", - "fmt": "fmt", - "fnv": "hash/fnv", - "format": "go/format", - "fs": "io/fs", - "fstest": "testing/fstest", - "gif": "image/gif", - "gob": "encoding/gob", - "gosym": "debug/gosym", - "gzip": "compress/gzip", - "hash": "hash", - "heap": "container/heap", - "hex": "encoding/hex", - "hmac": "crypto/hmac", - "html": "html", - "http": "net/http", - "httptest": "net/http/httptest", - "httptrace": "net/http/httptrace", - "httputil": "net/http/httputil", - "image": "image", - "importer": "go/importer", - "io": "io", - "iotest": "testing/iotest", - "ioutil": "io/ioutil", - "jpeg": "image/jpeg", - "json": "encoding/json", - "jsonrpc": "net/rpc/jsonrpc", - "list": "container/list", - "log": "log", - "lzw": "compress/lzw", - "macho": "debug/macho", - "mail": "net/mail", - "maphash": "hash/maphash", - "math": "math", - "md5": "crypto/md5", - "metrics": "runtime/metrics", - "mime": "mime", - "multipart": "mime/multipart", - "net": "net", - "os": "os", - "palette": "image/color/palette", - "parse": "text/template/parse", - "parser": "go/parser", - "path": "path", - "pe": "debug/pe", - "pem": "encoding/pem", - "pkix": "crypto/x509/pkix", - "plan9obj": "debug/plan9obj", - "plugin": "plugin", - "png": "image/png", - "pprof": "runtime/pprof", - "printer": "go/printer", - "quick": "testing/quick", - "quotedprintable": "mime/quotedprintable", - "race": "runtime/race", - "rand": "math/rand", - "rc4": "crypto/rc4", - "reflect": "reflect", - "regexp": "regexp", - "ring": "container/ring", - "rpc": "net/rpc", - "rsa": "crypto/rsa", - "runtime": "runtime", - "scanner": "text/scanner", - "sha1": "crypto/sha1", - "sha256": "crypto/sha256", - "sha512": "crypto/sha512", - "signal": "os/signal", - "smtp": "net/smtp", - "sort": "sort", - "sql": "database/sql", - "strconv": "strconv", - "strings": "strings", - "subtle": "crypto/subtle", - "suffixarray": "index/suffixarray", - "sync": "sync", - "syntax": "regexp/syntax", - "syscall": "syscall", - "syslog": "log/syslog", - "tabwriter": "text/tabwriter", - "tar": "archive/tar", - "template": "text/template", - "testing": "testing", - "textproto": "net/textproto", - "time": "time", - "tls": "crypto/tls", - "token": "go/token", - "trace": "runtime/trace", - "types": "go/types", - "tzdata": "time/tzdata", - "unicode": "unicode", - "unsafe": "unsafe", - "url": "net/url", - "user": "os/user", - "utf16": "unicode/utf16", - "utf8": "unicode/utf8", - "x509": "crypto/x509", - "xml": "encoding/xml", - "zip": "archive/zip", - "zlib": "compress/zlib", -} diff --git a/ruleguard/engine.go b/ruleguard/engine.go index e00706c3..444e8a32 100644 --- a/ruleguard/engine.go +++ b/ruleguard/engine.go @@ -15,10 +15,10 @@ import ( "sync" "github.com/quasilyte/go-ruleguard/internal/goenv" - "github.com/quasilyte/go-ruleguard/internal/stdinfo" "github.com/quasilyte/go-ruleguard/ruleguard/ir" "github.com/quasilyte/go-ruleguard/ruleguard/quasigo" "github.com/quasilyte/go-ruleguard/ruleguard/typematch" + "github.com/quasilyte/stdinfo" ) type engine struct { @@ -64,7 +64,7 @@ func (e *engine) Load(ctx *LoadContext, buildContext *build.Context, filename st pkg: pkg, ctx: ctx, importer: imp, - itab: typematch.NewImportsTab(stdinfo.Packages), + itab: typematch.NewImportsTab(stdinfo.PackagesList), gogrepFset: token.NewFileSet(), } l := newIRLoader(config) @@ -97,7 +97,7 @@ func (e *engine) LoadFromIR(ctx *LoadContext, buildContext *build.Context, filen state: e.state, ctx: ctx, importer: imp, - itab: typematch.NewImportsTab(stdinfo.Packages), + itab: typematch.NewImportsTab(stdinfo.PackagesList), gogrepFset: token.NewFileSet(), } l := newIRLoader(config) diff --git a/ruleguard/typematch/typematch.go b/ruleguard/typematch/typematch.go index 4363e6f0..812b6d96 100644 --- a/ruleguard/typematch/typematch.go +++ b/ruleguard/typematch/typematch.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/quasilyte/go-ruleguard/internal/xtypes" + "github.com/quasilyte/stdinfo" ) //go:generate stringer -type=patternOp @@ -60,8 +61,12 @@ type ImportsTab struct { imports []map[string]string } -func NewImportsTab(initial map[string]string) *ImportsTab { - return &ImportsTab{imports: []map[string]string{initial}} +func NewImportsTab(initial []stdinfo.Package) *ImportsTab { + convertMap := make(map[string]string) + for _, pack := range initial { + convertMap[pack.Name] = pack.Path + } + return &ImportsTab{imports: []map[string]string{convertMap}} } func (itab *ImportsTab) Lookup(pkgName string) (string, bool) { diff --git a/ruleguard/typematch/typematch_test.go b/ruleguard/typematch/typematch_test.go index c616266a..55aa6188 100644 --- a/ruleguard/typematch/typematch_test.go +++ b/ruleguard/typematch/typematch_test.go @@ -5,6 +5,8 @@ import ( "go/types" "path" "testing" + + "github.com/quasilyte/stdinfo" ) var ( @@ -14,6 +16,10 @@ var ( typeUint8 = types.Typ[types.Uint8] typeUnsafePtr = types.Typ[types.UnsafePointer] typeEstruct = types.NewStruct(nil, nil) + packages = [2]stdinfo.Package{ + {Name: "io", Path: "io"}, + {Name: "syntax", Path: "regexp/syntax"}, + } stringerIface = types.NewInterfaceType([]*types.Func{ types.NewFunc(token.NoPos, nil, "String", @@ -26,10 +32,7 @@ var ( stringVar = types.NewVar(token.NoPos, nil, "_", typeString) testContext = &Context{ - Itab: NewImportsTab(map[string]string{ - "io": "io", - "syntax": "regexp/syntax", - }), + Itab: NewImportsTab(packages[:]), } )