github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/pybind11/tools/check-style.sh (about) 1 #!/bin/bash 2 # 3 # Script to check include/test code for common pybind11 code style errors. 4 # 5 # This script currently checks for 6 # 7 # 1. missing space between keyword and parenthesis, e.g.: for(, if(, while( 8 # 2. Missing space between right parenthesis and brace, e.g. 'for (...){' 9 # 3. opening brace on its own line. It should always be on the same line as the 10 # if/while/for/do statement. 11 # 12 # Invoke as: tools/check-style.sh <filenames> 13 # 14 15 check_style_errors=0 16 IFS=$'\n' 17 18 19 found="$(grep '\<\(if\|for\|while\|catch\)(\|){' "$@" -rn --color=always)" 20 if [ -n "$found" ]; then 21 echo -e '\033[31;01mError: found the following coding style problems:\033[0m' 22 check_style_errors=1 23 echo "${found//^/ /}" 24 fi 25 26 found="$(awk ' 27 function prefix(filename, lineno) { 28 return " \033[35m" filename "\033[36m:\033[32m" lineno "\033[36m:\033[0m" 29 } 30 function mark(pattern, string) { sub(pattern, "\033[01;31m&\033[0m", string); return string } 31 last && /^\s*{/ { 32 print prefix(FILENAME, FNR-1) mark("\\)\\s*$", last) 33 print prefix(FILENAME, FNR) mark("^\\s*{", $0) 34 last="" 35 } 36 { last = /(if|for|while|catch|switch)\s*\(.*\)\s*$/ ? $0 : "" } 37 ' "$(find include -type f)" "$@")" 38 if [ -n "$found" ]; then 39 check_style_errors=1 40 echo -e '\033[31;01mError: braces should occur on the same line as the if/while/.. statement. Found issues in the following files:\033[0m' 41 echo "$found" 42 fi 43 44 exit $check_style_errors