-
Notifications
You must be signed in to change notification settings - Fork 5
/
check-line-lengths.sh
executable file
·45 lines (35 loc) · 1.22 KB
/
check-line-lengths.sh
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
#!/usr/bin/env bash
# originally written by Steven Schaefer <stschaef>
error=0
VENV_DIR="env"
# Check if the virtual environment directory exists
if [ ! -d "$VENV_DIR" ]; then
echo "Virtual environment does not exist. Creating one now..."
# Create the virtual environment with python3
python3 -m venv "$VENV_DIR" || { echo "Failed to create virtual environment."; exit 1; }
fi
source "$VENV_DIR/bin/activate"
if [ $? -ne 0 ]; then
echo "Error: Unable to activate the virtual environment."
exit 2
fi
echo "Virtual environment activated."
pip3 install wcwidth || { echo "Failed to install wcwidth."; exit 3; }
echo "Package 'wcwidth' has been successfully installed in the virtual environment."
while IFS= read -r -d '' file; do
python3 -c '
import sys
from wcwidth import wcswidth
filename = sys.argv[1]
try:
with open(filename, "r", encoding="utf-8") as file:
for lineno, line in enumerate(file, 1):
if wcswidth(line.rstrip("\n")) > 80:
print(f"{filename}:{lineno}: line too long")
sys.exit(1)
except Exception as e:
print(f"Error processing {filename}: {e}")
sys.exit(1)
' "${file}" || error=1
done < <(find . -name '*.agda' -print0)
exit ${error}