Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gagliardetto/cqlgen
cqlgen is a code generator for GitHub's CodeQL. WARNING: this is a WIP.
https://github.com/gagliardetto/cqlgen
Last synced: 3 months ago
JSON representation
cqlgen is a code generator for GitHub's CodeQL. WARNING: this is a WIP.
- Host: GitHub
- URL: https://github.com/gagliardetto/cqlgen
- Owner: gagliardetto
- License: mit
- Created: 2020-11-26T18:29:37.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-02T20:41:10.000Z (almost 4 years ago)
- Last Synced: 2024-06-21T18:56:32.698Z (6 months ago)
- Language: Go
- Homepage:
- Size: 445 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cqlgen
cqlgen is a code generator for CodeQL, based and converted from the awesome [Jennifer](https://github.com/dave/jennifer) Go code generation library.## Examples
See https://github.com/gagliardetto/cqlgen/blob/main/examples/main.go for a general example.
You can find other examples in [/examples/other/go](/examples/other/go).
## Requirements
To allow cqlgen to format the generated codeql, you need a recent version of the [codeql cli](https://github.com/github/codeql-cli-binaries/releases) (otherwise it will not be formatted), and have it available as `codeql` in your PATH.
## Basic example
Here is an example:
```go
package mainimport (
"os". "github.com/gagliardetto/cqlgen/jen"
)// https://github.com/github/codeql-go/blob/main/ql/examples/snippets/calltobuiltin.ql
func main() {
file := NewFile()
file.HeaderDoc("@name Call to built-in function")
file.HeaderDoc("@description Finds calls to the built-in `len` function.")
file.HeaderDoc("@id go/examples/calltolen")
file.HeaderDoc("@tags call")
file.HeaderDoc(" function")
file.HeaderDoc(" len")
file.HeaderDoc(" built-in")file.Import("go")
file.From(
Qual("DataFlow", "CallNode").Id("call"),
)file.Where(DoGroup(func(gr *Group) {
gr.Id("call").Eq().Qual("Builtin", "len").Call().Dot("getACall").Call()
}))
file.Select(Id("call"))file.Render(os.Stdout)
}
```The above example will generate the below codeql code:
```codeql
/**
* @name Call to built-in function
* @description Finds calls to the built-in `len` function.
* @id go/examples/calltolen
* @tags call
* function
* len
* built-in
*/import go
from DataFlow::CallNode call
where call = Builtin::len().getACall()
select call
```