git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] style: indent multiline "if" conditions by 4 spaces

From
Jeff King <peff@peff.net>
Date
Dec 3, 2020, 18:32 UTC
Message-ID
<X8kvJRnOtSEYziRK@coredump.intra.peff.net>
In-Reply-To
<xmqqv9dihhqs.fsf@gitster.c.googlers.com>
On Thu, Dec 03, 2020 at 10:22:35AM -0800, Junio C Hamano wrote:
Show 24 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > Commit 6dc905d974 (config: split repo scope to local and worktree,
> > 2020-02-10) made some "if" statements multiline, but didn't indent the
> > second lines in our usual way.
> >
> > Signed-off-by: Jeff King <peff@peff.net>
> > ---
> > I just happened to be reading nearby code and saw this.
> 
> Can we rephrase "by 4 spaces" to avoid misleading new developers,
> though?  It's not like our rule is to indent continued expression by
> 4 spaces---it happens to be 4 in this case only because the second
> line is aligned with the column inside "if (".
> 
> If the expression were
> 
> 	if ((A == X && B == Y &&
> 	     boolean_expression_on_the_second_line()) ||
> 	    C == Z)
> 
> we would have indented the second line to align with the inside of
> the opening parenthesis, which may end up with "by 5 spaces", but
> four vs five is not the important part of the equation.

Yeah, the goal is to align it, but I had trouble thinking of a succinct way to say that. Maybe just:

  style: align indent of multiline "if" conditions
?
-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 5 in “style: indent multiline "if" conditions by 4 spaces”
  1. style: indent multiline "if" conditions by 4 spacesJeff King, Dec 3, 2020
  2. Junio C HamanoDec 3, 2020
  3. Jeff KingDec 3, 2020
  4. Junio C HamanoDec 3, 2020
  5. Jeff KingDec 3, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.