
## Build the project

You need to have all the necessary [tree-sitter](https://github.com/tree-sitter) repositories
in `kernel` for the analysis to work. The `build` process will take care of this for you:

```shell
cargo build --profile release-dev
```
> [!TIP]
> The use of the `release-dev` cargo profile is highly recommended, as runtime analysis speed is effectively
> the same as `release` mode, but compile times are comparable to `debug` mode.

## Analyze a directory

```shell

cargo run --profile release-dev --bin datadog-static-analyzer -- --directory <SOURCE> --output result.json --format sarif --debug yes
```

## Start a local server

```shell
cargo run --profile release-dev --bin datadog-static-analyzer-server -- --port <server-port> -a <server-address>
```

## Run tests

Run all tests

```shell
cargo test
```


## Test a ruleset

```shell
cargo run --bin datadog-static-analyzer-test-ruleset -- -r <ruleset-name>1
```


## Run tests with output

```shell
cargo test -- --nocapture
```


## Test a request to the server

First, start the server using

```shell
cargo run --profile release-dev --bin datadog-static-analyzer-server
```


### Get an analysis request
```shell

curl -X POST \
     -H "Content-Type: application/json" \
     --data '{
        "filename": "myfile.py",
        "file_encoding": "utf-8",
        "language": "PYTHON",
        "code": "ZGVmIGZvbyhhcmcxKToKICAgIHBhc3M=",
        "rules": [
          {
              "id": "myrule",
              "short_description": "",
              "description": "",
              "language": "PYTHON",
              "type": "TREE_SITTER_QUERY",
              "entity_checked": null,
              "code": " ",
              "tree_sitter_query": "KGZ1bmN0aW9uX2RlZmluaXRpb24KICAgIG5hbWU6IChpZGVudGlmaWVyKSBAbmFtZQogIHBhcmFtZXRlcnM6IChwYXJhbWV0ZXJzKSBAcGFyYW1zCik="
          }
        ]
     }' \
     http://localhost:8000/analyze
```

### Get the AST Tree

```shell
curl -X POST \
-H "Content-Type: application/json" \
--data '{
"file_encoding": "utf-8",
"language": "PYTHON",
"code": "ZGVmIGZvbyhhcmcxKToKICAgIHBhc3M="
}' \
http://localhost:8000/get-treesitter-ast
```
