-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathchecks.sh
89 lines (81 loc) · 2.25 KB
/
checks.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
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
#! /usr/bin/env bash
set -e
script="$(dirname "$(readlink -f "$0")")"
packagedir="$script/../src/packages"
workdir=$(pwd)
IFS=$'\n'
pl=pylint
lintdir() {
comment="$1"
folder="$2"
echo "$comment"
$pl "$folder"
# also prevent runtime.execute
if grep -n -R -E "runtime\.execute\(|rt.execute\(" --include '*.py' "$folder"
then
echo "pymxs.execute used"
exit 1
fi
}
lint() {
for f in $(find "$packagedir" -name "setup.py")
do
local package="$(basename "$(dirname "$f")")"
lintdir "$package" "$packagedir/$package/$package"
done
}
lintsamples() {
lintdir "samples" "$script/../src/samples"
}
checkmarkdown() {
# find code blocks in markdown that don't specify the language
git grep -n '```' -- "*.md" |
dos2unix |
awk 'NR % 2 == 1' |
grep '``` *$' |
sed "s/$/ code block does not specify language/g"
# find references to max that are not 3ds Max
git grep "[^a-zA-Z_]max[^a-zA-Z]" -- "*.py" "*.md" |
sed "s/$/ uses max instead of 3ds Max/g"
git grep -n "[^a-zA-Z_\`.]python[^a-zA-Z_]" -- "*.md" |
sed "s/$/: python should be spelled Python/g"
}
checkmdlinks() {
file=$1
filedir=$(dirname "$file")
# iterate all links in the file
for link in $(grep -n -o "\[[^]]*\]([^)]*)" "$file")
do
url=$(echo "$link" | sed -e "s/^[^:]*://" -e "s/\[[^]]*\]//" -e "s/^(//" -e "s/)$//")
line=$(echo "$link" | grep -o "^[^:]*")
if [[ "$url" =~ ^https?:.* ]]
then
if ! curl --output /dev/null --silent --head "$url"
then
echo "$file:$line: Broken url (no head): $url"
fi
elif [[ "$url" =~ ^/.* ]]
then
if [ ! -e "$workdir$url" ]
then
echo "$file$line: Broken absolute link: $url"
fi
else
if [ ! -e "$filedir/$url" ]
then
echo "$file:$line: Broken relative link: $url"
fi
fi
done
}
checkmarkdownlinks() {
# iterate all matching markdown files in the repo
for f in $(git grep --name-only "\[[^]]*\]([^)]*)" -- "*.md")
do
checkmdlinks "$f"
done
}
lint
lintsamples
checkmarkdown
checkmarkdownlinks