summaryrefslogtreecommitdiffstats
path: root/extras
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-11-20 01:08:20 +0800
committerGitHub <noreply@github.com>2024-11-19 09:08:20 -0800
commit0bf6a668208c65c980648fbe74a8c0a7bf4ded77 (patch)
tree02e3a58af7561daed342c1362aef8b5aaad8e489 /extras
parenta50de6bd32de1b064874480a2528fc994597f7ac (diff)
Markdown emphasis corrections (#5588)
* Add markdown formatting to extras/formatting.sh * Correct formatting in markdown * Warn on unrecognized argument in formatting script * Print all diffs in formatting script * Correct markdown emph formatting * Don't format markdown by default --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'extras')
-rwxr-xr-xextras/formatting.sh80
1 files changed, 54 insertions, 26 deletions
diff --git a/extras/formatting.sh b/extras/formatting.sh
index 8e44eea81..f6a3134aa 100755
--- a/extras/formatting.sh
+++ b/extras/formatting.sh
@@ -9,13 +9,36 @@ check_only=0
no_version_check=0
run_cpp=0
run_yaml=0
+run_markdown=0
run_sh=0
run_cmake=0
run_all=1
+show_help() {
+ me=$(basename "$0")
+ cat <<EOF
+$me: Format or check formatting of files in this repo
+
+Usage: $me [--check-only] [--no-version-check] [--source <path>] [--cpp] [--yaml] [--md] [--sh] [--cmake]
+
+Options:
+ --check-only Check formatting without modifying files
+ --no-version-check Skip version compatibility checks
+ --source Path to source directory to format (defaults to parent of script directory)
+ --cpp Format only C++ files
+ --yaml Format only YAML/JSON files
+ --md Format only markdown files
+ --sh Format only shell script files
+ --cmake Format only CMake files
+EOF
+}
+
while [[ "$#" -gt 0 ]]; do
case $1 in
- -h | --help) help=1 ;;
+ -h | --help)
+ show_help
+ exit 0
+ ;;
--check-only) check_only=1 ;;
--no-version-check) no_version_check=1 ;;
--cpp)
@@ -26,6 +49,10 @@ while [[ "$#" -gt 0 ]]; do
run_yaml=1
run_all=0
;;
+ --md)
+ run_markdown=1
+ run_all=0
+ ;;
--sh)
run_sh=1
run_all=0
@@ -38,29 +65,15 @@ while [[ "$#" -gt 0 ]]; do
source_dir="$2"
shift
;;
+ *)
+ echo "unrecognized argument: $1"
+ show_help
+ exit 1
+ ;;
esac
shift
done
-if [ "$help" ]; then
- me=$(basename "$0")
- cat <<EOF
-$me: Format or check formatting of files in this repo
-
-Usage: $me [--check-only] [--no-version-check] [--source <path>] [--cpp] [--yaml] [--sh] [--cmake]
-
-Options:
- --check-only Check formatting without modifying files
- --no-version-check Skip version compatibility checks
- --source Path to source directory to format (defaults to parent of script directory)
- --cpp Format only C++ files
- --yaml Format only YAML/JSON files
- --sh Format only shell script files
- --cmake Format only CMake files
-EOF
- exit 0
-fi
-
cd "$source_dir" || exit 1
require_bin() {
@@ -177,18 +190,16 @@ cpp_formatting() {
fi
}
-yaml_json_formatting() {
- echo "Formatting yaml and json files..." >&2
-
- readarray -t files < <(git ls-files "*.yaml" "*.yml" "*.json" ':!external/**')
-
+# Format the 'files' array using the prettier tool (abstracted here because
+# it's used by markdown and json
+prettier_formatting() {
if [ "$check_only" -eq 1 ]; then
for file in "${files[@]}"; do
if ! output=$(prettier "$file" 2>/dev/null); then
continue
fi
if ! diff -q "$file" <(echo "$output") >/dev/null 2>&1; then
- diff --color -u --label "$file" --label "$file" "$file" <(echo "$output")
+ diff --color -u --label "$file" --label "$file" "$file" <(echo "$output") || :
exit_code=1
fi
done
@@ -197,6 +208,22 @@ yaml_json_formatting() {
fi
}
+yaml_json_formatting() {
+ echo "Formatting yaml and json files..." >&2
+
+ readarray -t files < <(git ls-files "*.yaml" "*.yml" "*.json" ':!external/**')
+
+ prettier_formatting
+}
+
+markdown_formatting() {
+ echo "Formatting markdown files..." >&2
+
+ readarray -t files < <(git ls-files "*.md" ':!external/**')
+
+ prettier_formatting
+}
+
sh_formatting() {
echo "Formatting sh files..." >&2
@@ -217,6 +244,7 @@ sh_formatting() {
((run_all || run_sh)) && sh_formatting
((run_all || run_cmake)) && cmake_formatting
((run_all || run_yaml)) && yaml_json_formatting
+((run_markdown)) && markdown_formatting
((run_all || run_cpp)) && cpp_formatting
exit $exit_code