-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pretty] add markdown support (#4881)
- Loading branch information
Showing
2 changed files
with
56 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/prettierrc", | ||
"printWidth": 80, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"proseWrap": "never" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,38 +30,45 @@ | |
# | ||
# The script to check or format source code of OpenThread. | ||
# | ||
# Format python and c/c++: | ||
# Format c/c++, markdown, and python: | ||
# | ||
# script/make-pretty | ||
# | ||
# Format python only: | ||
# | ||
# script/make-pretty python | ||
# | ||
# Format c/c++ only: | ||
# | ||
# script/make-pretty clang | ||
# | ||
# Format markdown only: | ||
# | ||
# script/make-pretty markdown | ||
# | ||
# Format python only: | ||
# | ||
# script/make-pretty python | ||
# | ||
# Check only: | ||
# | ||
# script/make-pretty check clang | ||
# script/make-pretty check markdown | ||
# script/make-pretty check python | ||
# | ||
|
||
set -euo pipefail | ||
|
||
readonly OT_CLANG_DIRS=(examples include src tests tools) | ||
readonly OT_PYTHON_DIRS=(tests tools) | ||
readonly OT_BUILD_JOBS=$(getconf _NPROCESSORS_ONLN) | ||
readonly OT_EXCLUDE_DIRS=(third_party) | ||
|
||
readonly OT_CLANG_SOURCES=('*.c' '*.cc' '*.cpp' '*.h' '*.hpp') | ||
readonly OT_MARKDOWN_SOURCES=('*.md') | ||
readonly OT_PYTHON_SOURCES=('*.py') | ||
|
||
do_clang_format() | ||
{ | ||
echo -e '=====================' | ||
echo -e ' format c/c++' | ||
echo -e '=====================' | ||
|
||
git ls-files "${OT_CLANG_SOURCES[@]}" | grep -E "^($(echo "${OT_CLANG_DIRS[@]}" | tr ' ' '|'))" \ | ||
git ls-files "${OT_CLANG_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \ | ||
| xargs -n3 -P"${OT_BUILD_JOBS}" script/clang-format -style=file -i -verbose | ||
} | ||
|
||
|
@@ -71,17 +78,37 @@ do_clang_check() | |
echo -e ' check c/c++' | ||
echo -e '=====================' | ||
|
||
git ls-files "${OT_CLANG_SOURCES[@]}" | grep -E "^($(echo "${OT_CLANG_DIRS[@]}" | tr ' ' '|'))" \ | ||
git ls-files "${OT_CLANG_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \ | ||
| xargs -n3 -P"${OT_BUILD_JOBS}" script/clang-format-check | ||
} | ||
|
||
do_markdown_format() | ||
{ | ||
echo -e '======================' | ||
echo -e ' format markdown' | ||
echo -e '======================' | ||
|
||
git ls-files "${OT_MARKDOWN_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \ | ||
| xargs -n10 -P"${OT_BUILD_JOBS}" npx [email protected] --write | ||
} | ||
|
||
do_markdown_check() | ||
{ | ||
echo -e '======================' | ||
echo -e ' check markdown' | ||
echo -e '======================' | ||
|
||
git ls-files "${OT_MARKDOWN_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \ | ||
| xargs -n10 -P"${OT_BUILD_JOBS}" npx [email protected] --check | ||
} | ||
|
||
do_python_format() | ||
{ | ||
echo -e '======================' | ||
echo -e ' format python' | ||
echo -e '======================' | ||
|
||
git ls-files '*.py' | grep -E "^($(echo "${OT_PYTHON_DIRS[@]}" | tr ' ' '|'))" \ | ||
git ls-files "${OT_PYTHON_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \ | ||
| xargs -n10 -P"${OT_BUILD_JOBS}" python3 -m yapf --verbose --style google -ipr | ||
} | ||
|
||
|
@@ -91,21 +118,24 @@ do_python_check() | |
echo -e ' check python' | ||
echo -e '=====================' | ||
|
||
git ls-files '*.py' | grep -E "^($(echo "${OT_PYTHON_DIRS[@]}" | tr ' ' '|'))" \ | ||
git ls-files "${OT_PYTHON_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \ | ||
| xargs -n10 -P"${OT_BUILD_JOBS}" python3 -m yapf --verbose --style google -dpr | ||
} | ||
|
||
do_check() | ||
{ | ||
if [ $# == 0 ]; then | ||
do_python_check | ||
do_clang_check | ||
do_markdown_check | ||
do_python_check | ||
elif [ "$1" == 'clang' ]; then | ||
do_clang_check | ||
elif [ "$1" == 'markdown' ]; then | ||
do_markdown_check | ||
elif [ "$1" == 'python' ]; then | ||
do_python_check | ||
else | ||
>&2 echo "Unsupported check: $1. Supported: clang, python" | ||
>&2 echo "Unsupported check: $1. Supported: clang, markdown, python" | ||
# 128 for Invalid arguments | ||
exit 128 | ||
fi | ||
|
@@ -115,16 +145,19 @@ main() | |
{ | ||
if [ $# == 0 ]; then | ||
do_clang_format | ||
do_python_format | ||
elif [ "$1" == 'python' ]; then | ||
do_markdown_format | ||
do_python_format | ||
elif [ "$1" == 'clang' ]; then | ||
do_clang_format | ||
elif [ "$1" == 'markdown' ]; then | ||
do_markdown_format | ||
elif [ "$1" == 'python' ]; then | ||
do_python_format | ||
elif [ "$1" == 'check' ]; then | ||
shift | ||
do_check "$@" | ||
else | ||
>&2 echo "Unsupported action: $1. Supported: clang, python" | ||
>&2 echo "Unsupported action: $1. Supported: clang, markdown, python" | ||
# 128 for Invalid arguments | ||
exit 128 | ||
fi | ||
|