Essentials

Code Review & Analysis

Learn how to use AI Developer Assistant for code review and analysis

Code Review & Analysis

AI Developer Assistant provides powerful code review capabilities that help identify issues, suggest improvements, and ensure code quality across multiple programming languages.

Basic Code Review

Review Latest Changes

# Review all changes in your working directory
ai-dev review

# Review only staged changes
ai-dev review --staged

# Review only unstaged changes
ai-dev review --unstaged

Review Specific Files

# Review specific files
ai-dev review --file-patterns "src/utils/helper.ts"

# Review multiple files
ai-dev review --file-patterns "src/**/*.ts,src/**/*.js"

# Review with glob patterns
ai-dev review --file-patterns "src/components/**/*.{ts,tsx}"

Advanced Review Options

Verbose Output

Get detailed analysis with verbose mode:

# Detailed review with explanations
ai-dev review --verbose

# Review specific files with verbose output
ai-dev review --file-patterns "src/**/*.ts" --verbose

Output Formats

Choose different output formats for different use cases:

# Console output (default)
ai-dev review

# Markdown output
ai-dev review --format markdown --output-path review.md

# JSON output for programmatic use
ai-dev review --format json --output-path review.json

# HTML output for sharing
ai-dev review --format html --output-path review.html

Git Integration

Review changes between specific commits or branches:

# Review changes between commits
ai-dev review --base HEAD~1 --head HEAD

# Review changes between branches
ai-dev review --base main --head feature-branch

# Review specific commit
ai-dev review --base commit-hash~1 --head commit-hash

Language-Specific Analysis

TypeScript/JavaScript

# Review TypeScript files
ai-dev review --file-patterns "src/**/*.ts"

# Review React components
ai-dev review --file-patterns "src/components/**/*.{ts,tsx}"

# Review Node.js backend
ai-dev review --file-patterns "server/**/*.{js,ts}"

Python

# Review Python files
ai-dev review --file-patterns "**/*.py"

# Review specific modules
ai-dev review --file-patterns "src/api/**/*.py"

# Review with Python-specific analysis
ai-dev review --file-patterns "**/*.py" --verbose

Dart/Flutter

# Review Dart files
ai-dev review --file-patterns "lib/**/*.dart"

# Review Flutter widgets
ai-dev review --file-patterns "lib/widgets/**/*.dart"

# Review with Flutter-specific best practices
ai-dev review --file-patterns "lib/**/*.dart" --verbose

Java

# Review Java files
ai-dev review --file-patterns "src/**/*.java"

# Review Spring Boot applications
ai-dev review --file-patterns "src/main/java/**/*.java"

# Review with Java-specific patterns
ai-dev review --file-patterns "**/*.java" --verbose

Review Categories

AI Developer Assistant analyzes code across multiple categories:

Code Quality

  • Style Issues: Inconsistent formatting, naming conventions
  • Best Practices: Following language-specific best practices
  • Code Smells: Long methods, duplicate code, complex conditionals
  • Maintainability: Code organization, modularity, readability

Logic & Correctness

  • Potential Bugs: Logic errors, edge cases, null pointer exceptions
  • Algorithm Efficiency: Performance issues, complexity analysis
  • Error Handling: Missing error handling, improper exception usage
  • Data Flow: Variable usage, state management, data consistency

Security

  • Vulnerabilities: Injection attacks, authentication issues, data exposure
  • Input Validation: Missing validation, sanitization issues
  • Cryptography: Weak encryption, improper key handling
  • Dependencies: Vulnerable dependencies, outdated packages

Documentation

  • Missing Documentation: Functions, classes, and modules without docs
  • Incomplete Documentation: Missing parameters, return types, examples
  • Outdated Documentation: Documentation that doesn't match code
  • API Documentation: Missing or incomplete API documentation

GitHub Integration

Post Reviews to GitHub PRs

# Post review comments to GitHub PR
ai-dev review --post-github --github-owner your-org --github-repo your-repo --pr 123

# Post with specific options
ai-dev review --post-github --github-owner your-org --github-repo your-repo --pr 123 --verbose

GitHub Configuration

Set up GitHub integration:

# Set GitHub token
export GITHUB_TOKEN="your-github-token"

