提交 0b566672 编写于 作者: S storypku 提交者: Chang Songhong

apollo.sh: apollo.sh lint --help support

上级 85874a85
......@@ -195,8 +195,7 @@ function main() {
env ${APOLLO_ENV} bash "${APOLLO_ROOT_DIR}/scripts/apollo_buildify.sh"
;;
lint)
# FIXME(all): apollo_lint.sh "$@" when bash/python scripts are ready.
env ${APOLLO_ENV} bash "${APOLLO_ROOT_DIR}/scripts/apollo_lint.sh" cpp
env ${APOLLO_ENV} bash "${APOLLO_ROOT_DIR}/scripts/apollo_lint.sh" "$@"
;;
clean)
env ${APOLLO_ENV} bash "${APOLLO_ROOT_DIR}/scripts/apollo_clean.sh" "$@"
......
......@@ -39,11 +39,11 @@ are provided for developers to check style issues.
> files only. We hope that linters for other languages will be online in the
> near future.
| Linters | Source Extensions | Apollo Command Used |
| :--------: | :-----------------------------------: | :------------------------- |
| cpplint | .h/.c/.hpp/.cpp/.hh/.cc/.hxx/.cxx/.cu | scripts/apollo_lint.sh cpp |
| flake8 | .py | scripts/apollo_lint.sh py |
| shellcheck | .sh/.bash/.bashrc | scripts/apollo_lint.sh sh |
| Linters | Source Extensions | Apollo Command Used |
| :--------: | :-----------------------------------: | :------------------------ |
| cpplint | .h/.c/.hpp/.cpp/.hh/.cc/.hxx/.cxx/.cu | bash apollo.sh lint --cpp |
| flake8 | .py | bash apollo.sh lint --py |
| shellcheck | .sh/.bash/.bashrc | bash apollo.sh lint --sh |
To make sure your code conforms to Apollo coding style, you can use
`./apollo.sh lint` to find any possible style problems and fix them manually.
......@@ -57,13 +57,13 @@ avoid common mistakes when writing code.
The following table lists the formatters currently integrated into Apollo,
covering C/C++, Python, Bash, Bazel, Markdown, JSON and YAML files.
| Formatters | Source Extension | Apollo Command Used | Formatter Config |
| :----------: | :------------------------------------: | :----------------------------------------------: | :--------------: |
| clang-format | .h/.c/.hpp/.cpp/.hh/.cc/.hxx/.cxx;/.cu | ./apollo.sh format -c <path/to/src/dir/or/files> | .clang-format |
| autopep8 | .py | ./apollo.sh format -p <path/to/src/dir/or/files> | tox.ini |
| buildifier | .BUILD/.bzl/.bazel/WORKSPACE/BUILD | ./apollo.sh format -b <path/to/src/dir/or/files> | N/A |
| shfmt | .sh/.bash/.bashrc | ./apollo.sh format -s <path/to/src/dir/or/files> | .editorconfig |
| prettier | .md/.json/.yml | ./apollo.sh format -m <path/to/src/dir/or/files> | .prettier.json |
| Formatters | Source Extensions | Apollo Command Used | Formatter Config |
| :----------: | :------------------------------------------: | :----------------------------------------------: | :--------------: |
| clang-format | .h/.c/.hpp/.cpp/.hh/.cc/.hxx/.cxx/.cu/.proto | ./apollo.sh format -c <path/to/src/dir/or/files> | .clang-format |
| autopep8 | .py | ./apollo.sh format -p <path/to/src/dir/or/files> | tox.ini |
| buildifier | .BUILD/.bzl/.bazel/WORKSPACE/BUILD | ./apollo.sh format -b <path/to/src/dir/or/files> | N/A |
| shfmt | .sh/.bash/.bashrc | ./apollo.sh format -s <path/to/src/dir/or/files> | .editorconfig |
| prettier | .md/.json/.yml | ./apollo.sh format -m <path/to/src/dir/or/files> | .prettier.json |
For easy use, you can format all files with types listed above with:
......@@ -82,8 +82,8 @@ which will auto-format Bazel `WORKSPACE` file under `$APOLLO_ROOT_DIR`,
Note:
> `./apollo.sh format` can also work outside Docker if relavant tools
> installed properly.
> `./apollo.sh format` can also work outside Docker if relavant tools installed
> properly.
## Conclusion
......
......@@ -24,17 +24,20 @@ source "${TOP_DIR}/scripts/apollo.bashrc"
: ${STAGE:=dev}
PYTHON_LINT_FLAG=0
CPP_LINT_FLAG=0
SHELL_LINT_FLAG=0
function _cpp_lint_impl() {
bazel test --config=cpplint "$@"
}
function run_cpp_lint() {
pushd "${APOLLO_ROOT_DIR}" > /dev/null
pushd "${APOLLO_ROOT_DIR}" >/dev/null
local cpp_dirs="cyber"
if [[ "${STAGE}" == "dev" ]]; then
cpp_dirs="${cpp_dirs} modules"
fi
# -not \( -path "modules/drivers/gnss/third_party" -prune \) \
for prey in $(find ${cpp_dirs} -name BUILD \
| xargs grep -l -E 'cc_library|cc_test|cc_binary|cuda_library' \
| xargs grep -L 'cpplint()'); do
......@@ -47,7 +50,7 @@ function run_cpp_lint() {
${buidifier} -lint=fix "${prey}"
fi
done
popd > /dev/null
popd >/dev/null
local targets="//cyber/..."
_cpp_lint_impl "${targets}"
......@@ -104,44 +107,62 @@ function run_py_lint() {
function print_usage() {
info "Usage: $0 [Options]"
info "Options:"
info "${TAB}--py Lint Python files"
info "${TAB}--sh Lint Bash scripts"
info "${TAB}--cpp Lint cpp source files"
info "${TAB}-a|--all Lint all. Equivalent to \"--py --sh --cpp\""
info "${TAB}-h|--help Show this message and exit"
info "${TAB}py|python Lint Python code"
info "${TAB}sh|shell Lint Bash code"
info "${TAB}cpp Lint cpp code"
info "${TAB}all Lint all (C++/Python/Bash)"
info "${TAB}help Same as '--help'"
}
function run_lint() {
local cmd="$1"
case "${cmd}" in
py | python)
run_py_lint
;;
cpp)
run_cpp_lint
;;
sh | shell)
run_sh_lint
;;
all)
run_cpp_lint
run_py_lint
run_sh_lint
;;
help)
print_usage
exit 0
;;
*)
print_usage
exit 1
;;
esac
function parse_cmdline_args() {
if [[ "$#" -eq 0 ]]; then
CPP_LINT_FLAG=1
return 0
fi
while [[ "$#" -gt 0 ]]; do
local opt="$1"
shift
case "${opt}" in
--py)
PYTHON_LINT_FLAG=1
;;
--cpp)
CPP_LINT_FLAG=1
;;
--sh)
SHELL_LINT_FLAG=1
;;
-a | --all)
PYTHON_LINT_FLAG=1
CPP_LINT_FLAG=1
SHELL_LINT_FLAG=1
;;
-h | --help)
print_usage
exit 0
;;
*)
warning "Unknown option: ${opt}"
print_usage
exit 1
;;
esac
done
}
function main() {
run_lint "$@"
parse_cmdline_args "$@"
if [[ "${CPP_LINT_FLAG}" ]]; then
run_cpp_lint
fi
if [[ "${PYTHON_LINT_FLAG}" -eq 1 ]]; then
run_py_lint
fi
if [[ "${SHELL_LINT_FLAG}" -eq 1 ]]; then
run_sh_lint
fi
}
main "$@"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册