From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,URIBL_SBL,URIBL_SBL_A autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97245C2BA80 for ; Tue, 7 Apr 2020 03:11:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 53C11206B8 for ; Tue, 7 Apr 2020 03:11:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="r4wPKZHq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 53C11206B8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 067DA8E008B; Mon, 6 Apr 2020 23:11:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 017208E0062; Mon, 6 Apr 2020 23:11:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E96838E008B; Mon, 6 Apr 2020 23:11:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id D1D798E0062 for ; Mon, 6 Apr 2020 23:11:09 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 828C1A8C6 for ; Tue, 7 Apr 2020 03:11:09 +0000 (UTC) X-FDA: 76679582658.27.cloud63_a103d4e87b3d X-HE-Tag: cloud63_a103d4e87b3d X-Filterd-Recvd-Size: 7039 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Apr 2020 03:11:09 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 144D420801; Tue, 7 Apr 2020 03:11:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586229068; bh=tjVWtxewLCfnHTv9EGOzztgcQtjxK+P4SgKnTP79ei0=; h=Date:From:To:Subject:In-Reply-To:From; b=r4wPKZHqDU30oa/vBPeMenOomjp5DsLNt84Z78eefLFaBP2VtcCGsk5DSSXKCdD7s /LPM/UmSBnYYU4KWvjqT0LKS1Gsg7g3/rECyaZSGbev7NY/zZ35F5GUaAoigLVm/F6 iYwewJWhz62ZwGPsX6LqYHLV1o/oGUmzYeLoC4e0= Date: Mon, 06 Apr 2020 20:11:07 -0700 From: Andrew Morton To: akpm@linux-foundation.org, borneo.antonio@gmail.com, erik.ahlen@avalonenterprise.com, joe@perches.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, spen@spen-soft.co.uk, torvalds@linux-foundation.org Subject: [patch 133/166] checkpatch: add command-line option for TAB size Message-ID: <20200407031107.XWCzbK77b%akpm@linux-foundation.org> In-Reply-To: <20200406200254.a69ebd9e08c4074e41ddebaf@linux-foundation.org> User-Agent: s-nail v14.8.16 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: =46rom: Antonio Borneo Subject: checkpatch: add command-line option for TAB size Linux kernel coding style requires a size of 8 characters for both TAB and indentation, and such value is embedded as magic value allover the checkpatch script. This makes hard to reuse the script by other projects with different requirements in their coding style (e.g. OpenOCD [1] requires TAB size of 4 characters [2]). Replace the magic value 8 with a variable. Add a command-line option "--tab-size" to let the user select a TAB size value other than 8. [1] http://openocd.org/ [2] http://openocd.org/doc/doxygen/html/stylec.html#styleformat Link: http://lkml.kernel.org/r/20200122163852.124417-3-borneo.antonio@gmail= .com Signed-off-by: Antonio Borneo Signed-off-by: Erik Ahl=C3=A9n Signed-off-by: Spencer Oliver Cc: Joe Perches Signed-off-by: Andrew Morton --- scripts/checkpatch.pl | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) --- a/scripts/checkpatch.pl~checkpatch-add-command-line-option-for-tab-size +++ a/scripts/checkpatch.pl @@ -64,6 +64,7 @@ my $color =3D "auto"; my $allow_c99_comments =3D 1; # Can be overridden by --ignore C99_COMMENT_= TOLERANCE # git output parsing needs US English output, so first set backtick child = process LANGUAGE my $git_command =3D'export LANGUAGE=3Den_US.UTF-8; git'; +my $tabsize =3D 8; =20 sub help { my ($exitcode) =3D @_; @@ -98,6 +99,7 @@ Options: --show-types show the specific message type in the output --max-line-length=3Dn set the maximum line length, if exceeded, w= arn --min-conf-desc-length=3Dn set the min description length, if shorter,= warn + --tab-size=3Dn set the number of spaces for tab (default 8) --root=3DPATH PATH to the kernel tree root --no-summary suppress the per-file summary --mailback only produce a report in case of warnings/err= ors @@ -215,6 +217,7 @@ GetOptions( 'list-types!' =3D> \$list_types, 'max-line-length=3Di' =3D> \$max_line_length, 'min-conf-desc-length=3Di' =3D> \$min_conf_desc_length, + 'tab-size=3Di' =3D> \$tabsize, 'root=3Ds' =3D> \$root, 'summary!' =3D> \$summary, 'mailback!' =3D> \$mailback, @@ -267,6 +270,9 @@ if ($color =3D~ /^[01]$/) { die "Invalid color mode: $color\n"; } =20 +# skip TAB size 1 to avoid additional checks on $tabsize - 1 +die "Invalid TAB size: $tabsize\n" if ($tabsize < 2); + sub hash_save_array_words { my ($hashRef, $arrayRef) =3D @_; =20 @@ -1239,7 +1245,7 @@ sub expand_tabs { if ($c eq "\t") { $res .=3D ' '; $n++; - for (; ($n % 8) !=3D 0; $n++) { + for (; ($n % $tabsize) !=3D 0; $n++) { $res .=3D ' '; } next; @@ -2252,7 +2258,7 @@ sub string_find_replace { sub tabify { my ($leading) =3D @_; =20 - my $source_indent =3D 8; + my $source_indent =3D $tabsize; my $max_spaces_before_tab =3D $source_indent - 1; my $spaces_to_tab =3D " " x $source_indent; =20 @@ -3231,7 +3237,7 @@ sub process { next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/); =20 # at the beginning of a line any tabs must come first and anything -# more than 8 must use tabs. +# more than $tabsize must use tabs. if ($rawline =3D~ /^\+\s* \t\s*\S/ || $rawline =3D~ /^\+\s* \s*/) { my $herevet =3D "$here\n" . cat_vet($rawline) . "\n"; @@ -3250,7 +3256,7 @@ sub process { "please, no space before tabs\n" . $herevet) && $fix) { while ($fixed[$fixlinenr] =3D~ - s/(^\+.*) {8,8}\t/$1\t\t/) {} + s/(^\+.*) {$tabsize,$tabsize}\t/$1\t\t/) {} while ($fixed[$fixlinenr] =3D~ s/(^\+.*) +\t/$1\t/) {} } @@ -3272,11 +3278,11 @@ sub process { if ($perl_version_ok && $sline =3D~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|whil= e\b|\s*$)|$Declare\s*$Ident\s*[;=3D])/) { my $indent =3D length($1); - if ($indent % 8) { + if ($indent % $tabsize) { if (WARN("TABSTOP", "Statements should start on a tabstop\n" . $herecurr) && $fix) { - $fixed[$fixlinenr] =3D~ s@(^\+\t+) +@$1 . "\t" x ($indent/8)@e; + $fixed[$fixlinenr] =3D~ s@(^\+\t+) +@$1 . "\t" x ($indent/$tabsize)@e; } } } @@ -3294,8 +3300,8 @@ sub process { my $newindent =3D $2; =20 my $goodtabindent =3D $oldindent . - "\t" x ($pos / 8) . - " " x ($pos % 8); + "\t" x ($pos / $tabsize) . + " " x ($pos % $tabsize); my $goodspaceindent =3D $oldindent . " " x $pos; =20 if ($newindent ne $goodtabindent && @@ -3766,11 +3772,11 @@ sub process { #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sinden= t> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> = stat_real<$stat_real> stat<$stat>\n"; =20 if ($check && $s ne '' && - (($sindent % 8) !=3D 0 || + (($sindent % $tabsize) !=3D 0 || ($sindent < $indent) || ($sindent =3D=3D $indent && ($s !~ /^\s*(?:\}|\{|else\b)/)) || - ($sindent > $indent + 8))) { + ($sindent > $indent + $tabsize))) { WARN("SUSPECT_CODE_INDENT", "suspect code indent for conditional statements ($indent, $sinden= t)\n" . $herecurr . "$stat_real\n"); } _