Skip to content

Commit c48f84d

Browse files
committed
[pretty] add markdown support (openthread#4881)
1 parent 32f8274 commit c48f84d

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

.prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "http://json.schemastore.org/prettierrc",
3+
"printWidth": 80,
4+
"tabWidth": 2,
5+
"useTabs": false,
6+
"proseWrap": "never"
7+
}

script/make-pretty

+49-16
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,45 @@
3030
#
3131
# The script to check or format source code of OpenThread.
3232
#
33-
# Format python and c/c++:
33+
# Format c/c++, markdown, and python:
3434
#
3535
# script/make-pretty
3636
#
37-
# Format python only:
38-
#
39-
# script/make-pretty python
40-
#
4137
# Format c/c++ only:
4238
#
4339
# script/make-pretty clang
4440
#
41+
# Format markdown only:
42+
#
43+
# script/make-pretty markdown
44+
#
45+
# Format python only:
46+
#
47+
# script/make-pretty python
48+
#
4549
# Check only:
4650
#
4751
# script/make-pretty check clang
52+
# script/make-pretty check markdown
4853
# script/make-pretty check python
4954
#
5055

5156
set -euo pipefail
5257

53-
readonly OT_CLANG_DIRS=(examples include src tests tools)
54-
readonly OT_PYTHON_DIRS=(tests tools)
5558
readonly OT_BUILD_JOBS=$(getconf _NPROCESSORS_ONLN)
59+
readonly OT_EXCLUDE_DIRS=(third_party)
60+
5661
readonly OT_CLANG_SOURCES=('*.c' '*.cc' '*.cpp' '*.h' '*.hpp')
62+
readonly OT_MARKDOWN_SOURCES=('*.md')
63+
readonly OT_PYTHON_SOURCES=('*.py')
5764

5865
do_clang_format()
5966
{
6067
echo -e '====================='
6168
echo -e ' format c/c++'
6269
echo -e '====================='
6370

64-
git ls-files "${OT_CLANG_SOURCES[@]}" | grep -E "^($(echo "${OT_CLANG_DIRS[@]}" | tr ' ' '|'))" \
71+
git ls-files "${OT_CLANG_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \
6572
| xargs -n3 -P"${OT_BUILD_JOBS}" script/clang-format -style=file -i -verbose
6673
}
6774

@@ -71,17 +78,37 @@ do_clang_check()
7178
echo -e ' check c/c++'
7279
echo -e '====================='
7380

74-
git ls-files "${OT_CLANG_SOURCES[@]}" | grep -E "^($(echo "${OT_CLANG_DIRS[@]}" | tr ' ' '|'))" \
81+
git ls-files "${OT_CLANG_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \
7582
| xargs -n3 -P"${OT_BUILD_JOBS}" script/clang-format-check
7683
}
7784

85+
do_markdown_format()
86+
{
87+
echo -e '======================'
88+
echo -e ' format markdown'
89+
echo -e '======================'
90+
91+
git ls-files "${OT_MARKDOWN_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \
92+
| xargs -n10 -P"${OT_BUILD_JOBS}" npx prettier@2.0.4 --write
93+
}
94+
95+
do_markdown_check()
96+
{
97+
echo -e '======================'
98+
echo -e ' check markdown'
99+
echo -e '======================'
100+
101+
git ls-files "${OT_MARKDOWN_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \
102+
| xargs -n10 -P"${OT_BUILD_JOBS}" npx prettier@2.0.4 --check
103+
}
104+
78105
do_python_format()
79106
{
80107
echo -e '======================'
81108
echo -e ' format python'
82109
echo -e '======================'
83110

84-
git ls-files '*.py' | grep -E "^($(echo "${OT_PYTHON_DIRS[@]}" | tr ' ' '|'))" \
111+
git ls-files "${OT_PYTHON_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \
85112
| xargs -n10 -P"${OT_BUILD_JOBS}" python3 -m yapf --verbose --style google -ipr
86113
}
87114

@@ -91,21 +118,24 @@ do_python_check()
91118
echo -e ' check python'
92119
echo -e '====================='
93120

94-
git ls-files '*.py' | grep -E "^($(echo "${OT_PYTHON_DIRS[@]}" | tr ' ' '|'))" \
121+
git ls-files "${OT_PYTHON_SOURCES[@]}" | grep -v -E "^($(echo "${OT_EXCLUDE_DIRS[@]}" | tr ' ' '|'))" \
95122
| xargs -n10 -P"${OT_BUILD_JOBS}" python3 -m yapf --verbose --style google -dpr
96123
}
97124

98125
do_check()
99126
{
100127
if [ $# == 0 ]; then
101-
do_python_check
102128
do_clang_check
129+
do_markdown_check
130+
do_python_check
103131
elif [ "$1" == 'clang' ]; then
104132
do_clang_check
133+
elif [ "$1" == 'markdown' ]; then
134+
do_markdown_check
105135
elif [ "$1" == 'python' ]; then
106136
do_python_check
107137
else
108-
>&2 echo "Unsupported check: $1. Supported: clang, python"
138+
>&2 echo "Unsupported check: $1. Supported: clang, markdown, python"
109139
# 128 for Invalid arguments
110140
exit 128
111141
fi
@@ -115,16 +145,19 @@ main()
115145
{
116146
if [ $# == 0 ]; then
117147
do_clang_format
118-
do_python_format
119-
elif [ "$1" == 'python' ]; then
148+
do_markdown_format
120149
do_python_format
121150
elif [ "$1" == 'clang' ]; then
122151
do_clang_format
152+
elif [ "$1" == 'markdown' ]; then
153+
do_markdown_format
154+
elif [ "$1" == 'python' ]; then
155+
do_python_format
123156
elif [ "$1" == 'check' ]; then
124157
shift
125158
do_check "$@"
126159
else
127-
>&2 echo "Unsupported action: $1. Supported: clang, python"
160+
>&2 echo "Unsupported action: $1. Supported: clang, markdown, python"
128161
# 128 for Invalid arguments
129162
exit 128
130163
fi

0 commit comments

Comments
 (0)