Re: [PATCH v2] checkpatch: add command-line option for TAB size

From: Joe Perches
Date: Wed May 08 2019 - 18:00:58 EST


On Wed, 2019-05-08 at 21:14 +0000, Elliott, Robert (Servers) wrote:
> > -----Original Message-----
> > From: linux-kernel-owner@xxxxxxxxxxxxxxx [mailto:linux-kernel-owner@xxxxxxxxxxxxxxx] On Behalf Of
> > Antonio Borneo
> > Sent: Wednesday, May 8, 2019 12:44 PM
> > Subject: [PATCH v2] checkpatch: add command-line option for TAB size
> ...
> > Add a command-line option "--tab-size" to let the user select a
> > TAB size value other than 8.
> > This makes easy to reuse this script by other projects with
> > different requirements in their coding style (e.g. OpenOCD [1]
> > requires TAB size of 4 characters [2]).
> ...
> > + --tab-size=n set the number of spaces for tab (default 8)
> ...
> > + 'tab-size=i' => \$tabsize,
> ...
> > - for (; ($n % 8) != 0; $n++) {
> > + for (; ($n % $tabsize) != 0; $n++) {
> ...
> > - if ($indent % 8) {
> > + if ($indent % $tabsize) {
> > - "\t" x ($pos / 8) .
> > - " " x ($pos % 8);
> > + "\t" x ($pos / $tabsize) .
> > + " " x ($pos % $tabsize);
> ...
> > - (($sindent % 8) != 0 ||
> > + (($sindent % $tabsize) != 0 ||
> ...
> > - ($sindent > $indent + 8))) {
> > + ($sindent > $indent + $tabsize))) {
>
> Checking for 0 before using the value in division and modulo
> operations would be prudent.

true.

Maybe test $tabsize for <= 0 after GetOptions and error out
if so.