Work on this exercise locally

This web app is a reference guide — you can read instructions, browse starter code, and view tests here. To actually complete the exercise, you need to work in your local development environment.

1Clone the repo: git clone https://github.com/weihaoqu/program-analysis-bootcamp-student
2Edit the starter file in your editor (VS Code, Vim, etc.) — replace failwith "TODO" with your implementation.
3Run the tests: dune runtest labs/lab3-static-checker

Lab 3: Static Checker

Lab 3: Static Analysis Checker

Prerequisites: Modules 1-3 completed Duration: 4 hours | Total Points: 100

Objectives

  • Implement a static analysis tool for Python code quality checking
  • Create a configurable rule engine with multiple analysis passes
  • Generate structured analysis reports

Parts

Part A: Core Analysis Engine (40 points)

  • Implement StaticChecker class that parses and analyzes Python files
  • Detect: unused variables, unreachable code after return, undefined variable references
  • Handle multiple files in a single analysis run

Part B: Rule Engine (35 points)

  • Create configurable analysis rules with enable/disable and severity levels
  • Implement at least 3 rules: unused-variable, unreachable-code, shadowed-variable
  • Generate structured reports (text and JSON)

Part C: Integration Testing (25 points)

  • Test tool on provided sample code files
  • Document tool capabilities and limitations
  • Measure and report analysis performance

Getting Started

cd labs/lab3-static-checker/starter
pytest tests/test_checker.py -v
python checker.py sample_code/

Deliverables

  1. Completed checker.py, rules.py, reporter.py
  2. Test suite passing
  3. Analysis of all sample code files

Grading Rubric

CriteriaExcellent (90-100%)Good (80-89%)Satisfactory (70-79%)Needs Work (<70%)
Analysis AccuracyHigh precision, minimal false positivesGood accuracyAcceptable accuracyMany false positives/negatives
Tool ArchitectureModular, extensible designWell-structuredFunctionalPoorly structured
PerformanceEfficient, scales wellGood performanceAdequatePerformance issues
DocumentationComprehensiveGood coverageBasicMinimal