Re: [patch] checkpatch: putting the && or || on the wrong line
From: J. Bruce Fields
Date: Tue Jan 04 2011 - 11:38:43 EST
On Tue, Jan 04, 2011 at 08:59:00AM +0300, Dan Carpenter wrote:
> This patch makes checkpatch.pl complain if you break up conditions in
> the wrong way.
>
> Wrong:
> if ((really_long_condition)
> && (second_condition)) { ...
> Right:
> if ((really_long_condition) &&
> (second_condition)) { ...
As far as I can tell, the convention in mathematical typesetting is to
put operators on the left, not the right. When the conditions are short
of there are more lines, that allows you to left-align on the repeated
operator.
--b.
>
> If you do it in the wrong way the message is: "put the && or || at the
> end of the previous line"
>
> Signed-off-by: Dan Carpenter <error27@xxxxxxxxx>
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index e3c7fc0..0a813db 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -1509,6 +1509,11 @@ sub process {
> WARN("please, no space before tabs\n" . $herevet);
> }
>
> +# check for && or || at the start of a line
> + if ($rawline =~ /^\+\W+(&&|\|\|)/) {
> + WARN("put the && or || at the end of the previous line\n" . $herecurr);
> + }
> +
> # check for spaces at the beginning of a line.
> # Exceptions:
> # 1) within comments
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/