Skip to content

Commit

Permalink
checkpatch: fix the if and whitespace checks
Browse files Browse the repository at this point in the history
The regex for the if/for/while bracket tests fails to distinguish
non-space text.  This means text such as do_something_if() would match
incorrectly.

Additionally, the ends-with-bracket test doesn't allow for the common
coding paradigm:

    if (condition) { /* Text about conditional. */
    }

So fix that as well.

Signed-off-by: Aaron Conole <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
apconole authored and blp committed Nov 29, 2016
1 parent 83f76d4 commit a1193b4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions utilities/checkpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ def print_warning(message, lineno=None):
__regex_leading_with_spaces = re.compile(r'^ +[\S]+')
__regex_trailing_whitespace = re.compile(r'[^\S]+$')
__regex_single_line_feed = re.compile(r'^\f$')
__regex_for_if_missing_whitespace = re.compile(r'(if|for|while)[\(]')
__regex_for_if_too_much_whitespace = re.compile(r'(if|for|while) +[\(]')
__regex_for_if_parens_whitespace = re.compile(r'(if|for|while) \( +[\s\S]+\)')
__regex_for_if_missing_whitespace = re.compile(r' +(if|for|while)[\(]')
__regex_for_if_too_much_whitespace = re.compile(r' +(if|for|while) +[\(]')
__regex_for_if_parens_whitespace = \
re.compile(r' +(if|for|while) \( +[\s\S]+\)')
__regex_is_for_if_single_line_bracket = \
re.compile(r'^ +(if|for|while) \(.*\)')

__regex_ends_with_bracket = re.compile(r'[^\s]\) {$')
__regex_ends_with_bracket = \
re.compile(r'[^\s]\) {(\s+/\*[\s\Sa-zA-Z0-9\.,\?\*/+-]*)?$')

skip_leading_whitespace_check = False
skip_trailing_whitespace_check = False
Expand Down

0 comments on commit a1193b4

Please sign in to comment.