Skip to content
  • Max Reitz's avatar
    checkpatch: Brace handling on multi-line condition · a97ceca5
    Max Reitz authored
    
    
    CODING_STYLE states the following about braces around blocks:
    
    > The opening brace is on the line that contains the control flow
    > statement that introduces the new block; [...]
    
    This is obviously impossible with multi-line conditions. Therefore,
    CODING_STYLE does not make any clear statement about where to put the
    opening brace after a multi-line condition.
    
    There is a reason to prefer to place the opening brace on an own line
    after such a condition while still placing it on the same line as the
    "control flow statement" if possible; that reason is that the last line
    of a multi-line condition is indented, in the case of "if", it is often
    indented by four spaces, just as much as the first statement in the
    block will be indented. This is hard to read as there is no clearly
    visible distinction between condition and block. Placing the opening
    brace on a separate line solves this issue.
    
    Also, there are cases where placing the opening brace on a separate line
    is the only viable option; if the previous line had nearly 80 characters
    and splitting it is not desirable, the opening brace is naturally placed
    on an own line.
    
    This patch fixes checkpatch.pl to not complain about braces on own lines
    if the condition introducing the block spanned more than one line, or if
    the previous line had 79 or 80 characters.
    
    Furthermore, the warning about not having braces around a block is fixed
    to mind braces not being on the last line of the condition.
    
    Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    a97ceca5