## Scope Validation

**Goal**: Validate whether the file and starting line number of a defect are within the scan scope. Defects outside the scope will be filtered or corrected.

### Branch Scan Mode

1. Obtain branch change information:
   * Use `git diff <target_branch>..<source_branch> --diff-filter=AM` to get the additions and modifications on the source branch relative to the target branch
   * Extract the changed file list (add `--name-only`) and the changed line number ranges (parse `+` lines from the diff output)

2. Two-level validation and correction:

   **Level 1: File Validation**
   * The defect's file path must be in the changed file list, otherwise **filter immediately**

   **Level 2: Line Number Validation and Correction**
   * The defect's starting line number (start_line) must be within the changed line number range of that file
   * If not within range, attempt correction using the following strategies:

   **Line Number Correction Strategies** (attempt in order of priority):

   * **Strategy 1: Function Name Match** — If the defect reports an issue in a specific function, search for that function name in the diff (keywords like `def`/`function`/`func`/`void`), and correct the line number to the function's changed line
   * **Strategy 2: Variable Name Match** — Search for variable declarations or usages in the changes (variable names mentioned in the defect description), and correct the line number to the variable-related change
   * **Strategy 3: Code Pattern Match** — Search for code patterns in the changes that match the defect description (e.g., specific API calls, operator usages), and correct the line number to the matched location
   * **Correction Failure Handling** — If none of the three strategies can match, mark as "line number unverifiable" rather than filtering directly, and let the validation stage make further judgment

   **Multi-hunk diff handling**:
   * When a file has multiple non-contiguous changes, the defect's line number only needs to fall within **any one hunk range** to pass
   * Hunk range = starting line from `@@` marker + number of changed lines
   * Parse the `@@ -a,b +c,d @@` format in `git diff` output to extract the line number ranges of all hunks

3. Exception handling: If Git Diff information cannot be obtained, log a warning but do not filter. Note in the report conclusion that "change scope validation was not performed"

### File Scan Mode

1. File path validation: The defect's file path must be in the user-specified file list, otherwise **filter immediately**
2. Line range validation (only when the user specified a line range, e.g., `:10:50`):
   * The defect's starting line number must be within the specified line range, otherwise **filter**
3. When no line range is specified: Only validate file path, do not validate line numbers

### Directory Scan Mode

1. File path validation: The defect's file path must be under the user-specified directory, otherwise **filter immediately**
2. Line range validation: Skip (directory mode scans entire files, no line number restrictions)
