[CDRIVER-1167] clang-format config Created: 21/Mar/16  Updated: 13/Dec/16  Resolved: 12/Dec/16

Status: Closed
Project: C Driver
Component/s: Build
Affects Version/s: None
Fix Version/s: 1.6.0

Type: Improvement Priority: Major - P3
Reporter: Hannes Magnusson Assignee: Hannes Magnusson
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File clang-format (2).txt    
Issue Links:
Duplicate
is duplicated by CDRIVER-706 Document coding style changes and upd... Closed
Related
related to CDRIVER-1577 Declare __cdecl as calling convention... Closed

 Description   

Lets come up with a clang-format configuration that formats the code into the ascii art of our current preference and stick to it.
Reformat the current source, fully (--commit-author "clang-format <drivers@mongodb.com>") so we can stick it into pre-commit hook.

The server did something similar recently. We might steal their configuration if reasonable.


remember to remove https://github.com/mongodb/mongo-c-driver/blob/master/src/mongoc/uncrustify.cfg and https://github.com/mongodb/mongo-c-driver/blob/master/src/mongoc/indent after the switch

http://zed0.co.uk/clang-format-configurator/



 Comments   
Comment by Githook User [ 13/Dec/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1167 fix some clang-format style
Branch: master
https://github.com/mongodb/libbson/commit/99e956db0a0f299df5693e511c74bdd2bd5cd2f1

Comment by Hannes Magnusson [ 12/Dec/16 ]

Had to explicitly disable SortIncludes as our internal include order is sensitive and not alphabetical.

Other then that, worked like a charm.. Until we find issues later

Comment by Githook User [ 12/Dec/16 ]

Author:

{u'name': u'Clang Formatter', u'email': u'drivers@mongodb.com'}

Message: CDRIVER-1167 Format mongoc with out new clang-format config
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/7f1dd3630d6bb4b8d5db4c2b865c328acd170012

Comment by Githook User [ 12/Dec/16 ]

Author:

{u'username': u'bjori', u'name': u'Hannes Magnusson', u'email': u'bjori@php.net'}

Message: CDRIVER-1167 Add clang-format file, and remove uncrustify
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/02d3fb5bed760ed589696490c993fc82677d8d3c

Comment by Githook User [ 12/Dec/16 ]

Author:

{u'name': u'Clang Formatter', u'email': u'drivers@mongodb.com'}

Message: CDRIVER-1167 Format libbson with out new clang-format config
Branch: master
https://github.com/mongodb/libbson/commit/564026426d0df5b872d2f0853ebe050b897b05b9

Comment by Githook User [ 12/Dec/16 ]

Author:

{u'username': u'bjori', u'name': u'Hannes Magnusson', u'email': u'bjori@php.net'}

Message: CDRIVER-1167 Add clang-format config & remove uncrustify
Branch: master
https://github.com/mongodb/libbson/commit/e00168bd1a2898e973253fa742ee80d025ecec2d

Comment by Hannes Magnusson [ 12/Dec/16 ]

Yep, thats right. Prototypes that overflow 80chars will have one parameter per line, with the pointer aligned to the variable, but the variable names no longer aligned consecutively – thats pretty much the only thing we are giving up I think.

Comment by A. Jesse Jiryu Davis [ 09/Dec/16 ]

I'm excited to see we have an 80-char column limit. As an emeritus Python coder, I still really like 80-char columns.

Comment by A. Jesse Jiryu Davis [ 09/Dec/16 ]

Me too. So we got pointer-alignment right, but we had to give up align consecutive declarations?:

static bool
_bson_as_json_visit_array (const bson_iter_t *iter,
                           const char *key,
                           const bson_t *v_array,
                           void *data)

That looks fine to me.

Comment by Hannes Magnusson [ 09/Dec/16 ]

https://gist.github.com/bjori/335f27790b2b1c6dfaafaa2cf1bbea93

Having swallowed the ascii art bullet in the pointeralignment.. I'm actually quite happy with how this looks.

Comment by Mark Benvenuto [ 19/Jul/16 ]

While you could make a fix upstream with the appropriate test cases, it would be cheaper to just use "uncrustify" if it just works. This is not the first time where I have seen clang-format options combinations either not work, or where one option dominates another (AlignOpenBrackets is another).

Comment by A. Jesse Jiryu Davis [ 19/Jul/16 ]

Huh, do you think it's profitable to try to contribute a fix to clang-format for that bug, or shall we change our style to PointerAlignment "left" (yuck), or use a different tool like "uncrustify" that does support our current style?

Comment by Mark Benvenuto [ 19/Jul/16 ]

jesse This is a bug in clang-format unfortunately with AlignConsecutiveDeclarations and PointerAlignment::Right. See the comment in the code:
https://github.com/llvm-mirror/clang/blob/08708dba6769ab21832b9c4a0e8e1d5df2b7377a/lib/Format/WhitespaceManager.cpp#L327-L340

Comment by A. Jesse Jiryu Davis [ 19/Jul/16 ]

Attached clang-format (2).txt comes close to our existing style. However, it formats signatures like this:

mongoc_async_cmd_t *
mongoc_async_cmd_new (mongoc_async_t *         async,
                      mongoc_stream_t *        stream,
                      mongoc_async_cmd_setup_t setup)
 {

Whereas we want this:

mongoc_async_cmd_t *
mongoc_async_cmd_new (mongoc_async_t           *async,
                      mongoc_stream_t          *stream,
                      mongoc_async_cmd_setup_t  setup)
{

I've set AlignConsecutiveDeclarations "true" and PointerAlignment "right". mark.benvenuto do you know if there's a way to get the asterisks all the way to the right with aligned declarations like this?

Generated at Wed Feb 07 21:11:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.