diff options
-rwxr-xr-x | tests/checkpatch.at | 27 | ||||
-rwxr-xr-x | utilities/checkpatch.py | 11 |
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/checkpatch.at b/tests/checkpatch.at index 9ab87410e..fdcdb846e 100755 --- a/tests/checkpatch.at +++ b/tests/checkpatch.at @@ -366,6 +366,33 @@ try_checkpatch \ AT_CLEANUP + +AT_SETUP([checkpatch - check egrep / fgrep]) +try_checkpatch \ + "COMMON_PATCH_HEADER([tests/something.at]) + +C_H_E_C_K([[ovs-vsctl show | grep -E 'my-port.*[[0-9]]$' | grep -F 'port']]) + " + +try_checkpatch \ + "COMMON_PATCH_HEADER([tests/something.at]) + +C_H_E_C_K([[ovs-vsctl show | egrep 'my-port.*[[0-9]]$']]) + " \ + "ERROR: grep -E/-F should be used instead of egrep/fgrep + #8 FILE: tests/something.at:1: + C_H_E_C_K([[ovs-vsctl show | egrep 'my-port.*[[0-9]]$']]) +" + +try_checkpatch \ + "COMMON_PATCH_HEADER([tests/something.at]) + +C_H_E_C_K([[ovs-vsctl show | fgrep 'my-port.*[[0-9]]$']]) + " \ + "ERROR: grep -E/-F should be used instead of egrep/fgrep + #8 FILE: tests/something.at:1: + C_H_E_C_K([[ovs-vsctl show | fgrep 'my-port.*[[0-9]]$']]) +" +AT_CLEANUP + + AT_SETUP([checkpatch - whitespace around cast]) try_checkpatch \ "COMMON_PATCH_HEADER diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py index 887928404..0d30b71b5 100755 --- a/utilities/checkpatch.py +++ b/utilities/checkpatch.py @@ -182,6 +182,7 @@ __regex_empty_return = re.compile(r'\s*return;') __regex_if_macros = re.compile(r'^ +(%s) \([\S]([\s\S]+[\S])*\) { +\\' % __parenthesized_constructs) __regex_nonascii_characters = re.compile("[^\u0000-\u007f]") +__regex_efgrep = re.compile(r'.*[ef]grep.*$') skip_leading_whitespace_check = False skip_trailing_whitespace_check = False @@ -341,6 +342,11 @@ def has_xxx_mark(line): return __regex_has_xxx_mark.match(line) is not None +def has_efgrep(line): + """Returns TRUE if the current line contains 'egrep' or 'fgrep'.""" + return __regex_efgrep.match(line) is not None + + def filter_comments(current_line, keep=False): """remove all of the c-style comments in a line""" STATE_NORMAL = 0 @@ -608,6 +614,11 @@ checks = [ 'print': lambda: print_warning("Empty return followed by brace, consider omitting") }, + + {'regex': r'(\.at|\.sh)$', 'match_name': None, + 'check': lambda x: has_efgrep(x), + 'print': + lambda: print_error("grep -E/-F should be used instead of egrep/fgrep")}, ] |