Skip to content

Commit a78233a

Browse files
chore: convert final-newline lint to Bash; drop irrelevant excludes (#135)
1 parent 766f291 commit a78233a

1 file changed

Lines changed: 12 additions & 33 deletions

File tree

.github/workflows/lint-format.yml

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ jobs:
3434
3535
- name: Check for Trailing Whitespaces
3636
run: |
37-
FILES=$(git grep -Ilr '[[:blank:]]$' -- \
38-
':(exclude)*.nix' \
39-
':(exclude)*.sql' \
40-
':(exclude)*.out' \
41-
':(exclude)*.rs' \
42-
':(exclude)docker/manifests/**' || true)
37+
FILES=$(git grep -Ilr '[[:blank:]]$' || true)
4338
if [[ ! -z "$FILES" ]]; then
4439
echo "The following files have trailing whitespaces:"
4540
echo "$FILES"
@@ -48,30 +43,14 @@ jobs:
4843
4944
- name: Check for Missing Final Newlines
5045
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
46+
MISSING=""
47+
while IFS= read -r file; do
48+
if [[ -s "$file" && -n "$(tail -c1 "$file")" ]]; then
49+
MISSING="${MISSING}${file}"$'\n'
50+
fi
51+
done < <(git grep -Il '.')
52+
if [[ -n "$MISSING" ]]; then
53+
echo "The following files are missing a trailing newline:"
54+
echo "$MISSING"
55+
exit 1
56+
fi

0 commit comments

Comments
 (0)