@@ -46,6 +46,15 @@ eslint_tests_conf="${root}/etc/eslint/.eslintrc.tests.js"
4646# Define the path to ESLint configuration file for linting benchmarks:
4747eslint_benchmarks_conf=" ${root} /etc/eslint/.eslintrc.benchmarks.js"
4848
49+ # Define the path to cppcheck configuration file for linting examples:
50+ cppcheck_examples_suppressions_list=" ${root} /etc/cppcheck/suppressions.examples.txt"
51+
52+ # Define the path to cppcheck configuration file for linting test fixtures:
53+ cppcheck_tests_fixtures_suppressions_list=" ${root} /etc/cppcheck/suppressions.tests_fixtures.txt"
54+
55+ # Define the path to cppcheck configuration file for linting benchmarks:
56+ cppcheck_benchmarks_suppressions_list=" ${root} /etc/cppcheck/suppressions.benchmarks.txt"
57+
4958
5059# FUNCTIONS #
5160
@@ -217,8 +226,8 @@ run_lint() {
217226 fi
218227 fi
219228
220- # Lint C files...
221- files=$( echo " ${changed_files} " | grep ' \.c$' | tr ' \n' ' ' )
229+ # Lint C source files...
230+ files=$( echo " ${changed_files} " | grep ' \.c$' | grep -v -e ' /examples ' -e ' /test ' -e ' /benchmark ' | tr ' \n' ' ' )
222231 if [[ -n " ${files} " ]]; then
223232 make check-c-linters > /dev/null >&2
224233 if [[ " $? " -ne 0 ]]; then
@@ -228,7 +237,58 @@ run_lint() {
228237 make FILES=" ${files} " lint-c-files > /dev/null >&2
229238 if [[ " $? " -ne 0 ]]; then
230239 echo ' ' >&2
231- echo ' C lint errors.' >&2
240+ echo ' C lint errors for source files.' >&2
241+ return 1
242+ fi
243+ fi
244+ fi
245+
246+ # Lint C examples files...
247+ files=$( echo " ${changed_files} " | grep ' /examples/.*\.c$' | tr ' \n' ' ' )
248+ if [[ -n " ${files} " ]]; then
249+ make check-c-linters > /dev/null >&2
250+ if [[ " $? " -ne 0 ]]; then
251+ echo ' ' >&2
252+ echo ' Unable to lint C files. Ensure that linters are installed.' >&2
253+ else
254+ make C_LINTER=cppcheck CPPCHECK_SUPPRESSIONS_LIST=" ${cppcheck_examples_suppressions_list} " FILES=" ${files} " lint-c-files > /dev/null >&2
255+ if [[ " $? " -ne 0 ]]; then
256+ echo ' ' >&2
257+ echo ' C lint errors for examples files.' >&2
258+ return 1
259+ fi
260+ fi
261+ fi
262+
263+ # Lint C benchmark files...
264+ files=$( echo " ${changed_files} " | grep ' /benchmark/.*\.c$' | tr ' \n' ' ' )
265+ if [[ -n " ${files} " ]]; then
266+ make check-c-linters > /dev/null >&2
267+ if [[ " $? " -ne 0 ]]; then
268+ echo ' ' >&2
269+ echo ' Unable to lint C files. Ensure that linters are installed.' >&2
270+ else
271+ make C_LINTER=cppcheck CPPCHECK_SUPPRESSIONS_LIST=" ${cppcheck_benchmarks_suppressions_list} " FILES=" ${files} " lint-c-files > /dev/null >&2
272+ if [[ " $? " -ne 0 ]]; then
273+ echo ' ' >&2
274+ echo ' C lint errors for benchmark files.' >&2
275+ return 1
276+ fi
277+ fi
278+ fi
279+
280+ # Lint C test fixtures files...
281+ files=$( echo " ${changed_files} " | grep ' /test/fixtures/.*\.c$' | tr ' \n' ' ' )
282+ if [[ -n " ${files} " ]]; then
283+ make check-c-linters > /dev/null >&2
284+ if [[ " $? " -ne 0 ]]; then
285+ echo ' ' >&2
286+ echo ' Unable to lint C files. Ensure that linters are installed.' >&2
287+ else
288+ make C_LINTER=cppcheck CPPCHECK_SUPPRESSIONS_LIST=" ${cppcheck_tests_fixtures_suppressions_list} " FILES=" ${files} " lint-c-files > /dev/null >&2
289+ if [[ " $? " -ne 0 ]]; then
290+ echo ' ' >&2
291+ echo ' C lint errors for test fixtures files.' >&2
232292 return 1
233293 fi
234294 fi
0 commit comments