Skip to content
Merged
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
26 changes: 11 additions & 15 deletions content-guards/scripts/validate-markdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

set -euo pipefail

# Fail open if jq is unavailable
if ! command -v jq &>/dev/null; then
exit 0
fi

# Extract the file path from stdin, which contains the hook input JSON
file_path=$(jq -r '.tool_input.file_path // empty')

Expand Down Expand Up @@ -50,27 +55,18 @@ if command -v markdownlint-cli2 &>/dev/null; then
config_flag=()
has_project_config=false

# Walk up from the file's directory looking for project-level config
# Check for project-level markdownlint config (walk up from file's directory)
search_dir="$(dirname -- "$file_path")"
while true; do
if [[ -f "$search_dir/.markdownlint-cli2.yaml" ]] ||
[[ -f "$search_dir/.markdownlint-cli2.jsonc" ]] ||
[[ -f "$search_dir/.markdownlint-cli2.cjs" ]] ||
[[ -f "$search_dir/.markdownlint-cli2.mjs" ]] ||
[[ -f "$search_dir/.markdownlint.json" ]] ||
[[ -f "$search_dir/.markdownlint.jsonc" ]] ||
[[ -f "$search_dir/.markdownlint.yaml" ]] ||
[[ -f "$search_dir/.markdownlint.yml" ]] ||
[[ -f "$search_dir/.markdownlint.cjs" ]] ||
[[ -f "$search_dir/.markdownlint.mjs" ]]; then
shopt -s nullglob
config_files=("$search_dir"/.markdownlint*)
shopt -u nullglob
if ((${#config_files[@]} > 0)); then
has_project_config=true
break
fi

parent_dir="$(dirname -- "$search_dir")"
if [[ "$parent_dir" == "$search_dir" ]]; then
break
fi
[[ "$parent_dir" == "$search_dir" ]] && break
search_dir="$parent_dir"
done

Expand Down
Loading