# Or use configuration file
# ai-dev.config.local.yaml
github:
  token: "${GITHUB_TOKEN}"
  baseUrl: "https://api.github.com"

Review Workflows

Daily Development Workflow

# 1. Make your changes
git add .

# 2. Review staged changes
ai-dev review --staged --verbose

# 3. Address any critical issues
# 4. Commit your changes
git commit -m "Your commit message"

Pull Request Workflow

# 1. Create PR and get PR number
# 2. Review with GitHub integration
ai-dev review --post-github --github-owner your-org --github-repo your-repo --pr 123

# 3. Generate PR summary
ai-dev pr-summary --pr 123 --include-metrics

Pre-commit Workflow

# 1. Stage your changes
git add .

# 2. Review staged changes
ai-dev review --staged

# 3. If review passes, commit
git commit -m "Your commit message"

Continuous Integration

# In CI pipeline
ai-dev review --format json --output-path review.json

# Check for critical issues
if grep -q '"severity":"critical"' review.json; then
  echo "Critical issues found"
  exit 1
fi

Customizing Reviews

Exclude Patterns

# Exclude test files from review
ai-dev review --exclude-patterns "**/*.test.ts,**/*.spec.ts"

# Exclude generated files
ai-dev review --exclude-patterns "**/generated/**,**/dist/**"

# Exclude multiple patterns
ai-dev review --exclude-patterns "**/node_modules/**,**/coverage/**,**/*.min.js"

Focus Areas

# Focus on security issues
ai-dev review --categories security

# Focus on performance issues
ai-dev review --categories performance

# Focus on documentation issues
ai-dev review --categories documentation

Severity Levels

# Review only high and critical issues
ai-dev review --severity high,critical

# Review all issues including low severity
ai-dev review --severity low,medium,high,critical

Review Output Examples

Console Output

ai-dev review --file-patterns "src/utils/helper.ts"

Example Output:

🔍 Code Review: src/utils/helper.ts

✅ Code Quality: Good
   - Consistent naming conventions
   - Proper TypeScript types

⚠️  Potential Issues:
   - Line 15: Consider adding null check for user input
   - Line 23: Function could be simplified

🔒 Security: No issues found

📚 Documentation: Missing
   - Function 'processUserData' needs JSDoc comments
   - Parameter 'data' should be documented

Markdown Output

ai-dev review --format markdown --output-path review.md

Example Output:

# Code Review Report

## Summary
- **Files Reviewed**: 5
- **Issues Found**: 12
- **Critical**: 0
- **High**: 2
- **Medium**: 5
- **Low**: 5

## Issues by File

### src/utils/helper.ts
- **Line 15**: Consider adding null check for user input
- **Line 23**: Function could be simplified
- **Line 31**: Missing JSDoc documentation

## Recommendations
1. Add input validation
2. Simplify complex functions
3. Add comprehensive documentation

JSON Output

ai-dev review --format json --output-path review.json

Example Output:

{
  "summary": {
    "filesReviewed": 5,
    "issuesFound": 12,
    "severity": {
      "critical": 0,
      "high": 2,
      "medium": 5,
      "low": 5
    }
  },
  "issues": [
    {
      "file": "src/utils/helper.ts",
      "line": 15,
      "severity": "medium",
      "category": "logic",
      "message": "Consider adding null check for user input",
      "suggestion": "Add null check before processing user data"
    }
  ]
}

Best Practices

Regular Reviews

  1. Review before committing:
ai-dev review --staged
  1. Review before pushing:
ai-dev review --base origin/main --head HEAD
  1. Review in CI/CD:
ai-dev review --format json --output-path review.json

Focus on Quality

  1. Address critical issues first:
ai-dev review --severity critical,high
  1. Review security-sensitive code:
ai-dev review --file-patterns "src/auth/**/*.ts" --categories security
  1. Maintain documentation:
ai-dev review --categories documentation

Team Collaboration

  1. Use GitHub integration:
ai-dev review --post-github --github-owner your-org --github-repo your-repo --pr 123
  1. Share review reports:
ai-dev review --format markdown --output-path review.md
  1. Track review metrics:
ai-dev review --format json --output-path review.json
Start with basic reviews and gradually incorporate more advanced features like GitHub integration and custom output formats as your team's workflow matures.