Skip to content

Fix SonarCloud and Codacy findings#122

Merged
JE-Chen merged 2 commits intodevfrom
fix/sonarcloud-codacy-issues
Apr 24, 2026
Merged

Fix SonarCloud and Codacy findings#122
JE-Chen merged 2 commits intodevfrom
fix/sonarcloud-codacy-issues

Conversation

@JE-Chen
Copy link
Copy Markdown
Member

@JE-Chen JE-Chen commented Apr 24, 2026

Summary

  • Resolve all 25 open SonarCloud code issues (complexity, duplicate literals, unused code, identity/equality checks, naming, literal-constructor, commented code).
  • Fix the 3 ReDoS hotspots (S5852) in the mermaid parser by bounding the non-greedy label captures; the remaining S5332 http literal is annotated as a scheme-detection check (actual fetch goes through the existing SSRF-validated safe_download_image).
  • Address Codacy real findings: unused imports, silent try/except/continue now logs, free-port probe binds to 127.0.0.1, Sphinx copyright gets # noqa: A001.
  • Suppress Codacy/Bandit/Semgrep false positives via [tool.bandit] (excludes test/, skips B101/B404) and per-callsite # nosec / # nosemgrep annotations with rationale on every intentional subprocess spawn and the plugin-registry import_module call.

Test plan

  • python -m pytest test/test_utils/ -v — 49 passed
  • python -m ruff check pybreeze/ — clean
  • Let SonarCloud + Codacy rescan this branch on CI to confirm issues close
  • After rescan, mark the 4 hotspots (AZ2SNbLpqLdx4W_f2Svm/n/o, AZ2SNbLQqLdx4W_f2Svl) as Reviewed: Safe in the Sonar UI if they don't auto-resolve

Addresses all 25 open SonarCloud code issues and the corresponding
Codacy findings:

- Reduce cognitive complexity (S3776) by extracting helpers in
  diagram_mermaid_parser, diagram_scene, build_plugin_menu,
  ssh_command_widget, ssh_file_viewer_widget, and both pull_text methods.
- Extract duplicate literals (S1192) in i18n dicts.
- Bound regex quantifiers in the mermaid parser to prevent ReDoS (S5852).
- Remove unused variable nw (S1481), redundant list() calls (S7504),
  commented code (S125), always-True identity check (S5727).
- Rename KeyType -> key_cls (S117); list() -> [] (S7498);
  dict comprehension -> dict.fromkeys (S7519).
- Log rejected SSH key types instead of silent continue (Bandit B112).
- Bind free-port probe socket to 127.0.0.1 (Semgrep bind-all-interfaces).
- Remove unused pytest/sys/Path imports.
- Add [tool.bandit] in pyproject.toml to skip B101/B404 and exclude tests.
- Annotate intentional subprocess callsites with # nosec and rationale.
- Annotate scheme-detection http literal and SSRF-validated urlopen.
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 24, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics -4 complexity · 0 duplication

Metric Results
Complexity -4
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Addresses PR #122 follow-up findings:

- Sonar S7519: use dict.fromkeys in _assign_layers.
- Codacy duplication gate (new-code 4.8% > 3%): extract load_private_key
  to ssh_key_loader.py (used by both ssh_command_widget and
  ssh_file_viewer_widget) and pump_message_queue to queue_pump.py (used
  by both python_task_process_manager and test_pioneer_process_manager).
- Add # nosemgrep alongside # nosec on every intentional subprocess
  callsite so Semgrep's dangerous-subprocess/spawn-process/non-literal
  rules stop firing.
@sonarqubecloud
Copy link
Copy Markdown

@JE-Chen JE-Chen merged commit a920d08 into dev Apr 24, 2026
5 checks passed
@JE-Chen JE-Chen mentioned this pull request Apr 24, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant