Skip to content

Commit ddb7dfc

Browse files
committed
chore: convert final-newline lint check from Python to Bash
1 parent 766f291 commit ddb7dfc

1 file changed

Lines changed: 16 additions & 27 deletions

File tree

.github/workflows/lint-format.yml

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,19 @@ jobs:
4848
4949
- name: Check for Missing Final Newlines
5050
run: |
51-
python - <<'PY'
52-
from pathlib import Path
53-
import subprocess
54-
import sys
55-
56-
ignored_suffixes = {".nix", ".sql", ".out", ".rs"}
57-
ignored_prefixes = ("docker/manifests/",)
58-
missing_newline: list[str] = []
59-
60-
output = subprocess.check_output(["git", "ls-files", "-z"], text=False)
61-
for raw_path in output.decode().split("\0"):
62-
if not raw_path:
63-
continue
64-
path = Path(raw_path)
65-
if raw_path.startswith(ignored_prefixes) or path.suffix in ignored_suffixes:
66-
continue
67-
data = path.read_bytes()
68-
if b"\0" in data:
69-
continue
70-
if data and not data.endswith(b"\n"):
71-
missing_newline.append(raw_path)
72-
73-
if missing_newline:
74-
print("The following files are missing a trailing newline:")
75-
print("\n".join(missing_newline))
76-
sys.exit(1)
77-
PY
51+
MISSING=""
52+
while IFS= read -r file; do
53+
if [[ -s "$file" && -n "$(tail -c1 "$file")" ]]; then
54+
MISSING="${MISSING}${file}"$'\n'
55+
fi
56+
done < <(git grep -Il '.' -- \
57+
':(exclude)*.nix' \
58+
':(exclude)*.sql' \
59+
':(exclude)*.out' \
60+
':(exclude)*.rs' \
61+
':(exclude)docker/manifests/**')
62+
if [[ -n "$MISSING" ]]; then
63+
echo "The following files are missing a trailing newline:"
64+
echo "$MISSING"
65+
exit 1
66+
fi

0 commit comments

Comments
 (0)