Skip to content

Commit

Permalink
[pretty] add markdown support (#4881)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhui committed Apr 24, 2020
1 parent 32f8274 commit c48f84d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .prettierrc
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"
}
65 changes: 49 additions & 16 deletions script/make-pretty
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c48f84d

Please sign in to comment.