Browse Source

CODING_STYLE: specify the indent rule for multiline code

We didn't specify the indent rule for multiline code here, which may
mislead users. And in current code, the code use various styles.

Add this rule in CODING_STYLE to make sure this is clear to every one.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
Suggested-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <2019030407.27567-2-richardw.yang@linux.intel.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
tags/v4.1.0-rc0
Wei Yang 4 months ago
parent
commit
6ac1fca4ef
1 changed files with 39 additions and 0 deletions
  1. 39
    0
      CODING_STYLE

+ 39
- 0
CODING_STYLE View File

@@ -29,6 +29,45 @@ Spaces of course are superior to tabs because:
29 29
 
30 30
 Do not leave whitespace dangling off the ends of lines.
31 31
 
32
+1.1 Multiline Indent
33
+
34
+There are several places where indent is necessary:
35
+
36
+ - if/else
37
+ - while/for
38
+ - function definition & call
39
+
40
+When breaking up a long line to fit within line width, we need a proper indent
41
+for the following lines.
42
+
43
+In case of if/else, while/for, align the secondary lines just after the
44
+opening parenthesis of the first.
45
+
46
+For example:
47
+
48
+    if (a == 1 &&
49
+        b == 2) {
50
+
51
+    while (a == 1 &&
52
+           b == 2) {
53
+
54
+In case of function, there are several variants:
55
+
56
+    * 4 spaces indent from the beginning
57
+    * align the secondary lines just after the opening parenthesis of the
58
+      first
59
+
60
+For example:
61
+
62
+    do_something(x, y,
63
+        z);
64
+
65
+    do_something(x, y,
66
+                 z);
67
+
68
+    do_something(x, do_another(y,
69
+                               z));
70
+
32 71
 2. Line width
33 72
 
34 73
 Lines should be 80 characters; try not to make them longer.

Loading…
Cancel
Save