MCPcopy Create free account
hub / github.com/bigdra50/unity-cli / run_inspectcode

Function run_inspectcode

scripts/inspect-unity.py:90–137  ·  view source on GitHub ↗

Run jb inspectcode and return (filtered SARIF path, issue count).

(sln_path: Path, output_dir: Path, severity: str)

Source from the content-addressed store, hash-verified

88
89
90def run_inspectcode(sln_path: Path, output_dir: Path, severity: str) -> tuple[Path, int]:
91 """Run jb inspectcode and return (filtered SARIF path, issue count)."""
92 raw_sarif = output_dir / "inspectcode-raw.sarif"
93 filtered_sarif = output_dir / "inspectcode.sarif"
94
95 sln_files = list(TEST_PROJECT.glob("*.sln"))
96 target = sln_files[0] if sln_files else sln_path
97
98 cmd = [
99 "jb",
100 "inspectcode",
101 str(target),
102 "--no-build",
103 "--format=Sarif",
104 f"--severity={severity}",
105 f"--output={raw_sarif}",
106 ]
107 print(f"Running: {' '.join(cmd)}")
108 result = subprocess.run(cmd, capture_output=True, text=True)
109 if result.returncode != 0:
110 print(f"inspectcode failed (exit {result.returncode}):")
111 if result.stderr:
112 print(result.stderr)
113 return filtered_sarif, 0
114
115 if not raw_sarif.exists():
116 print("inspectcode produced no output")
117 return filtered_sarif, 0
118
119 sarif = json.loads(raw_sarif.read_text())
120 total_removed = 0
121 for run in sarif.get("runs", []):
122 results = run.get("results", [])
123 filtered = []
124 for r in results:
125 rule_id = r.get("ruleId", "")
126 if rule_id in EXCLUDED_INSPECTIONS:
127 total_removed += 1
128 continue
129 filtered.append(r)
130 run["results"] = filtered
131
132 filtered_sarif.write_text(json.dumps(sarif, indent=2, ensure_ascii=False))
133 if total_removed:
134 print(f"Excluded {total_removed} InconsistentNaming issue(s)")
135
136 issue_count = sum(len(run.get("results", [])) for run in sarif.get("runs", []))
137 return filtered_sarif, issue_count
138
139
140def print_inspect_summary(sarif_path: Path) -> None:

Callers 1

mainFunction · 0.85

Calls 2

runMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected