Skip to content

Commit f3007a6

Browse files
sfowlclaude
andcommitted
feat(shellcheck): add SC_SKIP_JINJA option to skip Jinja2 templates
ShellCheck cannot parse Jinja2 template syntax ({{ }}, {% %}, {# #}). Any file containing these constructs breaks the parser entirely, producing unreliable findings (SC1054, SC1073, SC1083). Setting SC_SKIP_JINJA=1 causes filter_shell_scripts() to exclude these files before they reach shellcheck. Disabled by default so existing behavior is unchanged. Tested against https://github.com/openshift/cac-content-fork where findings dropped from 11,776 to 43 (99.6% noise reduction). Resolves: PSSECAUT-1577 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8203630 commit f3007a6

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

scripts/run-shellcheck.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export SC_JOBS
1515
test -n "$SC_TIMEOUT" || export SC_TIMEOUT=30
1616
test 0 -lt "$SC_TIMEOUT" || exit $?
1717

18+
# skip files containing Jinja2 template syntax ({{ }}, {% %}, {# #})
19+
test -n "$SC_SKIP_JINJA" || export SC_SKIP_JINJA=0
20+
1821
# directory for shellcheck results
1922
test -n "$SC_RESULTS_DIR" || export SC_RESULTS_DIR="./shellcheck-results"
2023

@@ -62,22 +65,33 @@ filter_shell_scripts() {
6265
# match by file name suffix
6366
if [[ "$i" =~ ^.*\.(ash|bash|bats|dash|ksh|sh)$ ]]; then
6467
echo "$i"
65-
echo -n . >&2
6668
continue
6769
fi
6870

6971
# match by shebang (executable files only)
7072
RE_SHEBANG='^\s*((#|!)|(#\s*!)|(!\s*#))\s*(/usr(/local)?)?/bin/(env\s+)?(ash|bash|bats|dash|ksh|sh)\b'
7173
if test -x "$i" && head -n1 "$i" | grep -qE --text "$RE_SHEBANG"; then
7274
echo "$i"
73-
echo -n . >&2
7475
fi
7576
done
7677
}
7778

79+
apply_exclusion() {
80+
while read -r i; do
81+
# skip Jinja2 templates if requested
82+
if [ "$SC_SKIP_JINJA" -eq 1 ] && grep -qE '\{\{|\{%|\{#' "$i" 2>/dev/null; then
83+
continue
84+
fi
85+
86+
echo "$i"
87+
echo -n . >&2
88+
done
89+
}
90+
7891
# store a script that filters shell scripts to a variable
7992
FILTER_SCRIPT="$(declare -f filter_shell_scripts)
80-
filter_shell_scripts"' "$@"'
93+
$(declare -f apply_exclusion)
94+
filter_shell_scripts"' "$@" | apply_exclusion'
8195

8296
# function that creates a separate JSON file if shellcheck detects anything
8397
wrap_shellcheck() {

0 commit comments

Comments
 (0)