10
10
#define "AA" <== Violation. file comment should be the first element of file.
11
11
///
12
12
/// blar blar
13
- /// Copyright reserved.
13
+ /// Copyright reserved.
14
14
///
15
-
16
- = start of file =
15
+
16
+ = start of file =
17
17
/** <== Violation. No copyright string.
18
- * blar blar
18
+ * blar blar
19
19
* blar blar
20
20
*/
21
-
21
+
22
22
== Good ==
23
23
24
- = start of file =
24
+ = start of file =
25
25
///
26
26
/// blar blar
27
27
/// Copyright reserved. <== Correct
28
+ /// file
29
+ /// author
30
+ /// date
31
+ /// version
32
+ /// brief
28
33
///
29
-
30
- = start of file =
34
+
35
+ = start of file =
31
36
/**
32
37
* blar blar
33
38
* Copyright reserved. <== Correct
39
+ * file
40
+ * author
41
+ * date
42
+ * version
43
+ * brief
34
44
* blar blar
35
45
*/
36
46
"""
37
- from nsiqcppstyle_rulehelper import *
47
+ from nsiqcppstyle_rulehelper import *
38
48
from nsiqcppstyle_reporter import *
39
49
from nsiqcppstyle_rulemanager import *
40
50
51
+ def error (lexer ):
52
+ nsiqcppstyle_reporter .Error (DummyToken (lexer .filename , "" , 1 , 0 ),
53
+ __name__ , """Please provide file info comment in front of
54
+ file. It includes license/copyright information along
55
+ with filename, author, date of modification, version and
56
+ a brief description""" )
57
+
41
58
def RunRule (lexer , filename , dirname ) :
42
59
43
60
t = lexer .GetNextTokenSkipWhiteSpace ()
44
61
if t == None : return
45
- if t .type == "COMMENT" :
46
- if t .value .lower ().find ("copyright" ) == - 1 :
47
- nsiqcppstyle_reporter .Error (DummyToken (lexer .filename , "" , 1 , 0 ), __name__ , "Please provide file info comment in front of file" )
48
-
49
- elif t .type == "CPPCOMMENT" :
62
+ if t .type in ("COMMENT" , "CPPCOMMENT" ) :
50
63
find = False
51
64
while (t != None and t .type == "CPPCOMMENT" ) :
52
- if t .value .lower ().find ("copyright" ) != - 1 :
65
+ if t .value .lower ().find ("copyright" ) != - 1 or t . value . lower (). find ( "license" ) != - 1 :
53
66
find = True
54
67
break ;
55
68
t = lexer .GetNextTokenSkipWhiteSpace ()
56
69
if not find :
57
- nsiqcppstyle_reporter . Error ( DummyToken ( lexer . filename , "" , 1 , 0 ), __name__ , "Please provide file info comment in front of file" )
70
+ error ( lexer )
58
71
else :
59
- nsiqcppstyle_reporter . Error ( DummyToken ( lexer . filename , "" , 1 , 0 ), __name__ , "Please provide file info comment in front of file" )
60
-
72
+ error ( lexer )
73
+
61
74
ruleManager .AddFileStartRule (RunRule )
62
75
63
76
###########################################################################################
@@ -67,7 +80,7 @@ def RunRule(lexer, filename, dirname) :
67
80
from nsiqunittest .nsiqcppstyle_unittestbase import *
68
81
class testRule (nct ):
69
82
def setUpRule (self ):
70
- ruleManager .AddFileStartRule (RunRule )
83
+ ruleManager .AddFileStartRule (RunRule )
71
84
def test1 (self ):
72
85
self .Analyze ("thisfile.c" ,"""
73
86
// license
@@ -110,4 +123,4 @@ def test6(self):
110
123
#define "WEWE"
111
124
#include </ewe/kk> """ )
112
125
assert not CheckErrorContent (__name__ )
113
-
126
+
0 commit comments