Skip to content

AST-based Python code reviewer with pattern detection and optional LLM integration

License

Notifications You must be signed in to change notification settings

ama228/ai-code-reviewer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ai-code-reviewer

Automated Python code reviewer combining AST-based static analysis, regex pattern detection, and optional LLM-powered feedback.

What it catches

Security

  • Hardcoded passwords, API keys, tokens
  • eval() / exec() usage

Bugs

  • Bare except: clauses (catches KeyboardInterrupt)
  • Mutable default arguments (def foo(x=[]))
  • Silent error swallowing (except: pass)

Style

  • Wildcard imports (from x import *)
  • TODO/FIXME comments
  • Commented-out code blocks

Usage

from ai_reviewer import CodeReviewer

reviewer = CodeReviewer()
result = reviewer.review(open("app.py").read(), "app.py")

print(result.summary())
# Review: app.py
#   5 issues (2 errors, 1 warnings)
#   security: 2
#   bug: 1
#   style: 2

for issue in result.issues:
    print(f"  {issue}")
    if issue.suggestion:
        print(f"    -> {issue.suggestion}")

With LLM feedback

def llm_review(code, filename):
    # call your LLM API here
    return client.chat("Review this code for issues:\n" + code)

reviewer = CodeReviewer(llm_review_fn=llm_review)
result = reviewer.review(code)
print(result.llm_feedback)

Filtering

# skip style issues, only show warnings and errors
reviewer = CodeReviewer(
    skip_categories={"style"},
    min_severity="warning",
)

Tests

pytest -v

About

AST-based Python code reviewer with pattern detection and optional LLM integration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages