Skip to content

feat(backend): add static analysis rule for unreachable python code#370

Open
DeepeshKafalatiya wants to merge 9 commits into
imDarshanGK:mainfrom
DeepeshKafalatiya:feat/unreachable-code-rule
Open

feat(backend): add static analysis rule for unreachable python code#370
DeepeshKafalatiya wants to merge 9 commits into
imDarshanGK:mainfrom
DeepeshKafalatiya:feat/unreachable-code-rule

Conversation

@DeepeshKafalatiya
Copy link
Copy Markdown

Description

This PR implements a native, lightweight static analysis rule using Python's ast (Abstract Syntax Tree) module to detect unreachable/dead code blocks. Specifically, it flags any non-empty code lines that occur directly after terminating structural keywords (return, break, continue) within the same scope.

The rule logic has been successfully integrated into both primary analysis endpoints:

  1. Single file analysis (POST /analyze/) — appends to the payload["debugging"]["issues"] structure.
  2. ZIP archive analysis (POST /analyze/zip/) — safely handles individual file dictionaries with a solid key-fallback structure.

Related Issue

Fixes #328

Type of change

  • Bug fix
  • New feature / enhancement
  • Documentation update
  • Test addition
  • Refactor

Checklist

  • I have read CONTRIBUTING.md
  • My branch is up to date with main
  • I have run pytest -v and all tests pass
  • I have not introduced duplicate issues or features
  • My PR title follows the format: feat/fix/docs/test: short description
  • I have added tests for new features (Level 2 and 3 issues)
  • No hardcoded secrets or API keys in my code
  • This PR is linked to a GSSoC 2026 issue

Screenshots (if frontend change)

N/A (Backend change verified locally via Swagger UI docs platform)

Test evidence

# Handled manual request schema validation using /docs interface
# Sample payload tested successfully:
# def test():
        return 5
        print("Dead code") -> Correctly flagged with type: 'UnreachableCode'

@DeepeshKafalatiya
Copy link
Copy Markdown
Author

DeepeshKafalatiya commented May 26, 2026

Hi maintainers!
@imDarshanGK

I have successfully implemented the UnreachableCodeDetector logic using Python's native ast parser and verified it locally using the Swagger UI docs interface.

Please review my changes and let me know if any updates are needed. Kindly link this PR to my assigned issue and tag it under GSSoC 2026 and add lables.

Thank you! 🚀🔥

@DeepeshKafalatiya
Copy link
Copy Markdown
Author

Hi @imDarshanGK, Please take a look here

I have successfully implemented the UnreachableCodeDetector logic using Python's native ast parser and verified it locally using the Swagger UI docs interface.

Please review my changes and let me know if any updates are needed. Kindly link this PR to my assigned issue and tag it under GSSoC 2026 and add lables.

Thank you! 🚀🔥

@DeepeshKafalatiya
Copy link
Copy Markdown
Author

Hi @imDarshanGK 👋

Just wanted to let you know that I have successfully resolved all the merge conflicts on this PR. It is now clean, green, and completely ready for review.

Could you please take a look when you get a moment? Thank you so much for your time! 🚀

Please review my changes and let me know if any updates are needed. Kindly link this PR to my assigned issue and tag it under GSSoC 2026 and add lables.

Thank you! 🚀🔥

@imDarshanGK
Copy link
Copy Markdown
Owner

@DeepeshKafalatiya
image

@DeepeshKafalatiya
Copy link
Copy Markdown
Author

Hi @imDarshanGK!

I have cleaned up the indentation formatting and fully resolved the merge conflicts. The branch is now clean and ready for review.

Could you please approve and trigger the workflow checks when you get a moment? Thank you! 🚀

@imDarshanGK
Copy link
Copy Markdown
Owner

@DeepeshKafalatiya Resolve conflicts

@DeepeshKafalatiya
Copy link
Copy Markdown
Author

Hi @imDarshanGK!
Sorry for the inconvenience.

I have successfully resolved the latest merge conflicts directly on GitHub. The branch is completely up to date with the main branch and ready for review.

Could you please approve and trigger the workflow checks whenever you get a chance? Thank you so much! 🚀

@imDarshanGK
Copy link
Copy Markdown
Owner

@DeepeshKafalatiya update the branch with the latest main changes

@DeepeshKafalatiya
Copy link
Copy Markdown
Author

Hi @imDarshanGK!
I have already updated the branch with the latest main changes. As you can see, there are no conflicts now and the changes can be cleanly merged.

Could you please approve the workflow checks and review it when you are free? Thank you! 🚀

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.

[Feature] feat(backend): Add static rule to detect 'Dead Code / Unreachable Code' after return statements in Python

2 participants