forked from purpleidea/mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-markdownlint.sh
executable file
·79 lines (64 loc) · 2.1 KB
/
test-markdownlint.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
#!/bin/bash
# check for any markdown files that aren't in an ideal format
echo running "$0 $*"
set -o errexit
set -o nounset
set -o pipefail
#ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir!
ROOT=$(dirname "${BASH_SOURCE[0]}")/..
cd "${ROOT}" || exit 1
. test/util.sh
MDL=$(command -v mdl 2>/dev/null) || true
if [ -z "$MDL" ]; then
fail_test "The 'mdl' utility can't be found."
fi
STYLE=$($mktemp)
# styles that we ignore... if they're too onerous, we can exclude them here...
cat << 'EOF' > "$STYLE"
all
exclude_rule 'MD010' # Hard tabs
exclude_rule 'MD032' # Lists should be surrounded by blank lines
exclude_rule 'MD040' # Fenced code blocks should have a language specified
exclude_rule 'MD026' # Trailing punctuation in header
exclude_rule 'MD024' # Multiple headers with the same content
exclude_rule 'MD002' # First header should be a top level header
exclude_rule 'MD041' # First line in file should be a top level header
exclude_rule 'MD007' # Unordered list indentation
# FIXME: no idea why this issue occurs
exclude_rule 'MD029' # Ordered list item prefix
# FIXME: bug: https://github.com/markdownlint/markdownlint/issues/182
exclude_rule 'MD039' # Spaces inside link text
# Line length
rule 'MD013', :line_length => 80, :code_blocks => false, :tables => false
EOF
#STYLE="test/mdl.style" # style file
find_files() {
git ls-files | grep '\.md$'
}
F=${1:-} # only check this file from $1 is specified
bad_files=$(
for i in $(find_files); do
if [ "$F" != "" ] && [ "$F" != "$i" ]; then
continue
fi
# search for more than one leading space, to ensure we use tabs
if grep -q '^ ' "$i"; then
echo "$i: MDX042: Leading spaces found instead of tabs" 1>&2
echo "$i"
fi
# check the markdown format with the linter
if ! "$MDL" --style "$STYLE" "$i" 1>&2; then
echo "$i"
fi
done
)
# cleanup
if [ -e "$STYLE" ]; then
rm "$STYLE"
fi
if [[ -n "${bad_files}" ]]; then
# see a description of the rules at:
# https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md
fail_test "The following markdown files are not properly formatted:\n${bad_files}"
fi
echo 'PASS'