From 0b1883778e56951b1cac1601758824d36d3fac63 Mon Sep 17 00:00:00 2001 From: mose-zm <602187256@qq.com> Date: Tue, 28 Jul 2026 08:47:49 +0000 Subject: [PATCH] fix: hint when detected lang has no lang_tools entry Distinguish no-entry (print hint) from empty value (silent skip). Non-fatal: unconfigured lang is not a policy violation. --- lang-runner.sh | 17 +++++++++++++++-- load-config.sh | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lang-runner.sh b/lang-runner.sh index c11291f..dc8422f 100644 --- a/lang-runner.sh +++ b/lang-runner.sh @@ -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}=' to hook-rules.conf" >&2 + return 0 + fi if ! _lang_tool_available "$cmd"; then local tool="${cmd%% *}" diff --git a/load-config.sh b/load-config.sh index 155a7db..21af637 100644 --- a/load-config.sh +++ b/load-config.sh @@ -112,6 +112,23 @@ get_rule() { ' } +# 0 if [lang_tools] has at least one entry whose lang matches +# (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 exists and has at least one non-comment entry. config_section_nonempty() { local section="$1"