mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[pretty] add markdown support (#4881)
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json.schemastore.org/prettierrc",
|
||||||
|
"printWidth": 80,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"proseWrap": "never"
|
||||||
|
}
|
||||||
+49
-16
@@ -30,30 +30,37 @@
|
|||||||
#
|
#
|
||||||
# The script to check or format source code of OpenThread.
|
# The script to check or format source code of OpenThread.
|
||||||
#
|
#
|
||||||
# Format python and c/c++:
|
# Format c/c++, markdown, and python:
|
||||||
#
|
#
|
||||||
# script/make-pretty
|
# script/make-pretty
|
||||||
#
|
#
|
||||||
# Format python only:
|
|
||||||
#
|
|
||||||
# script/make-pretty python
|
|
||||||
#
|
|
||||||
# Format c/c++ only:
|
# Format c/c++ only:
|
||||||
#
|
#
|
||||||
# script/make-pretty clang
|
# script/make-pretty clang
|
||||||
#
|
#
|
||||||
|
# Format markdown only:
|
||||||
|
#
|
||||||
|
# script/make-pretty markdown
|
||||||
|
#
|
||||||
|
# Format python only:
|
||||||
|
#
|
||||||
|
# script/make-pretty python
|
||||||
|
#
|
||||||
# Check only:
|
# Check only:
|
||||||
#
|
#
|
||||||
# script/make-pretty check clang
|
# script/make-pretty check clang
|
||||||
|
# script/make-pretty check markdown
|
||||||
# script/make-pretty check python
|
# script/make-pretty check python
|
||||||
#
|
#
|
||||||
|
|
||||||
set -euo pipefail
|
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_BUILD_JOBS=$(getconf _NPROCESSORS_ONLN)
|
||||||
|
readonly OT_EXCLUDE_DIRS=(third_party)
|
||||||
|
|
||||||
readonly OT_CLANG_SOURCES=('*.c' '*.cc' '*.cpp' '*.h' '*.hpp')
|
readonly OT_CLANG_SOURCES=('*.c' '*.cc' '*.cpp' '*.h' '*.hpp')
|
||||||
|
readonly OT_MARKDOWN_SOURCES=('*.md')
|
||||||
|
readonly OT_PYTHON_SOURCES=('*.py')
|
||||||
|
|
||||||
do_clang_format()
|
do_clang_format()
|
||||||
{
|
{
|
||||||
@@ -61,7 +68,7 @@ do_clang_format()
|
|||||||
echo -e ' format c/c++'
|
echo -e ' format c/c++'
|
||||||
echo -e '====================='
|
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
|
| 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 ' check c/c++'
|
||||||
echo -e '====================='
|
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
|
| 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()
|
do_python_format()
|
||||||
{
|
{
|
||||||
echo -e '======================'
|
echo -e '======================'
|
||||||
echo -e ' format python'
|
echo -e ' format python'
|
||||||
echo -e '======================'
|
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
|
| 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 ' check python'
|
||||||
echo -e '====================='
|
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
|
| xargs -n10 -P"${OT_BUILD_JOBS}" python3 -m yapf --verbose --style google -dpr
|
||||||
}
|
}
|
||||||
|
|
||||||
do_check()
|
do_check()
|
||||||
{
|
{
|
||||||
if [ $# == 0 ]; then
|
if [ $# == 0 ]; then
|
||||||
do_python_check
|
|
||||||
do_clang_check
|
do_clang_check
|
||||||
|
do_markdown_check
|
||||||
|
do_python_check
|
||||||
elif [ "$1" == 'clang' ]; then
|
elif [ "$1" == 'clang' ]; then
|
||||||
do_clang_check
|
do_clang_check
|
||||||
|
elif [ "$1" == 'markdown' ]; then
|
||||||
|
do_markdown_check
|
||||||
elif [ "$1" == 'python' ]; then
|
elif [ "$1" == 'python' ]; then
|
||||||
do_python_check
|
do_python_check
|
||||||
else
|
else
|
||||||
>&2 echo "Unsupported check: $1. Supported: clang, python"
|
>&2 echo "Unsupported check: $1. Supported: clang, markdown, python"
|
||||||
# 128 for Invalid arguments
|
# 128 for Invalid arguments
|
||||||
exit 128
|
exit 128
|
||||||
fi
|
fi
|
||||||
@@ -115,16 +145,19 @@ main()
|
|||||||
{
|
{
|
||||||
if [ $# == 0 ]; then
|
if [ $# == 0 ]; then
|
||||||
do_clang_format
|
do_clang_format
|
||||||
do_python_format
|
do_markdown_format
|
||||||
elif [ "$1" == 'python' ]; then
|
|
||||||
do_python_format
|
do_python_format
|
||||||
elif [ "$1" == 'clang' ]; then
|
elif [ "$1" == 'clang' ]; then
|
||||||
do_clang_format
|
do_clang_format
|
||||||
|
elif [ "$1" == 'markdown' ]; then
|
||||||
|
do_markdown_format
|
||||||
|
elif [ "$1" == 'python' ]; then
|
||||||
|
do_python_format
|
||||||
elif [ "$1" == 'check' ]; then
|
elif [ "$1" == 'check' ]; then
|
||||||
shift
|
shift
|
||||||
do_check "$@"
|
do_check "$@"
|
||||||
else
|
else
|
||||||
>&2 echo "Unsupported action: $1. Supported: clang, python"
|
>&2 echo "Unsupported action: $1. Supported: clang, markdown, python"
|
||||||
# 128 for Invalid arguments
|
# 128 for Invalid arguments
|
||||||
exit 128
|
exit 128
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user