Skip to content
This repository was archived by the owner on Apr 9, 2026. It is now read-only.

Create time_phase.mcfunction #144

Create time_phase.mcfunction

Create time_phase.mcfunction #144

name: mcfunction Lint
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
on:
push:
branches: [ main ]
paths:
- '**/*.mcfunction'
- '**/*.json'
- '.github/workflows/mcfunction-lint.yml'
pull_request:
branches: [ main ]
paths:
- '**/*.mcfunction'
jobs:
# ─────────────────────────────────────────────
# 1. CRLF Line Ending Detection
# ─────────────────────────────────────────────
lint-crlf:
name: CRLF Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Detect CRLF line endings in .mcfunction files
run: |
FAILED=0
while IFS= read -r f; do
if file "$f" | grep -q "CRLF"; then
echo "FAIL [CRLF]: $f"
FAILED=1
fi
done < <(find data _pre_1_21_4 compat_1_21_4 1_20_3 1_21_4 1_21_5 1_21_6 26_1 -name "*.mcfunction" 2>/dev/null)
if [ $FAILED -ne 0 ]; then
echo ""
echo "Fix: git config core.autocrlf false && dos2unix <file>"
exit 1
fi
echo "PASSED: No CRLF line endings found."
# ─────────────────────────────────────────────
# 2. Macro Line Prefix Check
# Macro değişkeni $(var) kullanan satırlar $ ile başlamalı
# ─────────────────────────────────────────────
lint-macro-prefix:
name: Macro Line Prefix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Check macro variable lines start with $
run: |
FAILED=0
while IFS= read -r f; do
lineno=0
while IFS= read -r line; do
lineno=$((lineno + 1))
stripped=$(echo "$line" | sed 's/^[[:space:]]*//')
[[ "$stripped" == "#"* || -z "$stripped" ]] && continue
# Line contains $(var) but does NOT start with $
if echo "$line" | grep -qP '\$\([a-zA-Z_][a-zA-Z0-9_]*\)'; then
if ! echo "$line" | grep -qP '^\s*\$'; then
# BUG FIX: $(var) inside double-quoted echo was executed as shell command.
# Use single quotes around the dynamic part to print literally.
echo "FAIL [macro-prefix] $f:$lineno: "'\$(var)'" used on non-macro line"
echo " > $line"
FAILED=1
fi
fi
done < "$f"
done < <(find data _pre_1_21_4 compat_1_21_4 1_20_3 1_21_4 1_21_5 1_21_6 26_1 -name "*.mcfunction" 2>/dev/null)
[ $FAILED -ne 0 ] && exit 1 || echo "PASSED: All macro variables on correct lines."
# ─────────────────────────────────────────────
# 3. INPUT Comment Coverage
# $(var) kullanan dosyalar # INPUT: yorumuna sahip olmalı
# ─────────────────────────────────────────────
lint-input-comment:
name: INPUT Comment Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Check INPUT comment presence where macros are used
run: |
WARN=0
while IFS= read -r f; do
has_macro=$(grep -cP '^\$' "$f") || has_macro=0
has_input=$(grep -cP '^# INPUT:' "$f") || has_input=0
if [ "${has_macro:-0}" -gt 0 ] && [ "${has_input:-0}" -eq 0 ]; then
echo "WARN [no-input-comment]: $f"
WARN=$((WARN + 1))
fi
done < <(find data _pre_1_21_4 compat_1_21_4 1_20_3 1_21_4 1_21_5 1_21_6 26_1 -name "*.mcfunction" 2>/dev/null)
if [ $WARN -gt 0 ]; then
echo ""
echo "WARN: $WARN file(s) use macro variables but have no '# INPUT:' comment."
else
echo "PASSED: All macro files have INPUT comments."
fi
# ─────────────────────────────────────────────
# 4. @p Selector Usage
# Bu projede @p yerine @a[name=...,limit=1] kullanılır
# ─────────────────────────────────────────────
lint-at-p:
name: "@p Selector Check"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Warn on @p usage
run: |
FOUND=0
while IFS= read -r f; do
lineno=0
while IFS= read -r line; do
lineno=$((lineno + 1))
stripped=$(echo "$line" | sed 's/^[[:space:]]*//')
[[ "$stripped" == "#"* || -z "$stripped" ]] && continue
if echo "$line" | grep -qP '@p\b'; then
echo "WARN [@p]: $f:$lineno"
echo " > $line"
FOUND=$((FOUND + 1))
fi
done < "$f"
done < <(find data _pre_1_21_4 compat_1_21_4 1_20_3 1_21_4 1_21_5 1_21_6 26_1 -name "*.mcfunction" 2>/dev/null)
if [ $FOUND -gt 0 ]; then
echo ""
echo "WARN: $FOUND @p occurrence(s). Prefer @a[name=\$(player),limit=1]."
else
echo "PASSED: No @p usage found."
fi
# ─────────────────────────────────────────────
# 5. Trailing Whitespace
# ─────────────────────────────────────────────
lint-trailing-whitespace:
name: Trailing Whitespace
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Detect trailing whitespace in .mcfunction files
run: |
FOUND=0
while IFS= read -r f; do
count=$(grep -cP '\s+$' "$f") || count=0
if [ "${count:-0}" -gt 0 ]; then
echo "WARN [trailing-ws]: $f ($count line(s))"
FOUND=$((FOUND + count))
fi
done < <(find data _pre_1_21_4 compat_1_21_4 1_20_3 1_21_4 1_21_5 1_21_6 26_1 -name "*.mcfunction" 2>/dev/null)
[ $FOUND -gt 0 ] && echo "WARN: $FOUND total trailing whitespace line(s)." || echo "PASSED"