From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751954AbcBPBUS (ORCPT ); Mon, 15 Feb 2016 20:20:18 -0500 Received: from mail-ob0-f169.google.com ([209.85.214.169]:36276 "EHLO mail-ob0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751761AbcBPBUQ (ORCPT ); Mon, 15 Feb 2016 20:20:16 -0500 From: Jeffrey Merkey To: linux-kernel@vger.kernel.org Cc: apw@canonical.com, joe@perches.com Subject: [PATCH] Add fix case for open braces Date: Mon, 15 Feb 2016 18:20:06 -0700 Message-Id: <1455585606-21054-1-git-send-email-jeffmerkey@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some quite excellent fixes from Joe Perches that belong back in the original. Submitting to Joe for inclusion. Joe was the original author of these fixes that save a lot of time rewriting code. Thanks Joe. Signed-off-by: Jeffrey Merkey --- scripts/checkpatch.pl | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 874132b..71f93e8 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3108,9 +3108,15 @@ sub process { #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n"; if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { - ERROR("OPEN_BRACE", - "that open brace { should be on the previous line\n" . - "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); + if (ERROR("OPEN_BRACE", + "that open brace { should be on the previous line\n" . + "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n") && + $fix && + $rawlines[$ctx_ln - 2] =~ /^\+/ && + $rawlines[$ctx_ln - 1] =~ /^\+\s*{\s*$/) { + $fixed[$ctx_ln - 2] = rtrim($fixed[$ctx_ln - 2]) . ' {'; + fix_delete_line($ctx_ln - 1, $rawlines[$ctx_ln - 1]); + } } if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ && $ctx =~ /\)\s*\;\s*$/ && @@ -4807,8 +4813,15 @@ sub process { $herectx .= raw_line($linenr, $n) . "\n"; } - WARN("BRACES", - "braces {} are not necessary for single statement blocks\n" . $herectx); + if (WARN("BRACES", + "braces {} are not necessary for single statement blocks\n" . $herectx) && + $fix && + $fixed[$fixlinenr] =~ /^\+.*\{\s*$/ && + $fixed[$fixlinenr + 1] =~ /^\+.*;\s*$/ && + $fixed[$fixlinenr + 2] =~ /^\+\s*\}\s*$/) { + $fixed[$fixlinenr] =~ s/\{\s*$//; + fix_delete_line($fixlinenr + 2, $rawlines[$fixlinenr + 2]); + } } } -- 1.8.3.1