~widelands-dev/widelands/bug-1654989-fuzzy-terrain-images

« back to all changes in this revision

Viewing changes to cmake/codecheck/rules/multiline_single-statement-controlling_control-statement_not_wrapped_before_controlled_statement

  • Committer: qcs
  • Date: 2010-02-05 01:13:20 UTC
  • Revision ID: git-v1:136d6c48811c97ec1f98301726134b0de66f868c
Manual merge of cmake-migration branch to trunk

git-svn-id: https://widelands.svn.sourceforge.net/svnroot/widelands/trunk@5030 37b2a8de-5219-0410-9f54-a31bc463ab9c

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
 
 
4
"""
 
5
This was added to find some of the stuff that annoys Nicolai, such as:
 
6
   if (a) throw wexception
 
7
      ("Message explaining what went wrong, using format "
 
8
       "argument such as %u, %ill and %s",
 
9
       7, -9380350846789, "hej");
 
10
 
 
11
He requires it to be formatted like this instead:
 
12
   if (a)
 
13
      throw wexception
 
14
         ...
 
15
 
 
16
So a line with "for (a)", "if (a)" or "while (a)" must end with one of the
 
17
characters in the string "){};\". Although a comment at the end is allowed
 
18
(therefore the complex regexp).
 
19
 
 
20
It would indeed be inconsistent to wrap within the controlled statement without
 
21
wrapping before it. A justification to do that would be to save vertical screen
 
22
space.
 
23
 
 
24
Do the same for do, else and return statements. Unfortunately it will miss
 
25
lines ending with do or else followed by something very short (a single letter,
 
26
                                                               like "do a" or
 
27
                                                               "else a")
 
28
because it has to allow "do if" and "else if".
 
29
"""
 
30
 
 
31
error_msg = """Multiline conditional should break after conditional. if (a) blah... -> if (a) \\n blah"""
 
32
 
 
33
regexp=r"""(?x)
 
34
^
 
35
(
 
36
    [^/\#"']|/([^/"']|"([^"\]|\\"|\\[^"])*"|'(\\[\'0nt]|[^\'])')|"([^"]|\\")*"|'(\\[\'0nt]|[^\'])'
 
37
)*
 
38
(
 
39
    (^|\t)((do|else)[ ]([^/i]|(i[^f]))|return[ ]+)|(for|if|while)[ ]*\((/[^/*]|[^/])*\)[ ]*
 
40
)
 
41
(/[^/*]|[^/])*
 
42
[^){};\\ \n]$"""
 
43
 
 
44
forbidden = [
 
45
    'do hl',
 
46
    '   do gam',
 
47
    'else hl',
 
48
    '   else gam',
 
49
    'return a ?',
 
50
    '   return hlj',
 
51
    'if (condition) do_something',
 
52
    'if (a) throw wexception',
 
53
]
 
54
 
 
55
allowed = [
 
56
    '   do if',
 
57
    '   do //  something',
 
58
    '   else if',
 
59
    '   else //  something',
 
60
    '   return a ? b : c;',
 
61
    '   return',
 
62
    '\return this is a doxygen comment',
 
63
    '\todo',
 
64
    'if (condition) do_something();',
 
65
    'if (c) throw wexception("Something went wrong.");',
 
66
    'if (c)',
 
67
    '   ("calculated value for (%i, %i)",',
 
68
    '\t\treturn m_nb; ',
 
69
    '\t\treturn m_nb;\n',
 
70
]