Skip to content

Modernize clang-format: enforce 120-column limit and reduce config to meanful overrides#2

Open
harrylin98 wants to merge 2 commits into
unstablefrom
clang_format
Open

Modernize clang-format: enforce 120-column limit and reduce config to meanful overrides#2
harrylin98 wants to merge 2 commits into
unstablefrom
clang_format

Conversation

@harrylin98
Copy link
Copy Markdown
Owner

@harrylin98 harrylin98 commented May 26, 2026

This is internal draft PR:

This PR changes the .clang-format configuration and reformats src/* accordingly.

Reformat: The second commit applies the new config across all src/*.{c,h} (122 files). This is a mechanical reformatting with no logic changes.

Config changes:

  1. ColumnLimit: 0 → ColumnLimit: 120: The old config disabled all line length enforcement. The new limit prevents unbounded line growth, with specific penalty break rules.
  •  PenaltyReturnTypeOnItsOwnLine: 1000000 // always keep return type on same line as function name
    
  •  PenaltyBreakAssignment: 100 // prefer not breaking over splitting assignments
    
  •  PenaltyBreakOpenParenthesis: 1000 // avoid breaking right after '('
    
  1. Removed 16 redundant options: These are already set by LLVM's default.
  2. BinPackArguments: false: one argument per line when they don't all fit.
  3. AllowAllArgumentsOnNextLine: false: prevents dumping all args on the next line.
  4. ReflowComments: false: don't reflow comment text and preserves intentional formatting.
  5. SkipMacroDefinitionBody: true: don't reformat macro bodies.
  6. AllowShortEnumsOnASingleLine: false: one enum value per line.
  7. BreakBeforeBinaryOperators: NonAssignment: break before ||, &&.

Signed-off-by: harrylin98 <harrylin980107@gmail.com>
Signed-off-by: harrylin98 <harrylin980107@gmail.com>
Copy link
Copy Markdown

@JimB123 JimB123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few comments/notes. I just scanned files up to cluster_legacy.

Overall, I think many of the changes are neutral. Some of them are really good. A few are seem negative.

If I had to guess regarding TSC feedback, I think they'll probably nitpick the things that they don't like, and dismiss the rest as mostly neutral.

For me, I think that overall it's an improvement.

"dataset changes will be retained.",
0,
abortCommandHandler,
lua),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section isn't great. Between the expansion to multi-lines, and the shifting due to string size, I think this might generate push back.

Comment on lines +433 to 434
size_t *commands_len) {
VALKEYMODULE_NOT_USED(module_ctx);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This blends the function contents into the parameters.

Personally, I can live with this, but I'd rather see something like:

static int fn (
        int p1,
        int p2) { // indented 8 to avoid blending with code
    // code begins (indented 4)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we try ContinuationIndentWidth set at 8? Will this fix this?

case LUA_TSTRING:
ValkeyModule_ReplyWithStringBuffer(ctx, lua_tostring(lua, -1), lua_strlen(lua, -1));
break;
case LUA_TSTRING: ValkeyModule_ReplyWithStringBuffer(ctx, lua_tostring(lua, -1), lua_strlen(lua, -1)); break;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one is a negative. I like the original better.

Maybe if ALL of the case branches could fit like this, but it's inconsistent.

Comment on lines +117 to 119
if (ValkeyModule_CreateCommand(ctx, "hellocluster.pingall", PingallCommand_ValkeyCommand, "readonly", 0, 0, 0)
== VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is similar to my comment about function parameters. It bends the IF continuation with the next line.

Ideally, I'd do this

Suggested change
if (ValkeyModule_CreateCommand(ctx, "hellocluster.pingall", PingallCommand_ValkeyCommand, "readonly", 0, 0, 0)
== VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;
if (ValkeyModule_CreateCommand(ctx, "hellocluster.pingall", PingallCommand_ValkeyCommand, "readonly", 0, 0, 0)
== VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

Comment thread src/acl.c
Comment on lines +2936 to +2938
case ACL_DENIED_DB:
le->object = argpos ? sdsdup(objectGetVal(c->argv[argpos])) : sdsdup(c->cmd->fullname);
break;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case is inconsistent, but I personally like the change. I think the original line was just getting too large/complex. IMO this change helps readability.

Comment thread src/ae.h
Comment on lines +45 to +48
#define AE_BARRIER 4 /* With WRITABLE, never fire the event if the \
READABLE event already fired in the same event \
loop iteration. Useful when you want to persist \
things to disk before sending replies, and want \
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was unexpected. Why did this occur?

Comment thread src/call_reply.c
Comment on lines +367 to +368
if (rep->type != VALKEYMODULE_REPLY_STRING && rep->type != VALKEYMODULE_REPLY_SIMPLE_STRING
&& rep->type != VALKEYMODULE_REPLY_ERROR)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems worse.

Comment thread src/cluster_legacy.c
{"client-tls-port",
auxAnnounceClientTlsPortSetter,
auxAnnounceClientTlsPortGetter,
auxAnnounceClientTlsPortPresent},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems worse.

Comment thread src/cluster_legacy.c
Comment on lines +2879 to +2880
if (!(flags & (CLUSTER_NODE_FAIL | CLUSTER_NODE_PFAIL)) && nodeInNormalState(node) && node->ping_sent == 0
&& clusterNodeFailureReportsCount(node) == 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems worse. Looking at the original, why wasn't that refactored earlier?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants