静态检测工具--PMD/ERROR PRONE /CppCheck
程序员文章站
2022-07-12 19:00:14
...
静态检测工具会确认code是否符合规范,是否有多余或者错误的code
PMD
Documentation Index | PMD Source Code Analyzer
error prone:
cpp check
Cppcheck - A tool for static C/C++ code analysis
PMD:
Download the latest binary zip from the releases and extract it somewhere.
执行Execute bin/run.sh
使用下面脚本(check_pmd.sh)解析pmd的结果,其中customize.xml 是PMD rule 规范
./check_pmd.sh code_path result_name
#!/bin/bash
WORKSPACE=$1
PMD_RESULT=$2
if [ -z $WORKSPACE ]; then
echo "======================================================="
echo " please give the path to check pmd "
echo "======================================================="
exit 1;
fi
if [ -z $PMD_RESULT ]; then
PMD_RESULT=result
fi
./run.sh pmd -d $WORKSPACE -f xml -R customize.xml > $PMD_RESULT.xml
level1=$(grep -nre "priority=\"1" $PMD_RESULT.xml | wc -l)
level2=$(grep -nre "priority=\"2" $PMD_RESULT.xml | wc -l)
level3=$(grep -nre "priority=\"3" $PMD_RESULT.xml | wc -l)
level4=$(grep -nre "priority=\"4" $PMD_RESULT.xml | wc -l)
level5=$(grep -nre "priority=\"5" $PMD_RESULT.xml | wc -l)
echo "wait report PMD analysis ..."
sleep 5
echo "======================================================="
echo " PMD Priority Result "
echo "======================================================="
echo "| | Patch |"
echo " "
echo "| Level 1 (High) | $level1 |"
echo "| Level 2 | $level2 |"
echo "| Level 3 (Normal)| $level3 |"
echo "| Level 4 | $level4 |"
echo "| Level 5 (Low) | $level5 |"
echo " "
Error Prone--Google出品的Java和Android Bug分析利器
android source code 编译可以使用这个命令执行error prone:
RUN_ERROR_PRONE=true mm
可能有些规范与PMD 冲突,看自己选择哪一个
如果不想解决,可以通过SuppressWarnings方式过滤掉
@SuppressWarnings("AlwaysThrows")
多个 @SuppressWarnings({"AlwaysThrows","AndroidInjectionBeforeSuper"})
同样该方法使用与PMD,如下
@SuppressWarnings("PMD.UselessParentheses")
CppCheck:
有window和linux 软件下载使用
其他的静态检测工具,有搜到如下博客