sysprog21 / fibdrv

Linux kernel module that calculates Fibonacci numbers
https://hackmd.io/@sysprog/linux2023-fibdrv
MIT License
41 stars 335 forks source link

Allow author skip format check failure #1

Closed tfliao closed 5 years ago

tfliao commented 5 years ago

Unify coding style is good, but sometimes the style doesn't match the running style of editing file, or something else. It will be good if we allow programmer to use their judgement on this topic.

for example, I created an array of struct attribute for my attribute_group, but clang-format think all attributes should be declared in single line.

 static struct attribute *attrs[] = {                               
-    &result_attribute.attr,                                        
-    &reset_attribute.attr,                                         
+    &result_attribute.attr, &reset_attribute.attr,                 
     NULL, /* need to NULL terminate the list of attributes */      
 };                                                                 
jserv commented 5 years ago

For such special cases, it is simply best to instruct clang to not indent that block of code:

/* clang-format off */
...The Code...
/* clang-format on */

There is absolutely no way how you can teach an AST pretty printer to get that particular piece of code indented the way you want.

Never skip format check at first glance.