From b0abaa99e4512dab21fb0afecc293396ed264511 Mon Sep 17 00:00:00 2001 From: storypku Date: Tue, 1 Sep 2020 10:03:39 -0700 Subject: [PATCH] Scripts: use mdfmt to format json/md/yml also --- scripts/mdfmt.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/mdfmt.sh b/scripts/mdfmt.sh index 181af605a1..ad7b6a1d65 100755 --- a/scripts/mdfmt.sh +++ b/scripts/mdfmt.sh @@ -39,13 +39,19 @@ function check_if_tools_installed() { function format_markdown_by_prettier() { for mypath in "$@"; do if [ -d "${mypath}" ]; then - find "${mypath}" -type f -name "*.md" -exec npx prettier --write {} + - elif [[ -f "${mypath}" && "${mypath##*.}" == "md" ]]; then - npx prettier --write "${mypath}" + find "${mypath}" -type f \( -name "*.md" \ + -or -name "*.json" \ + -or -name "*.yml" \) \ + -exec npx prettier --write {} + + elif [ -f "${mypath}" ]; then + local ext="${mypath##*.}" + if [[ "${ext}" == "md" || "${ext}" == "yml" || "${ext}" == "json" ]]; then + npx prettier --write "${mypath}" + else + warning "Only regular md/json/yml files will be formatted. Ignored ${mypath}" + fi else - warning "Only regular markdown files with '.md' extension will be" \ - "formatted, Got: ${mypath}" - exit 1 + warning "Special/Symlink file won't be formatted. Ignored ${mypath}" fi done } -- GitLab