Skip to content

Commit b54e43b

Browse files
authored
simplify the RPC for SARIF (#336)
The goal is to make it as close as possible as the general CallFormat so at some point we can merge them. test plan: see related PR in semgrep - [x] I ran `make setup && make` to update the generated code after editing a `.atd` file (TODO: have a CI check) - [x] I made sure we're still backward compatible with old versions of the CLI. For example, the Semgrep backend need to still be able to *consume* data generated by Semgrep 1.50.0. See https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades Note that the types related to the semgrep-core JSON output or the semgrep-core RPC do not need to be backward compatible! Co-authored-by: pad <[email protected]>
1 parent aec607b commit b54e43b

7 files changed

+6240
-6658
lines changed

semgrep_output_v1.atd

+9-29
Original file line numberDiff line numberDiff line change
@@ -1939,35 +1939,15 @@ type apply_fixes_return <python decorator="dataclass(frozen=True)"> = {
19391939
fixed_lines: (int * string list) list;
19401940
}
19411941

1942-
(* TODO: remove many fields so that CallSarifFormat gets close to CallFormatter.
1943-
* I think we just need the 'rules: fpath' as it can't be reconstructed
1944-
* from cli_output.
1945-
*)
1946-
type sarif_format_params <python decorator="dataclass(frozen=True)"> = {
1947-
(* Path the the rules file *)
1942+
type sarif_format <python decorator="dataclass(frozen=True)"> = {
1943+
(* Path to the rules file. We need it because rules can't be reconstructed
1944+
* from cli_output (which is one of the other param of CallSarifFormat) *)
19481945
rules: fpath;
1949-
1950-
(* TODO: remove, just use cli_output *)
1951-
cli_matches: cli_match list;
1952-
cli_errors: cli_error list;
1953-
(* TODO: remove, should be able to derive those from format_context *)
1954-
hide_nudge: bool;
1955-
engine_label: string;
1946+
(* TODO? move to format_context? *)
1947+
is_pro: bool;
19561948
show_dataflow_traces: bool;
19571949
}
19581950

1959-
(* TODO: remove, reuse RetFormatter *)
1960-
type sarif_format_return <python decorator="dataclass(frozen=True)"> = {
1961-
(* The formatted output. *)
1962-
output: string;
1963-
(* Time (in seconds) it took to format the output.
1964-
* This helps tracking how much actual formatting time is needed
1965-
* compared to the whole RPC call, so we can profile and improve
1966-
* performace when needed.
1967-
*)
1968-
format_time_seconds: float;
1969-
}
1970-
19711951
type output_format
19721952
<ocaml attr="deriving show">
19731953
<python decorator="dataclass(frozen=True)"> =
@@ -2148,9 +2128,9 @@ type resolution_result = [
21482128
type function_call <python decorator="dataclass(frozen=True)"> = [
21492129
| CallContributions
21502130
| CallApplyFixes of apply_fixes_params
2151-
(* TODO: merge with CallFormatter at some point *)
2152-
| CallSarifFormat of (format_context * sarif_format_params)
21532131
| CallFormatter of (output_format * format_context * cli_output)
2132+
(* TODO: merge with CallFormatter at some point *)
2133+
| CallSarifFormat of (sarif_format * format_context * cli_output)
21542134
(* NOTE: fpath is most likely a temporary file that contains all the rules in
21552135
JSON format. In the future, we could send the rules via a big string through
21562136
the RPC pipe.
@@ -2168,9 +2148,9 @@ type function_return <python decorator="dataclass(frozen=True)"> = [
21682148
| RetError of string
21692149
| RetApplyFixes of apply_fixes_return
21702150
| RetContributions of contributions
2171-
(* TODO: remove and use RetFormatter for the return of CallSarifFormat too *)
2172-
| RetSarifFormat of sarif_format_return
21732151
| RetFormatter of string
2152+
(* alt: reuse RetFormatter *)
2153+
| RetSarifFormat of string
21742154
| RetValidate of bool
21752155
| RetResolveDependencies of (dependency_source * resolution_result) list
21762156
| RetDumpRulePartitions of bool

semgrep_output_v1.jsonschema

+11-31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

semgrep_output_v1.proto

+3-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)