Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lang-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,21 @@ run_lang_stage() {
local cmd

cmd=$(get_lang_tool "$lang" "$stage")
# Empty value -> stage intentionally disabled for this language.
[ -z "$cmd" ] && return 0
# Empty value: two distinct cases.
if [ -z "$cmd" ]; then
if has_lang_any_tool "$lang"; then
# Intentional disable (entry exists with empty value, e.g.
# `java:fmt=`). Silent skip, same as before.
return 0
fi
# Detected language but no [lang_tools] entry at all. Print a
# hint so the user knows their .php/.pl/.cs/... changes are not
# being checked, and how to enable them. Non-fatal (return 0):
# an unconfigured language is not a policy violation.
echo " $lang $stage: detected but no [lang_tools] entry -- skipped." >&2
echo " to enable, add '${lang}:${stage}=<cmd>' to hook-rules.conf" >&2
return 0
fi

if ! _lang_tool_available "$cmd"; then
local tool="${cmd%% *}"
Expand Down
17 changes: 17 additions & 0 deletions load-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ get_rule() {
'
}

# 0 if [lang_tools] has at least one entry whose lang matches <lang>
# (any stage, value may be empty). Distinguishes "no entry at all"
# (detected language is unconfigured -> lang-runner prints a hint) from
# "entry with empty value" (intentional disable -> silent skip).
# Format checked: `lang:stage=...` (colon before `=`).
has_lang_any_tool() {
local lang="$1"
local line l colon
while IFS= read -r line; do
colon=$(printf '%s' "$line" | awk '{ i=index($0,":"); if(i>0) print substr($0,1,i-1) }')
if [ "$colon" = "$lang" ]; then
return 0
fi
done < <(_section_lines lang_tools)
return 1
}

# 0 if section <s> exists and has at least one non-comment entry.
config_section_nonempty() {
local section="$1"
Expand Down
Loading