Skip to content

Commit 0166f73

Browse files
committed
Add a metric to record how many interface fields are resolved
1 parent 2f2de99 commit 0166f73

9 files changed

+250
-10
lines changed

semgrep_metrics.atd

+20
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ type parse_stat = {
146146
num_bytes <ocaml mutable>: int;
147147
}
148148

149+
(*****************************************************************************)
150+
(* Pro Naming stats *)
151+
(*****************************************************************************)
152+
153+
type pro_naming_stat = {
154+
(* The number of interface fields resolved during the Naming_SAST phases.
155+
* This is the total count from the naming resolution of all field accesses
156+
* in the input source code.
157+
* Since semgrep 1.93
158+
*)
159+
?numInterfaceVarResolved <ocaml mutable>: int option;
160+
?numInterfaceMethodResolved <ocaml mutable>: int option;
161+
}
162+
149163
(*****************************************************************************)
150164
(* Errors *)
151165
(*****************************************************************************)
@@ -204,13 +218,19 @@ type pro_features = {
204218
* Since semgrep 1.46
205219
*)
206220
?diffDepth <ocaml mutable>: int option;
221+
207222
(* The number of scanned files per language for inter-file diff scan mode.
208223
* This number represents the count of changed files and their limited
209224
* dependencies.
210225
* Since semgrep 1.70
211226
*)
212227
?numInterfileDiffScanned <ocaml mutable>: (string (* lang *) * int) list
213228
<json repr="object"> option;
229+
230+
(* The naming and typing metrics.
231+
* Since semgrep 1.93
232+
*)
233+
?proNamingStat <ocaml mutable>: pro_naming_stat option;
214234
}
215235

216236
(* Since v1.55.0 *)

semgrep_metrics.py

+37
Original file line numberDiff line numberDiff line change
@@ -405,19 +405,54 @@ def to_json_string(self, **kw: Any) -> str:
405405
return json.dumps(self.to_json(), **kw)
406406

407407

408+
@dataclass
409+
class ProNamingStat:
410+
"""Original type: pro_naming_stat = { ... }"""
411+
412+
numInterfaceVarResolved: Optional[int] = None
413+
numInterfaceMethodResolved: Optional[int] = None
414+
415+
@classmethod
416+
def from_json(cls, x: Any) -> 'ProNamingStat':
417+
if isinstance(x, dict):
418+
return cls(
419+
numInterfaceVarResolved=_atd_read_int(x['numInterfaceVarResolved']) if 'numInterfaceVarResolved' in x else None,
420+
numInterfaceMethodResolved=_atd_read_int(x['numInterfaceMethodResolved']) if 'numInterfaceMethodResolved' in x else None,
421+
)
422+
else:
423+
_atd_bad_json('ProNamingStat', x)
424+
425+
def to_json(self) -> Any:
426+
res: Dict[str, Any] = {}
427+
if self.numInterfaceVarResolved is not None:
428+
res['numInterfaceVarResolved'] = _atd_write_int(self.numInterfaceVarResolved)
429+
if self.numInterfaceMethodResolved is not None:
430+
res['numInterfaceMethodResolved'] = _atd_write_int(self.numInterfaceMethodResolved)
431+
return res
432+
433+
@classmethod
434+
def from_json_string(cls, x: str) -> 'ProNamingStat':
435+
return cls.from_json(json.loads(x))
436+
437+
def to_json_string(self, **kw: Any) -> str:
438+
return json.dumps(self.to_json(), **kw)
439+
440+
408441
@dataclass
409442
class ProFeatures:
410443
"""Original type: pro_features = { ... }"""
411444

412445
diffDepth: Optional[int] = None
413446
numInterfileDiffScanned: Optional[List[Tuple[str, int]]] = None
447+
proNamingStat: Optional[ProNamingStat] = None
414448

415449
@classmethod
416450
def from_json(cls, x: Any) -> 'ProFeatures':
417451
if isinstance(x, dict):
418452
return cls(
419453
diffDepth=_atd_read_int(x['diffDepth']) if 'diffDepth' in x else None,
420454
numInterfileDiffScanned=_atd_read_assoc_object_into_list(_atd_read_int)(x['numInterfileDiffScanned']) if 'numInterfileDiffScanned' in x else None,
455+
proNamingStat=ProNamingStat.from_json(x['proNamingStat']) if 'proNamingStat' in x else None,
421456
)
422457
else:
423458
_atd_bad_json('ProFeatures', x)
@@ -428,6 +463,8 @@ def to_json(self) -> Any:
428463
res['diffDepth'] = _atd_write_int(self.diffDepth)
429464
if self.numInterfileDiffScanned is not None:
430465
res['numInterfileDiffScanned'] = _atd_write_assoc_list_to_object(_atd_write_int)(self.numInterfileDiffScanned)
466+
if self.proNamingStat is not None:
467+
res['proNamingStat'] = (lambda x: x.to_json())(self.proNamingStat)
431468
return res
432469

433470
@classmethod

semgrep_output_v1.atd

+3
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,9 @@ type cli_output_extra = {
868868

869869
(* EXPERIMENTAL: since: 1.37.0 *)
870870
~skipped_rules: skipped_rule list;
871+
872+
(* EXPERIMENTAL: since: 1.91.0 *)
873+
?extra_extra: raw_json option;
871874
}
872875

873876
(*****************************************************************************)

semgrep_output_v1.jsonschema

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

semgrep_output_v1.proto

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

semgrep_output_v1.py

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

semgrep_output_v1.ts

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

0 commit comments

Comments
 (0)