Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make Clang-Format ignore comments for line break

Is it possible to tell Clang-Format to ignore comments for line break operations? The idea is to follow the style "the code is well formatted, even if comments exceed the line break margin". Code should not be split in multiple lines, if it does not exceed the margin, but the comment does.

e.g.

//desired behaviour:
short code = shortCode + 
        longlonglongCode;
short code = shortCode; //long comment without a line break

//not desired behaviour:
short code =
    shortCode;  //long comment without a line break
like image 273
yar Avatar asked Jun 24 '17 01:06

yar


1 Answers

ReflowComments: (bool)

If true, clang-format will attempt to re-flow comments.

false:
// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
/* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */

true:
// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
// information
/* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
 * information */

Source

Use ReflowComments: true, when enabled it will add 1 space after // and brake comments when reach limit.

You can use PenaltyBreakComment to adjust.
E.g. block braking lines PenaltyBreakComment: 1000000000

like image 76
Stargateur Avatar answered Sep 18 '22 14:09

Stargateur