Skip to content

Commit dba48b9

Browse files
Fix command and shell consider fixed sceanrios (#2410)
1 parent a441661 commit dba48b9

File tree

2 files changed

+130
-20
lines changed

2 files changed

+130
-20
lines changed

.claude/commands/api-lint-diff.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Validate API issues using kube-api-linter with diff-aware analysis
44

55
# API Lint Diff
66

7-
Validates API issues in `api/` directory using kube-api-linter with diff-aware analysis that distinguishes between NEW and PRE-EXISTING issues.
7+
Validates API issues in `api/` directory using kube-api-linter with diff-aware analysis that distinguishes between FIXED, NEW, and PRE-EXISTING issues.
88

99
## Instructions for Claude AI
1010

@@ -19,6 +19,7 @@ When this command is invoked, you MUST:
1919

2020
2. **Understand the shell script's output**:
2121
- **False positives (IGNORED)**: Standard CRD scaffolding patterns that kube-api-linter incorrectly flags
22+
- **FIXED issues (SUCCESS)**: Issues that existed in baseline but were resolved in current branch → Celebrate! 🎉
2223
- **NEW issues (ERRORS)**: Introduced in current branch → MUST fix
2324
- **PRE-EXISTING issues (WARNINGS)**: Existed before changes → Can fix separately
2425

@@ -132,23 +133,38 @@ When this command is invoked, you MUST:
132133
# API Lint Diff Analysis Report
133134

134135
**Generated:** [date]
135-
**Baseline:** main branch
136-
**Current:** [branch name]
136+
**Baseline:** main branch (X issues)
137+
**Current:** [branch name] (Y issues)
137138
**Status:** [status icon and message based on logic below]
138139

139140
**Status Logic:**
140-
- ✅ PASSED: 0 real issues (after filtering false positives)
141+
- ✅ PASSED: 0 new issues (fixed issues are OK)
141142
- ⚠️ WARN: 0 new issues but has pre-existing issues
142143
- ❌ FAIL: Has new issues that must be fixed
143144

144145
## Executive Summary
145-
- Total issues: X
146-
- False positives (IGNORED): Y
147-
- Real issues (NEED FIXING): Z
148-
- NEW issues: N
149-
- PRE-EXISTING issues: P
146+
- Baseline issues: X
147+
- Current issues: Y
148+
- **FIXED**: F (issues resolved in this branch)
149+
- **NEW**: N (issues introduced in this branch)
150+
- **PRE-EXISTING**: P (issues that still remain)
151+
- False positives (IGNORED): Z
150152

151-
## REAL ISSUES - FIXES NEEDED (Z issues)
153+
## FIXED ISSUES (F issues)
154+
155+
[List of issues that were fixed in this branch - show the baseline line numbers]
156+
157+
## NEW ISSUES (N issues)
158+
159+
[List of issues introduced in this branch - these MUST be fixed]
160+
161+
## PRE-EXISTING ISSUES (P issues)
162+
163+
[List of issues that existed before and still exist - can be fixed separately]
164+
165+
---
166+
167+
## DETAILED ANALYSIS FOR ISSUES NEEDING FIXES
152168

153169
### Category 1: [Issue Type] (N issues) - [BREAKING/NON-BREAKING]
154170

hack/api-lint-diff/run.sh

Lines changed: 104 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,14 @@ get_changed_files() {
257257
grep -v 'zz_generated' || true
258258
}
259259

260-
# Categorize issues as NEW or PRE-EXISTING
260+
# Categorize issues as NEW, PRE-EXISTING, or FIXED
261261
categorize_issues() {
262262
local current_file="$1"
263263
local baseline_file="$2"
264264
local changed_files_file="$3"
265265
local new_issues_file="$4"
266266
local preexisting_issues_file="$5"
267+
local fixed_issues_file="$6"
267268

268269
# Read changed files into array
269270
local changed_files=()
@@ -306,17 +307,81 @@ categorize_issues() {
306307
# Compare without line numbers since line numbers can change when code is added/removed
307308
# Format is: file:line:col:linter:message
308309
# We'll compare: file:linter:message
309-
# Use f1,4,5- to capture field 5 and all remaining fields (handles colons in messages)
310+
# Extract file (field 1), linter (field 4), and message (field 5+) from current issue
310311
local file_linter_msg
311312
file_linter_msg=$(echo "${line}" | cut -d: -f1,4,5-)
312313

313-
if grep -Fq "${file_linter_msg}" "${baseline_file}" 2>/dev/null; then
314+
# Check if baseline has a matching issue (same file, linter, message but possibly different line number)
315+
# We need to extract the same fields from baseline and compare
316+
local found=false
317+
if [[ -f "${baseline_file}" ]]; then
318+
while IFS= read -r baseline_line; do
319+
[[ -z "${baseline_line}" ]] && continue
320+
local baseline_file_linter_msg
321+
baseline_file_linter_msg=$(echo "${baseline_line}" | cut -d: -f1,4,5-)
322+
if [[ "${file_linter_msg}" == "${baseline_file_linter_msg}" ]]; then
323+
found=true
324+
break
325+
fi
326+
done < "${baseline_file}"
327+
fi
328+
329+
if $found; then
314330
echo "${line}" >> "${preexisting_issues_file}"
315331
else
316332
echo "${line}" >> "${new_issues_file}"
317333
fi
318334
done < "${current_file}"
319335
fi
336+
337+
# Find FIXED issues - issues in baseline that are NOT in current
338+
if [[ -f "${baseline_file}" && -s "${baseline_file}" ]]; then
339+
while IFS= read -r baseline_line; do
340+
[[ -z "${baseline_line}" ]] && continue
341+
342+
local file
343+
file=$(echo "${baseline_line}" | cut -d: -f1)
344+
345+
# Only check files that were changed
346+
if [[ ${#changed_files[@]} -gt 0 ]]; then
347+
local file_changed=false
348+
for changed_file in "${changed_files[@]}"; do
349+
if [[ "${file}" == "${changed_file}" ]]; then
350+
file_changed=true
351+
break
352+
fi
353+
done
354+
355+
# Skip if file wasn't changed
356+
if ! $file_changed; then
357+
continue
358+
fi
359+
fi
360+
361+
# Extract file:linter:message from baseline
362+
local baseline_file_linter_msg
363+
baseline_file_linter_msg=$(echo "${baseline_line}" | cut -d: -f1,4,5-)
364+
365+
# Check if this issue still exists in current
366+
local still_exists=false
367+
if [[ -f "${current_file}" ]]; then
368+
while IFS= read -r current_line; do
369+
[[ -z "${current_line}" ]] && continue
370+
local current_file_linter_msg
371+
current_file_linter_msg=$(echo "${current_line}" | cut -d: -f1,4,5-)
372+
if [[ "${baseline_file_linter_msg}" == "${current_file_linter_msg}" ]]; then
373+
still_exists=true
374+
break
375+
fi
376+
done < "${current_file}"
377+
fi
378+
379+
# If issue doesn't exist in current, it was fixed
380+
if ! $still_exists; then
381+
echo "${baseline_line}" >> "${fixed_issues_file}"
382+
fi
383+
done < "${baseline_file}"
384+
fi
320385
}
321386

322387
# Output issue (basic format)
@@ -328,20 +393,41 @@ output_issue() {
328393
generate_report() {
329394
local new_issues_file="$1"
330395
local preexisting_issues_file="$2"
396+
local fixed_issues_file="$3"
397+
local baseline_file="$4"
331398

332399
local new_count=0
333400
local preexisting_count=0
401+
local fixed_count=0
402+
local baseline_count=0
334403

335404
[[ -f "${new_issues_file}" ]] && new_count=$(wc -l < "${new_issues_file}" | tr -d ' ')
336405
[[ -f "${preexisting_issues_file}" ]] && preexisting_count=$(wc -l < "${preexisting_issues_file}" | tr -d ' ')
406+
[[ -f "${fixed_issues_file}" ]] && fixed_count=$(wc -l < "${fixed_issues_file}" | tr -d ' ')
407+
[[ -f "${baseline_file}" ]] && baseline_count=$(wc -l < "${baseline_file}" | tr -d ' ')
408+
409+
local current_total=$((new_count + preexisting_count))
337410

338-
# Simple summary
411+
# Summary header
339412
echo "API Lint Diff Results"
340-
echo "Baseline: ${BASELINE_BRANCH}"
413+
echo "====================="
414+
echo "Baseline (${BASELINE_BRANCH}): ${baseline_count} issues"
415+
echo "Current branch: ${current_total} issues"
416+
echo ""
417+
echo "FIXED: ${fixed_count}"
341418
echo "NEW: ${new_count}"
342419
echo "PRE-EXISTING: ${preexisting_count}"
343420
echo ""
344421

422+
# Show FIXED issues
423+
if [[ ${fixed_count} -gt 0 ]]; then
424+
echo "=== FIXED ISSUES ==="
425+
while IFS= read -r line; do
426+
output_issue "${line}"
427+
done < "${fixed_issues_file}"
428+
echo ""
429+
fi
430+
345431
# Show NEW issues
346432
if [[ ${new_count} -gt 0 ]]; then
347433
echo "=== NEW ISSUES ==="
@@ -362,13 +448,17 @@ generate_report() {
362448

363449
# Exit based on NEW issues count
364450
if [[ ${new_count} -eq 0 ]]; then
365-
echo -e "${GREEN}NO NEW ISSUES found. Lint check passed.${NC}"
451+
if [[ ${fixed_count} -gt 0 ]]; then
452+
echo -e "${GREEN}SUCCESS: Fixed ${fixed_count} issue(s), no new issues introduced.${NC}"
453+
else
454+
echo -e "${GREEN}NO NEW ISSUES found. Lint check passed.${NC}"
455+
fi
366456
if [[ ${preexisting_count} -gt 0 ]]; then
367-
echo -e "${YELLOW}WARNING: Pre-existing issues detected. Please address them separately.${NC}"
457+
echo -e "${YELLOW}WARNING: ${preexisting_count} pre-existing issue(s) remain. Please address them separately.${NC}"
368458
fi
369459
return 0
370460
else
371-
echo -e "${RED}FAILED: ${new_count} new issue(s)${NC}"
461+
echo -e "${RED}FAILED: ${new_count} new issue(s) introduced${NC}"
372462
return 1
373463
fi
374464
}
@@ -414,18 +504,22 @@ main() {
414504
# Categorize issues
415505
touch "${TEMP_DIR}/new_issues.txt"
416506
touch "${TEMP_DIR}/preexisting_issues.txt"
507+
touch "${TEMP_DIR}/fixed_issues.txt"
417508

418509
categorize_issues \
419510
"${TEMP_DIR}/current_parsed.txt" \
420511
"${TEMP_DIR}/baseline_parsed.txt" \
421512
"${TEMP_DIR}/changed_files.txt" \
422513
"${TEMP_DIR}/new_issues.txt" \
423-
"${TEMP_DIR}/preexisting_issues.txt"
514+
"${TEMP_DIR}/preexisting_issues.txt" \
515+
"${TEMP_DIR}/fixed_issues.txt"
424516

425517
# Generate report
426518
generate_report \
427519
"${TEMP_DIR}/new_issues.txt" \
428-
"${TEMP_DIR}/preexisting_issues.txt"
520+
"${TEMP_DIR}/preexisting_issues.txt" \
521+
"${TEMP_DIR}/fixed_issues.txt" \
522+
"${TEMP_DIR}/baseline_parsed.txt"
429523

430524
return $?
431525
}

0 commit comments

Comments
 (0)