[pretty] add markdown support (#4881)
This commit is contained in:
parent
32f8274395
commit
c48f84d9ea
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"$schema": "http://json.schemastore.org/prettierrc",
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"proseWrap": "never"
|
||||
}
|
|
@ -30,30 +30,37 @@
|
|||
#
|
||||
# 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()
|
||||
{
|
||||
|
@ -61,7 +68,7 @@ do_clang_format()
|
|||
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 prettier@2.0.4 --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 prettier@2.0.4 --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
|
||||
|
|
Loading…
Reference in New Issue