forked from Zamiell/babies-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint.sh
executable file
·89 lines (72 loc) · 2.5 KB
/
lint.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
#!/bin/bash
set -euo pipefail # Exit on errors and undefined variables.
# Get the directory of this script:
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Get the name of the repository:
# https://stackoverflow.com/questions/23162299/how-to-get-the-last-part-of-dirname-in-bash/23162553
REPO_NAME="$(basename "$DIR")"
SECONDS=0
cd "$DIR"
# Use Prettier to check formatting.
# "--log-level=warn" makes it only output errors.
npx prettier --log-level=warn --check .
# Use ESLint to lint the TypeScript.
# "--max-warnings 0" makes warnings fail in CI, since we set all ESLint errors to warnings.
npx eslint --max-warnings 0 .
# Check for unused exports.
# "--error" makes it return an error code of 1 if unused exports are found.
# @template-ignore-next-line
npx ts-prune --error --ignore "characterCostumeProtector.d.ts" # We ignore library definition files.
# Use `isaac-xml-validator` to validate XML files.
# (Skip this step if Python is not currently installed for whatever reason.)
if command -v python &> /dev/null; then
pip install isaac-xml-validator --upgrade --quiet
isaac-xml-validator --quiet
fi
# Spell check every file using CSpell.
# "--no-progress" and "--no-summary" make it only output errors.
npx cspell --no-progress --no-summary .
# Check for unused CSpell words.
npx cspell-check-unused-words
# @template-customization-start
# Check for base file updates.
npx isaacscript check
# Check for Windows-style line endings.
WINDOWS_FILES=$(
grep \
--recursive \
--files-with-matches \
--binary \
--perl-regexp \
--exclude-dir='.git' \
--exclude-dir='.yarn' \
--exclude-dir='node_modules' \
--exclude='*.fnt' \
--exclude='*.jpg' \
--exclude='*.png' \
--exclude='*.pyc' \
--exclude='*.stb' \
--exclude='*.ttf' \
--exclude='*.wav' \
--exclude='yarn.lock' \
'\r$' .
) || true
if [[ $WINDOWS_FILES ]]; then
echo "Files with Windows line-endings were found:"
echo "$WINDOWS_FILES"
exit 1
fi
# Check that the documentation is up to date.
DOCS="$DIR/docs/babies.md"
TMP_DOCS="/tmp/babies.md"
cp "$DOCS" "$TMP_DOCS"
bash "$DIR/scripts/generateDocs.sh"
if ! cmp "$DOCS" "$TMP_DOCS" --silent; then
echo 'The Markdown documentation is not up to date. Please run the "generateDocs.sh" script and then commit the changes.'
diff "$DOCS" "$TMP_DOCS"
exit 1
fi
rm -f "$TMP_DOCS"
# @template-customization-end
echo "Successfully linted $REPO_NAME in $SECONDS seconds."