This repository was archived by the owner on Apr 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
152 lines (145 loc) · 6.48 KB
/
mcfunction-lint.yml
File metadata and controls
152 lines (145 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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"