1
|
1 |
# #################################################################
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
#
|
|
5 |
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
6 |
#
|
|
7 |
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
8 |
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9 |
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10 |
#
|
|
11 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
12 |
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
|
|
13 |
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
14 |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
15 |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
|
|
16 |
#
|
|
17 |
# todocomments.py
|
|
18 |
#
|
|
19 |
# Checks : "To do" comments.
|
|
20 |
#
|
|
21 |
# Reason : "To do" comments in code suggest that it is not finished.
|
|
22 |
#
|
|
23 |
# #################################################################
|
|
24 |
|
|
25 |
script = CScript("todocomments")
|
|
26 |
script.iReString = r"""
|
|
27 |
/(/|\*) # "//" or "/*"
|
|
28 |
.*(t|T)(o|O)(d|D)(o|O) # skip to Todo
|
|
29 |
"""
|
|
30 |
script.iFileExts = ["h", "cpp", "c"]
|
|
31 |
script.iCategory = KCategoryCodeReviewGuides
|
|
32 |
script.iIgnore = KIgnoreQuotes
|
|
33 |
script.iSeverity = KSeverityLow
|
|
34 |
|
|
35 |
def todocommentcodecompare(lines, currentline, rematch, filename):
|
|
36 |
m = rematch.search(lines[currentline])
|
|
37 |
if m:
|
|
38 |
line = lines[currentline]
|
|
39 |
i = 0
|
|
40 |
inCommentBlock = 0
|
|
41 |
|
|
42 |
while i < len(line):
|
|
43 |
if not inCommentBlock:
|
|
44 |
if (line[i] == "/"):
|
|
45 |
if (line[i + 1] == "/"):
|
|
46 |
return 1
|
|
47 |
elif (line[i + 1] == "*"):
|
|
48 |
inCommentBlock = 1
|
|
49 |
i += 2
|
|
50 |
continue
|
|
51 |
else:
|
|
52 |
endIndex = line[i:].find("*/")
|
|
53 |
if (endIndex <> -1):
|
|
54 |
inCommentBlock = 0
|
|
55 |
# note, that first character is ignored in comments as can be direction to the in-source documentation tool
|
|
56 |
if (line[i+1:i + endIndex + 2].lower().find("todo") <> -1):
|
|
57 |
return 1
|
|
58 |
i += endIndex + 2
|
|
59 |
continue
|
|
60 |
else:
|
|
61 |
return 1
|
|
62 |
i += 1
|
|
63 |
return 0
|
|
64 |
|
|
65 |
script.iCompare = todocommentcodecompare
|
|
66 |
scanner.AddScript(script)
|