aboutsummaryrefslogtreecommitdiff
path: root/docs/notes/style_checks.txt
blob: 9ef130220cf67c998bee79cb718d6c663b89ac75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

style checks
============

uncontroversial checks
----------------------

    if()
      ^ no space between control keyword and parenthesis
        (this does not apply to "function-like" keywords)
        (note that the parenthesis is usually not required)
    
    f ();
     ^ space between function name and arguments parenthesis.
       applies to both declarations and calls.
    
    x ;
     ^ space between expression and semicolon
    
    x ^;
    x ?;
      ^ space before ^ or ? operator
    
    @ x;
     ^ space after @ operator
    
    int ^
    int ?
    int *+>
    int #[10]
        ^ space before type suffix (but spacing is allowed inside #[]).
          also, note that "int own^ x" is allowed, but "int own ^ x" isn't.
    
    f(); g(
    ); h;
      ^ statement starts in the middle of a line and spans multiple lines
    fi();{
    }
    ^ statement starts in the middle of a line and spans multiple lines
    
        if x {
    }
    ^ closing bracket not aligned with statement header
    
    if x {
        }
        ^ closing bracket not alogined with statement header
    
    if x
        {
        ^ opening bracket is on separate line but not aligned with statement header.
    
    if x
    // empty lines here
    {
    ^ one or more empty lines between statement header and opening bracket
      (but it's allowed to have empty lines before a bare compound statement)
    
    if x {
    } if y { z; }
      ^ statement after multiline statement should start on a separate line
        (but comments are allowed)
    
    if x
        continue;
        return 1;
        ^ wrong indentation
    
    return; (optional whitespace) }
      ^ void return at the end of function (note that if there's code
        commented out after the return, it should be accepted)
    
            /* 
    int x;   * bla bla
             */
             ^  block comment hides code to the left of it.
    
    - mixing tabs and spaces in indentation
    - trailing whitespace after a line (but not for indentation)
    - no newline at the end of the file
    - enforce that the source files are UTF-8 encoded
    - forbid certain bytes and UTF-8 characters:
        0x00-0x1F, except 0x09, 0x0A, 0x0D and form feed
        0x7F-0xA0 (some of these affect terminals, and 0x85 can apparently cause problems in Python)
        0xFE
        0xFF
        U+2028, U+2029 (Unicode linefeed)
        U+FDD0, U+FFFF, U+1FFFF, 
        any overlong UTF-8 sequence
        any Unicode combininig marks not in NFC order (or perhaps _any_ combining marks)
    - forbid those outside of comments:
        U+200B, U+200C, U+200D, (ZWSP etc.)
        perhaps U+200E U+200F (ltr, rtl mark)
        also, ‐ (Unicode hyphen) can be deceptive
        perhaps any Unicode whitespace character?
        perhaps any Unicode operator-like or character-like character?
    - perhaps have an option to allow/forbid Unicode outside of comments and strings
    
    
controversial checks
--------------------

    if a{
        ^ no space before {
    else{
        ^ no space before {
    
    }else
     ^ no space/newline after }
     
    1 * 2+3
       ^ deceptive use of spaces (this could be used for alignment)

    1_00_000
     ^ confusing usage of _ in number.
       (but in some countries numbers might be written like this)
       also, numbers like 1_000_00 can be used for currencies.

    - no newline between function header and {
    - newline between control statement header and {
    - newline between } and "else" or "while"
    - using not 4 spaces for indentation
    - using tabs for indentation


bad checks, won't be added
--------------------------

    - checking for too many / to few spaces in the middle of a line,
      or in the beginning of second (or later) line in a multi-line
      expression/definition/statement/etc, because this is in fact very
      useful for alignment.
    - checking that statements begin at the beginning of a line, because
      it's useful to be able to call functions in a table, e.g.:
          a1(1);  b1(2); c1(3);
          a2(1);  b2(2); c2(3);