diff --git a/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.expected b/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.expected deleted file mode 100644 index e13af31a9db..00000000000 --- a/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.expected +++ /dev/null @@ -1,2 +0,0 @@ -| go.mod:10:1:10:44 | go.mod exclude line | codeql-go-tests/gomod | github.com/github/codeql-go | v1.23.1 | -| go.mod:23:1:23:42 | go.mod exclude line | codeql-go-tests/gomod | github.com/sirupsen/logrus | v1.4.2 | diff --git a/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.ql b/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.ql deleted file mode 100644 index f469a5d5b21..00000000000 --- a/ql/test/library-tests/semmle/go/GoModExpr/ExcludeLines.ql +++ /dev/null @@ -1,4 +0,0 @@ -import go - -from GoModExcludeLine excl -select excl, excl.getModulePath(), excl.getPath(), excl.getVersion() diff --git a/ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.expected b/ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.expected new file mode 100644 index 00000000000..4ebf86ed075 --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.expected @@ -0,0 +1,3 @@ +missingRequire +missingExclude +missingReplace diff --git a/ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.ql b/ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.ql new file mode 100644 index 00000000000..cab5795037e --- /dev/null +++ b/ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.ql @@ -0,0 +1,88 @@ +import go + +/** + * Holds if there exists a comment on the same line as `l` + * that contains the substring "`kind`,`dep`,`ver`". + */ +predicate metadata(Locatable l, string kind, string mod, string dep, string ver) { + exists(string f, int line, Comment c, string text | + l.hasLocationInfo(f, line, _, _, _) and + c.hasLocationInfo(f, line, _, _, _) + | + text = c.getText().regexpFind("\\b([^,\\s]+,[^,]+,[^,]+,[^,\\s]+)", _, _) and + kind = text.regexpCapture("([^,]+),([^,]+),([^,]+),([^,]+)", 1) and + mod = text.regexpCapture("([^,]+),([^,]+),([^,]+),([^,]+)", 2) and + dep = text.regexpCapture("([^,]+),([^,]+),([^,]+),([^,]+)", 3) and + ver = text.regexpCapture("([^,]+),([^,]+),([^,]+),([^,]+)", 4) + ) +} + +query predicate missingRequire(string mod, string dep, string ver, int line) { + exists(Locatable l | metadata(l, "RequireLine", mod, dep, ver) | + l.hasLocationInfo(_, line, _, _, _) + ) and + not exists(GoModRequireLine req | + req.getModulePath() = mod and + req.getPath() = dep and + req.getVersion() = ver and + metadata(req, "RequireLine", mod, dep, ver) and + req.hasLocationInfo(_, line, _, _, _) + ) +} + +query predicate missingExclude(string mod, string dep, string ver, int line) { + exists(Locatable l | metadata(l, "ExcludeLine", mod, dep, ver) | + l.hasLocationInfo(_, line, _, _, _) + ) and + not exists(GoModExcludeLine exc | + exc.getModulePath() = mod and + exc.getPath() = dep and + exc.getVersion() = ver and + metadata(exc, "ExcludeLine", mod, dep, ver) and + exc.hasLocationInfo(_, line, _, _, _) + ) +} + +/** + * Holds if there exists a comment on the same line as `l` + * that contains the substring "ReplaceLine,`mod`,`dep`,`dver`,`rep`,`rver`". + */ +predicate repmetadata(Locatable l, string mod, string dep, string dver, string rep, string rver) { + exists(string f, int line, Comment c, string text | + l.hasLocationInfo(f, line, _, _, _) and + c.hasLocationInfo(f, line, _, _, _) + | + text = c.getText().regexpFind("\\b(ReplaceLine,[^,]*,[^,]*,[^,]*,[^,]*,[^,\\s]*)", _, _) and + mod = text.regexpCapture("ReplaceLine,([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)", 1) and + dep = text.regexpCapture("ReplaceLine,([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)", 2) and + dver = text.regexpCapture("ReplaceLine,([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)", 3) and + rep = text.regexpCapture("ReplaceLine,([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)", 4) and + rver = text.regexpCapture("ReplaceLine,([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)", 5) + ) +} + +query predicate missingReplace(string mod, string dep, string dver, string rep, string rver, int line) { + exists(Locatable l | repmetadata(l, mod, dep, dver, rep, rver) | + l.hasLocationInfo(_, line, _, _, _) + ) and + not exists(GoModReplaceLine repl | + ( + rver = repl.getReplacementVersion() + or + not exists(repl.getReplacementVersion()) and + rver = "" + ) and + ( + dver = repl.getOriginalVersion() + or + not exists(repl.getOriginalVersion()) and + dver = "" + ) + | + repl.getModulePath() = mod and + repl.getOriginalPath() = dep and + repl.getReplacementPath() = rep and + repmetadata(repl, mod, dep, dver, rep, rver) and + repl.hasLocationInfo(_, line, _, _, _) + ) +} diff --git a/ql/test/library-tests/semmle/go/GoModExpr/ReplaceLines.expected b/ql/test/library-tests/semmle/go/GoModExpr/ReplaceLines.expected deleted file mode 100644 index d9b887e7500..00000000000 --- a/ql/test/library-tests/semmle/go/GoModExpr/ReplaceLines.expected +++ /dev/null @@ -1,2 +0,0 @@ -| go.mod:12:1:12:54 | go.mod replace line | codeql-go-tests/gomod | github.com/Masterminds/squirrel | no version | ./squirrel | no version | -| go.mod:14:1:14:79 | go.mod replace line | codeql-go-tests/gomod | github.com/Sirupsen/logrus | v1.4.1 | github.com/sirupsen/logrus | v1.4.1 | diff --git a/ql/test/library-tests/semmle/go/GoModExpr/ReplaceLines.ql b/ql/test/library-tests/semmle/go/GoModExpr/ReplaceLines.ql deleted file mode 100644 index 485a7c69c44..00000000000 --- a/ql/test/library-tests/semmle/go/GoModExpr/ReplaceLines.ql +++ /dev/null @@ -1,18 +0,0 @@ -import go - -from GoModReplaceLine repl, string origVersion, string repVersion -where - ( - repVersion = repl.getReplacementVersion() - or - not exists(repl.getReplacementVersion()) and - repVersion = "no version" - ) and - ( - origVersion = repl.getOriginalVersion() - or - not exists(repl.getOriginalVersion()) and - origVersion = "no version" - ) -select repl, repl.getModulePath(), repl.getOriginalPath(), origVersion, repl.getReplacementPath(), - repVersion diff --git a/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.expected b/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.expected deleted file mode 100644 index ec8893e251e..00000000000 --- a/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.expected +++ /dev/null @@ -1,5 +0,0 @@ -| go.mod:6:2:6:67 | go.mod require line | codeql-go-tests/gomod | github.com/github/codeql-go | v1.23.2-0.20200302182241-5e71a04fdf30 | -| go.mod:7:2:7:55 | go.mod require line | codeql-go-tests/gomod | golang.org/x/tools | v0.0.0-20200109174759-ac4f524c1612 | -| go.mod:16:1:16:38 | go.mod require line | codeql-go-tests/gomod | github.com/gorilla/mux | v1.7.4 | -| go.mod:19:2:19:40 | go.mod require line | codeql-go-tests/gomod | github.com/Masterminds/squirrel | v1.2.0 | -| go.mod:20:2:20:35 | go.mod require line | codeql-go-tests/gomod | github.com/Sirupsen/logrus | v1.4.1 | diff --git a/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.ql b/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.ql deleted file mode 100644 index d3c1ebf3e75..00000000000 --- a/ql/test/library-tests/semmle/go/GoModExpr/RequireLines.ql +++ /dev/null @@ -1,4 +0,0 @@ -import go - -from GoModRequireLine req -select req, req.getModulePath(), req.getPath(), req.getVersion() diff --git a/ql/test/library-tests/semmle/go/GoModExpr/go.mod b/ql/test/library-tests/semmle/go/GoModExpr/go.mod index efae10e53cd..097a4f3ce2e 100644 --- a/ql/test/library-tests/semmle/go/GoModExpr/go.mod +++ b/ql/test/library-tests/semmle/go/GoModExpr/go.mod @@ -3,21 +3,21 @@ module codeql-go-tests/gomod go 1.14 require ( - github.com/github/codeql-go v1.23.2-0.20200302182241-5e71a04fdf30 // indirect - golang.org/x/tools v0.0.0-20200109174759-ac4f524c1612 // indirect + github.com/github/codeql-go v1.23.2-0.20200302182241-5e71a04fdf30 // indirect RequireLine,codeql-go-tests/gomod,github.com/github/codeql-go,v1.23.2-0.20200302182241-5e71a04fdf30 + golang.org/x/tools v0.0.0-20200109174759-ac4f524c1612 // indirect RequireLine,codeql-go-tests/gomod,golang.org/x/tools,v0.0.0-20200109174759-ac4f524c1612 ) -exclude github.com/github/codeql-go v1.23.1 +exclude github.com/github/codeql-go v1.23.1 // ExcludeLine,codeql-go-tests/gomod,github.com/github/codeql-go,v1.23.1 -replace github.com/Masterminds/squirrel => ./squirrel +replace github.com/Masterminds/squirrel => ./squirrel // ReplaceLine,codeql-go-tests/gomod,github.com/Masterminds/squirrel,,./squirrel, -replace github.com/Sirupsen/logrus v1.4.1 => github.com/sirupsen/logrus v1.4.1 +replace github.com/Sirupsen/logrus v1.4.1 => github.com/sirupsen/logrus v1.4.1 // ReplaceLine,codeql-go-tests/gomod,github.com/Sirupsen/logrus,v1.4.1,github.com/sirupsen/logrus,v1.4.1 -require github.com/gorilla/mux v1.7.4 // indirect +require github.com/gorilla/mux v1.7.4 // indirect RequireLine,codeql-go-tests/gomod,github.com/gorilla/mux,v1.7.4 require ( - github.com/Masterminds/squirrel v1.2.0 // indirect - github.com/Sirupsen/logrus v1.4.1 // indirect + github.com/Masterminds/squirrel v1.2.0 // indirect RequireLine,codeql-go-tests/gomod,github.com/Masterminds/squirrel,v1.2.0 + github.com/Sirupsen/logrus v1.4.1 // indirect RequireLine,codeql-go-tests/gomod,github.com/Sirupsen/logrus,v1.4.1 ) -exclude github.com/sirupsen/logrus v1.4.2 +exclude github.com/sirupsen/logrus v1.4.2 // ExcludeLine,codeql-go-tests/gomod,github.com/sirupsen/logrus,v1.4.2