Move comment style check from yaml to script
parent
8ccc0225ff
commit
2eac03b81d
|
|
@ -19,81 +19,5 @@ jobs:
|
|||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get changed files
|
||||
id: changed-files
|
||||
run: |
|
||||
# Get list of changed .java and .c/.h files in this PR
|
||||
git diff --name-only --diff-filter=AM origin/${{ github.base_ref }}...HEAD | \
|
||||
grep -E '\.(java|c|h)$' > changed_files.txt || echo "No matching files found"
|
||||
|
||||
if [ -s changed_files.txt ]; then
|
||||
echo "Found changed files:"
|
||||
cat changed_files.txt
|
||||
echo "has_files=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "No .java, .c, or .h files changed in this PR"
|
||||
echo "has_files=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Check for single-line comments in changed files
|
||||
if: steps.changed-files.outputs.has_files == 'true'
|
||||
run: |
|
||||
violations_found=false
|
||||
|
||||
while IFS= read -r file; do
|
||||
if [ -f "$file" ]; then
|
||||
echo "Checking $file for comment style violations..."
|
||||
|
||||
# Find potential single-line comments (//)
|
||||
# This is a simple check that may have some false positives
|
||||
# but catches the most common violations
|
||||
violations=$(grep -n '//' "$file" | \
|
||||
grep -v 'http://' | \
|
||||
grep -v 'https://' | \
|
||||
grep -v -E '/\*.*//.*\*/' | \
|
||||
grep -v -E '"[^"]*//[^"]*"' | \
|
||||
grep -E ':[[:space:]]*//' || true)
|
||||
|
||||
if [ -n "$violations" ]; then
|
||||
echo "❌ Single-line comments found in $file:"
|
||||
echo "$violations"
|
||||
echo ""
|
||||
violations_found=true
|
||||
else
|
||||
echo "✅ $file: No single-line comment violations found"
|
||||
fi
|
||||
fi
|
||||
done < changed_files.txt
|
||||
|
||||
if [ "$violations_found" = true ]; then
|
||||
echo ""
|
||||
echo "=================================="
|
||||
echo "❌ COMMENT STYLE CHECK FAILED"
|
||||
echo "=================================="
|
||||
echo ""
|
||||
echo "Single-line comments (//) were found in the changed files."
|
||||
echo "According to the coding standard in CLAUDE.md:"
|
||||
echo "- MUST only use multi-line comments, no \"//\" style ones"
|
||||
echo ""
|
||||
echo "Please replace all single-line comments (//) with multi-line comments (/* */)."
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " ❌ Bad: // This is a comment"
|
||||
echo " ✅ Good: /* This is a comment */"
|
||||
echo ""
|
||||
echo " ❌ Bad: // TODO: implement this"
|
||||
echo " ✅ Good: /* TODO: implement this */"
|
||||
echo ""
|
||||
exit 1
|
||||
else
|
||||
echo ""
|
||||
echo "=================================="
|
||||
echo "✅ COMMENT STYLE CHECK PASSED"
|
||||
echo "=================================="
|
||||
echo "All changed files follow the multi-line comment style standard."
|
||||
fi
|
||||
|
||||
- name: Comment style check skipped
|
||||
if: steps.changed-files.outputs.has_files == 'false'
|
||||
run: |
|
||||
echo "✅ Comment style check skipped - no .java, .c, or .h files were changed in this PR"
|
||||
run: ./scripts/comment-style-check.sh "${{ github.base_ref }}"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
#
|
||||
# Returns 0 if all lists match, 1 if any mismatch is found.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# cd to repo root (parent of scripts/)
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
|
||||
|
|
@ -62,10 +64,10 @@ compare_lists() {
|
|||
DISK_JAVA=$(find src/java -name '*.java' -not -path '*/test/*' | sort)
|
||||
|
||||
# Native .c files – basenames only (each manifest uses different path prefixes)
|
||||
DISK_C=$(find native -maxdepth 1 -name '*.c' -printf '%f\n' | sort)
|
||||
DISK_C=$(find native -maxdepth 1 -name '*.c' -exec basename {} \; | sort)
|
||||
|
||||
# Native .h files – basenames only
|
||||
DISK_H=$(find native -maxdepth 1 -name '*.h' -printf '%f\n' | sort)
|
||||
DISK_H=$(find native -maxdepth 1 -name '*.h' -exec basename {} \; | sort)
|
||||
|
||||
# ======================== Java source checks ========================
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Comment Style Check Script
|
||||
# Checks that .java, .c, and .h files use multi-line comments (/* */)
|
||||
# instead of single-line comments (//).
|
||||
#
|
||||
# Usage:
|
||||
# comment-style-check.sh <base_ref>
|
||||
#
|
||||
# Arguments:
|
||||
# base_ref - The base branch to diff against (e.g., "main")
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $0 <base_ref>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASE_REF="$1"
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
CHANGED_FILES="$(mktemp -t changed_files.XXXXXX)"
|
||||
trap 'rm -f "$CHANGED_FILES"' EXIT
|
||||
|
||||
cd "$REPO_ROOT"
|
||||
|
||||
# Get list of changed .java and .c/.h files
|
||||
DIFF_OUTPUT="$(git diff --name-only --diff-filter=AM "origin/${BASE_REF}...HEAD")"
|
||||
printf '%s\n' "$DIFF_OUTPUT" | grep -E '\.(java|c|h)$' > "$CHANGED_FILES" || true
|
||||
|
||||
if [ ! -s "$CHANGED_FILES" ]; then
|
||||
echo "✅ Comment style check skipped - no .java, .c, or .h files were changed in this PR"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Found changed files:"
|
||||
cat "$CHANGED_FILES"
|
||||
|
||||
violations_found=false
|
||||
|
||||
while IFS= read -r file; do
|
||||
if [ -f "$file" ]; then
|
||||
echo "Checking $file for comment style violations..."
|
||||
|
||||
# Find potential single-line comments (//)
|
||||
# This is a simple check that may have some false positives
|
||||
# but catches the most common violations
|
||||
violations=$(grep -n '//' "$file" | \
|
||||
grep -v 'http://' | \
|
||||
grep -v 'https://' | \
|
||||
grep -v -E '/\*.*//.*\*/' | \
|
||||
grep -v -E '"[^"]*//[^"]*"' || true)
|
||||
|
||||
if [ -n "$violations" ]; then
|
||||
echo "❌ Single-line comments found in $file:"
|
||||
echo "$violations"
|
||||
echo ""
|
||||
violations_found=true
|
||||
else
|
||||
echo "✅ $file: No single-line comment violations found"
|
||||
fi
|
||||
fi
|
||||
done < "$CHANGED_FILES"
|
||||
|
||||
if [ "$violations_found" = true ]; then
|
||||
echo ""
|
||||
echo "=================================="
|
||||
echo "❌ COMMENT STYLE CHECK FAILED"
|
||||
echo "=================================="
|
||||
echo ""
|
||||
echo "Single-line comments (//) were found in the changed files."
|
||||
echo "According to the coding standard in CLAUDE.md:"
|
||||
echo "- MUST only use multi-line comments, no \"//\" style ones"
|
||||
echo ""
|
||||
echo "Please replace all single-line comments (//) with multi-line comments (/* */)."
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " ❌ Bad: // This is a comment"
|
||||
echo " ✅ Good: /* This is a comment */"
|
||||
echo ""
|
||||
echo " ❌ Bad: // TODO: implement this"
|
||||
echo " ✅ Good: /* TODO: implement this */"
|
||||
echo ""
|
||||
exit 1
|
||||
else
|
||||
echo ""
|
||||
echo "=================================="
|
||||
echo "✅ COMMENT STYLE CHECK PASSED"
|
||||
echo "=================================="
|
||||
echo "All changed files follow the multi-line comment style standard."
|
||||
fi
|
||||
Loading…
Reference in New Issue