()
| 230 | |
| 231 | |
| 232 | def main() -> None: |
| 233 | parser = argparse.ArgumentParser(description="Run static analysis on Unity C# code") |
| 234 | parser.add_argument( |
| 235 | "--only", |
| 236 | choices=["inspect", "similarity"], |
| 237 | help="Run only the specified tool", |
| 238 | ) |
| 239 | parser.add_argument( |
| 240 | "--severity", |
| 241 | default="WARNING", |
| 242 | help="inspectcode severity threshold (default: WARNING)", |
| 243 | ) |
| 244 | parser.add_argument( |
| 245 | "--threshold", |
| 246 | type=float, |
| 247 | default=0.87, |
| 248 | help="similarity-csharp threshold (default: 0.87)", |
| 249 | ) |
| 250 | parser.add_argument( |
| 251 | "--output-dir", |
| 252 | type=Path, |
| 253 | help="Report output directory (default: /tmp)", |
| 254 | ) |
| 255 | parser.add_argument( |
| 256 | "--keep-sln", |
| 257 | action="store_true", |
| 258 | help="Keep generated .sln after analysis", |
| 259 | ) |
| 260 | args = parser.parse_args() |
| 261 | |
| 262 | run_inspect = args.only in (None, "inspect") |
| 263 | run_sim = args.only in (None, "similarity") |
| 264 | |
| 265 | if not ensure_tools(run_inspect, run_sim): |
| 266 | sys.exit(1) |
| 267 | |
| 268 | output_dir: Path = args.output_dir or Path(tempfile.gettempdir()) |
| 269 | output_dir.mkdir(parents=True, exist_ok=True) |
| 270 | |
| 271 | generated_sln = False |
| 272 | sln_path: Path | None = None |
| 273 | if run_inspect and not sln_exists(): |
| 274 | if not find_csproj_files(): |
| 275 | print("No .csproj files found in TestProject/. Open the project in Unity first.") |
| 276 | sys.exit(1) |
| 277 | sln_path = generate_sln() |
| 278 | generated_sln = True |
| 279 | |
| 280 | has_issues = False |
| 281 | |
| 282 | if run_inspect: |
| 283 | print("\n── inspectcode ──") |
| 284 | sarif_path, issue_count = run_inspectcode(sln_path or TEST_PROJECT, output_dir, args.severity) |
| 285 | print(f"\nInspectCode results ({sarif_path}):") |
| 286 | print_inspect_summary(sarif_path) |
| 287 | if issue_count > 0: |
| 288 | has_issues = True |
| 289 |
no test coverage detected