Re: [PATCH 6/8] clang-format: formalize some of the spacing rules
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Jul 8, 2024, 17:26 UTC
- Message-ID
- <CAOLa=ZQUv7=CKFY7YwfVeOW0qobJbMU8nadN4daB7Lb2=eJc8Q@mail.gmail.com>
- In-Reply-To
- <xmqq8qybj039.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 10 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes: > >> There are some spacing rules that we follow in the project and it makes >> sen to formalize them: >> * Ensure there is no space inserted after the logical not '!' operator. > > Shouldn't the rule be more like "no space between any single operand > prefix or postfix operator and its operand"? "foo++", "--foo", "~0" > are the examples that come to my mind. >
The rule here is SpaceAfterLogicalNot [1], is specific to logical not operator. Unfortunately I couldn't find a general rule for unary operators. That would be very useful indeed.
>> * Ensure there is no space before the case statement's color. > > "color" -> "colon". >
Will fix, thanks!
Show 17 quoted lines
>> * Ensure there is no space before the first bracket '[' of an array.
>> * Ensure there is no space in empty blocks.
>
> Hmph, I actually thought we preferred to be more explicit, using
>
> if (foo)
> ; /* nothing */
>
> instead of any of
>
> if (foo) {}
> if (foo) { }
> if (foo) { ; }
> if (foo) { ; /* nothing */ }
>
> to write an empty statement.
>Yup, that is correct. This rule doesn't state that we need to use 'if (foo) {}' over the more explicit format. It only states that if we do create an empty block without statements, the rule is to have no spaces.
We only have a few instances of this in our code.
[1]: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#spaceafterlogicalnot
[snip]