forked from fantaisie-software/purebasic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate.sh
140 lines (124 loc) · 5.27 KB
/
validate.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
# "validate.sh" by Tristano Ajmone v3.0.0 | 2020/02/08
#-------------------------------------------------------------------------------
# 1. Check that PureBasic sources don't contain saved IDE settings.
# 2. Validate code style consistency in the repository via EditorConfig settings
# and the EClint validator tool:
# https://editorconfig.org
# https://www.npmjs.com/package/eclint
#-------------------------------------------------------------------------------
# *******************************************
# 1. Check PureBasic Sources for IDE Settings
# *******************************************
echo -e "\n\033[34;1m==========================================="
echo -e "\033[33;1mChecking PureBasic Sources for IDE Settings "
echo -e "\033[34;1m===========================================\033[0m"
tmpLog=$(mktemp)
passed=true
for pbfile in $(find . -name '*.pb' -o \
-name '*.pbi' -o \
-name '*.pbf' );
do
result="$(grep -c '^; IDE Options =' $pbfile)"
if [ "$result" != "0" ] ; then
echo "$pbfile" >> $tmpLog
passed=
fi
done
if [ "$passed" != true ] ; then
echo -e "\033[31;1m~~~ ERROR! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "\033[31;1mThe following files contain IDE settings:\n\033[33;1m"
cat $tmpLog
rm $tmpLog
echo -e "\033[31;1m\nPlease change your PureBasic IDE preferences for:"
echo -e "\033[37;1m Editor \033[34;1m>\033[37;1m Save Settings to \033[34;1m>\033[37;1m The end of the source file"
echo -e "\033[31;1mto some other option in order to prevent this from happening."
echo -e "\033[31;1m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "\033[31;1m/// Aborting All Tests ///\033[0m"
exit 1
fi
echo -e "\033[32;1m/// Test Passed ///\033[0m"
rm $tmpLog
# **************************************************
# 2. Check PureBasic Sources for Trailing Whitespace
# **************************************************
# Currently EditorConfig can't be used to check for the presence of trailing
# whitespace due to the PureBasic IDE indenting empty lines that precede an
# indented line, which EClint would consider as trailing whitespace.
# (see editorconfig/editorconfig#238)
#
# So we have to grep all PB sources looking for trailing spaces in lines that
# contain at least one non-space/tab character...
echo -e "\n\033[34;1m=================================================="
echo -e "\033[33;1mChecking PureBasic Sources for Trailing Whitespace "
echo -e "\033[34;1m==================================================\033[0m"
tmpLog=$(mktemp)
passed=true
for pbfile in $(find . -name '*.pb' -o \
-name '*.pbi' -o \
-name '*.pbf' );
do
result="$(grep -cE '[^ \\t].*( |\\t)+[[:cntrl:]]*$' $pbfile)"
if [ "$result" != "0" ] ; then
echo "$pbfile" >> $tmpLog
passed=
fi
done
if [ "$passed" != true ] ; then
echo -e "\033[31;1m~~~ ERROR! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "\033[31;1mThe following files contain trailing whitespace:\n\033[33;1m"
cat $tmpLog
rm $tmpLog
echo -e "\033[31;1m\nPlease clean up your sources and fix the problem."
echo -e "\033[31;1m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "\033[31;1m/// Aborting All Tests ///\033[0m"
exit 1
fi
echo -e "\033[32;1m/// Test Passed ///\033[0m"
rm $tmpLog
# *******************************************
# 3. Check Sources for Code Style Consistency
# *******************************************
echo -e "\n\033[34;1m================================================"
echo -e "\033[33;1mValidating Code Styles via EditorConfig Settings"
echo -e "\033[34;1m================================================\033[0m"
# ==================
# Check Dependencies
# ==================
# Since the script might also be run locally by end users, check that EClint is
# installed on the user machine:
if eclint --version > /dev/null 2>&1 ; then
echo -e "Using:"
echo -e "\033[34;1m*\033[35m Node.js $(node -v)"
echo -e "\033[34;1m*\033[35m EClint v$(eclint --version).\n\033[31;1m"
else
echo -e "\033[31;1m~~~ ERROR! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "\033[31;1mIn order to run this script you need to install EClint (Node.js):\n"
echo -e "\033[31;1m\thttps://www.npmjs.com/package/eclint"
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m"
echo -e "If you've already installed Node.js on your machine, type:\n"
echo -e "\033[33;1m\tnpm install -g eclint"
echo -e "\033[31;1m\n/// Aborting All Tests ///\033[0m"
exit 1
fi
# ==============
# Validate Files
# ==============
# Check that project files meet the code style standards set in `.editorconfig`;
# if not, print only the list of files that failed -- because EClint reports are
# usually too long.
tmpLog=$(mktemp)
eclint check 2> $tmpLog || {
echo -e "\033[31;1m~~~ ERROR! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
echo -e "\033[31;1mThe following files didn't pass the validation test:\n\033[33;1m";
cat $tmpLog | grep "^[^ ]";
echo -e "\033[31;1m\nRun ECLint locally for detailed information about the problems.";
echo -e "\033[31;1m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
echo -e "\033[31;1m/// Aborting All Tests ///\033[0m";
rm $tmpLog;
exit 1;
}
rm $tmpLog;
echo -e "\033[32;1m/// Test Passed ///\033[0m"
exit
# EOF #