Skip to content

Commit 601a036

Browse files
theletterfcodexcursoragentclaude
authored
Fix Vale false positives on context lines in PR diffs (#181)
* Update Vale sticky comment behavior Keep the Vale PR comment stable by updating it in place and skipping no-op updates when the rendered report is unchanged. Co-authored-by: OpenAI GPT-5.5 <noreply@openai.com> Co-authored-by: Cursor <cursoragent@cursor.com> * Fix Vale false positives on context lines in PR diffs The line-range filter was extracting hunk headers (@@ -x,y +a,b @@) and treating the entire hunk span as "modified." Context lines within a hunk (e.g. mapped_pages at line 3 when only a description was added at line 2) were wrongly flagged. Fix: walk the full patch per-file and record only actual '+' lines, one entry per added line. Change the Python filter to exclusive upper bound (start <= line < end) so a count=1 entry for line N matches exactly N. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: OpenAI GPT-5.5 <noreply@openai.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b1d0893 commit 601a036

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

vale/lint/action.yml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -512,19 +512,25 @@ runs:
512512
'.[] | select(.filename == $f) | .patch // empty')
513513
514514
if [ -n "$patch" ]; then
515-
echo "$patch" | { grep '^@@' || true; } | while read -r hunk; do
516-
# Extract start line and count from @@ -x,y +a,b @@
517-
range=$(echo "$hunk" | sed -n 's/^@@ -[0-9,]* +\([0-9]*\),*\([0-9]*\).*/\1 \2/p')
518-
start=$(echo "$range" | awk '{print $1}')
519-
count=$(echo "$range" | awk '{print $2}')
520-
521-
# If count is empty, exactly 1 line was changed
522-
if [ -z "$count" ]; then
523-
count=1
524-
fi
525-
526-
echo "$file|$start|$count" >> "$TEMP_DIR/line_ranges.txt"
527-
done
515+
new_line=0
516+
while IFS= read -r pline; do
517+
case "$pline" in
518+
@@*)
519+
new_line=$(printf '%s\n' "$pline" | sed -n 's/^@@ -[0-9,]* +\([0-9]*\).*/\1/p')
520+
;;
521+
+++*|---*)
522+
;;
523+
+*)
524+
echo "$file|$new_line|1" >> "$TEMP_DIR/line_ranges.txt"
525+
new_line=$((new_line + 1))
526+
;;
527+
-*)
528+
;;
529+
*)
530+
new_line=$((new_line + 1))
531+
;;
532+
esac
533+
done <<< "$patch"
528534
fi
529535
done < files_to_lint.txt
530536

vale/lint/vale_reporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def filter_issues_to_modified_lines(
155155
if modified_ranges:
156156
if normalized_file in modified_ranges:
157157
ranges = modified_ranges[normalized_file]
158-
is_modified = any(start <= line_num <= end for start, end in ranges)
158+
is_modified = any(start <= line_num < end for start, end in ranges)
159159
if not is_modified:
160160
stats['filtered_no_line_match'] += 1
161161
if debug:

0 commit comments

Comments
 (0)