Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a metric to record how many interface fields are resolved #294

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions semgrep_metrics.atd
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ type parse_stat = {
num_bytes <ocaml mutable>: int;
}

(*****************************************************************************)
(* Pro Naming stats *)
(*****************************************************************************)

type pro_naming_stat = {
(* The number of interface fields resolved during the Naming_SAST phases.
* This is the total count from the naming resolution of all field accesses
* in the input source code.
* Since semgrep 1.93
*)
?numInterfaceVarResolved <ocaml mutable>: int option;
?numInterfaceMethodResolved <ocaml mutable>: int option;
}

(*****************************************************************************)
(* Errors *)
(*****************************************************************************)
Expand Down Expand Up @@ -204,13 +218,19 @@ type pro_features = {
* Since semgrep 1.46
*)
?diffDepth <ocaml mutable>: int option;

(* The number of scanned files per language for inter-file diff scan mode.
* This number represents the count of changed files and their limited
* dependencies.
* Since semgrep 1.70
*)
?numInterfileDiffScanned <ocaml mutable>: (string (* lang *) * int) list
<json repr="object"> option;

(* The naming and typing metrics.
* Since semgrep 1.93
*)
?proNamingStat <ocaml mutable>: pro_naming_stat option;
}

(* Since v1.55.0 *)
Expand Down
37 changes: 37 additions & 0 deletions semgrep_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,19 +405,54 @@ def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)


@dataclass
class ProNamingStat:
"""Original type: pro_naming_stat = { ... }"""

numInterfaceVarResolved: Optional[int] = None
numInterfaceMethodResolved: Optional[int] = None

@classmethod
def from_json(cls, x: Any) -> 'ProNamingStat':
if isinstance(x, dict):
return cls(
numInterfaceVarResolved=_atd_read_int(x['numInterfaceVarResolved']) if 'numInterfaceVarResolved' in x else None,
numInterfaceMethodResolved=_atd_read_int(x['numInterfaceMethodResolved']) if 'numInterfaceMethodResolved' in x else None,
)
else:
_atd_bad_json('ProNamingStat', x)

def to_json(self) -> Any:
res: Dict[str, Any] = {}
if self.numInterfaceVarResolved is not None:
res['numInterfaceVarResolved'] = _atd_write_int(self.numInterfaceVarResolved)
if self.numInterfaceMethodResolved is not None:
res['numInterfaceMethodResolved'] = _atd_write_int(self.numInterfaceMethodResolved)
return res

@classmethod
def from_json_string(cls, x: str) -> 'ProNamingStat':
return cls.from_json(json.loads(x))

def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)


@dataclass
class ProFeatures:
"""Original type: pro_features = { ... }"""

diffDepth: Optional[int] = None
numInterfileDiffScanned: Optional[List[Tuple[str, int]]] = None
proNamingStat: Optional[ProNamingStat] = None

@classmethod
def from_json(cls, x: Any) -> 'ProFeatures':
if isinstance(x, dict):
return cls(
diffDepth=_atd_read_int(x['diffDepth']) if 'diffDepth' in x else None,
numInterfileDiffScanned=_atd_read_assoc_object_into_list(_atd_read_int)(x['numInterfileDiffScanned']) if 'numInterfileDiffScanned' in x else None,
proNamingStat=ProNamingStat.from_json(x['proNamingStat']) if 'proNamingStat' in x else None,
)
else:
_atd_bad_json('ProFeatures', x)
Expand All @@ -428,6 +463,8 @@ def to_json(self) -> Any:
res['diffDepth'] = _atd_write_int(self.diffDepth)
if self.numInterfileDiffScanned is not None:
res['numInterfileDiffScanned'] = _atd_write_assoc_list_to_object(_atd_write_int)(self.numInterfileDiffScanned)
if self.proNamingStat is not None:
res['proNamingStat'] = (lambda x: x.to_json())(self.proNamingStat)
return res

@classmethod
Expand Down
3 changes: 3 additions & 0 deletions semgrep_output_v1.atd
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@ type cli_output_extra = {

(* EXPERIMENTAL: since: 1.37.0 *)
~skipped_rules: skipped_rule list;

(* EXPERIMENTAL: since: 1.91.0 *)
?extra_extra: raw_json option;
}

(*****************************************************************************)
Expand Down
9 changes: 6 additions & 3 deletions semgrep_output_v1.jsonschema

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion semgrep_output_v1.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions semgrep_output_v1.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions semgrep_output_v1.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading