qiushao@qiushao-pc:~/source/android-10/system/core/adb$ cpplint.py --verbose=5 --counting=toplevel adb.cpp adb.cpp:33: <chrono> is an unapproved C++11 header. [build/c++11] [5] adb.cpp:34: <condition_variable> is an unapproved C++11 header. [build/c++11] [5] adb.cpp:35: <mutex> is an unapproved C++11 header. [build/c++11] [5] adb.cpp:37: <thread> is an unapproved C++11 header. [build/c++11] [5] adb.cpp:62: Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5] adb.cpp:135: Missing space before ( in switch( [whitespace/parens] [5] adb.cpp:135: Missing space before { [whitespace/braces] [5] adb.cpp:322: Missing space before ( in switch( [whitespace/parens] [5] adb.cpp:322: Missing space before { [whitespace/braces] [5] adb.cpp:390: Missing space before ( in if( [whitespace/parens] [5] Done processing adb.cpp Category 'build' errors found: 5 Category 'whitespace' errors found: 5 Total errors found: 10
#!/bin/sh # # An example hook script to verify what is about to be committed. # Called by "git commit" with no arguments. The hook should #exit with non-zero status after issuing an appropriate message if # it wants to stop the commit. # # To enable this hook, rename this file to "pre-commit".
if git rev-parse --verify HEAD >/dev/null 2>&1 then against=HEAD else # Initial commit: diff against an empty tree object against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 fi
# Redirect output to stderr. exec 1>&2
cpplint=cpplint.py sum=0 filters='-whitespace/line_length,-build/include' #for cpp for file in $(git diff-index --name-status $against -- | grep -E '\.[ch](pp)?$' | awk '{print $2}'); do $cpplint --filter=$filters $file sum=$(expr ${sum} + $?) done if [ ${sum} -eq 0 ]; then exit 0 else exit 1 fi
我们来尝试提交一个有错误的代码:
1 2 3 4 5 6 7
qiushao@qiushao-pc:~/projects/clion/test$ git commit -m 'test' main.cpp:0: No copyright message found. You should have a line: "Copyright [year] <Copyright Owner>" [legal/copyright] [5] main.cpp:2: Line contains invalid UTF-8 (or Unicode replacement character). [readability/utf8] [5] main.cpp:7: Could not find a newline character at the end of the file. [whitespace/ending_newline] [5] Done processing main.cpp Total errors found: 3 qiushao@qiushao-pc:~/projects/clion/test$