Re: list iterator spacing: clang-format vs checkpatch
From: Joe Perches
Date: Mon Jan 17 2022 - 13:05:31 EST
On Mon, 2022-01-17 at 13:47 +0100, Jason A. Donenfeld wrote:
> Hey again,
Rehi.
> Four years later I went through basically the same motions: "oh hey I
> should clean this up", "I'll start with clang format", "oh cool it
> adds spaces before the iterator paren so it looks like a normal for
> loop to me", "that seems so reasonable; I love clang format", "oh no
> checkpatch.pl complains; I hope it's wrong", "I wonder if anybody has
> thought about this before", "oh, look, I asked about this already in
> 2018."
Original thread:
https://lore.kernel.org/lkml/CAHmME9ofzanQTBD_WYBRW49d+gM77rCdh8Utdk4+PM9n_bmKwA@xxxxxxxxxxxxxx/
> So, here we are again. I'm wondering:
> - Can we switch to spaces before iterator parens?
Still doubtful because the kernel sources has ~150:1 preference
for no space, and it's still just a whitespace convention...
$ git grep -P '\b\w*for_each\w*\(' | wc -l
31920
$ git grep -P '\b\w*for_each\w*\s+\(' | wc -l
196
> - If not, is clang-format ever going to be fixed to quit adding them?
Doubtful as it's likely the .clang-format for_each list is
just out of date for your particular for_each type use and
the scripted bit that it uses to create them hasn't be
updated in awhile. Also that scripted bit only works on files
in include/ and not anything locally defined.
in .clang-format:
# Taken from:
# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ \
# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
# | sort | uniq
commit 4792f9dd12936ec35deced665ae3a4ca8fe98729
Author: Miguel Ojeda <ojeda@xxxxxxxxxx>
Date: Wed May 12 23:32:39 2021 +0200
clang-format: Update with the latest for_each macro list
Re-run the shell fragment that generated the original list.
Signed-off-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
checkpatch basically just looks for any use of 'for_each'
(?:[a-z_]+|)for_each[a-z_]+)
So it has false positives for some functions and not macros.