Skip to content

Commit 89b50c8

Browse files
committed
Fix: code-related vera++ rules should not be enforced in comments
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent 69291e2 commit 89b50c8

File tree

2 files changed

+78
-15
lines changed

2 files changed

+78
-15
lines changed
Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/tclsh
22

3-
# Copyright 2015 Samsung Electronics Co., Ltd.
3+
# Copyright 2015-2016 Samsung Electronics Co., Ltd.
4+
# Copyright 2016 University of Szeged
45
#
56
# Licensed under the Apache License, Version 2.0 (the "License");
67
# you may not use this file except in compliance with the License.
@@ -14,12 +15,43 @@
1415
# See the License for the specific language governing permissions and
1516
# limitations under the License.
1617

17-
foreach f [getSourceFileNames] {
18-
set lineNumber 1
19-
foreach line [getAllLines $f] {
20-
if {[regexp {[[:graph:]][[:blank:]]+\)} $line]} {
21-
report $f $lineNumber "there should be no blank characters before closing parentheses"
18+
proc check_part_of_the_file {file line_num col_start col_end} {
19+
if {$col_start == $col_end} {
20+
return
21+
}
22+
23+
set line [getLine $file $line_num]
24+
set line [string range $line $col_start $col_end]
25+
26+
if {[regexp {[[:graph:]][[:blank:]]+\)} $line]} {
27+
report $file $line_num "there should be no blank characters before closing parentheses"
28+
}
29+
}
30+
31+
foreach fileName [getSourceFileNames] {
32+
set checkLine 1
33+
set checkColStart 0
34+
set seenOmitToken false
35+
foreach token [getTokens $fileName 1 0 -1 -1 {}] {
36+
set lineNumber [lindex $token 1]
37+
set colNumber [lindex $token 2]
38+
set tokenType [lindex $token 3]
39+
40+
if {$checkLine != $lineNumber} {
41+
if {!$seenOmitToken} {
42+
check_part_of_the_file $fileName $checkLine $checkColStart end
43+
}
44+
set checkColStart $colNumber
45+
set checkLine $lineNumber
46+
} elseif {$seenOmitToken} {
47+
set checkColStart $colNumber
48+
}
49+
50+
if {$tokenType in {ccomment cppcomment stringlit}} {
51+
check_part_of_the_file $fileName $checkLine $checkColStart $colNumber
52+
set seenOmitToken true
53+
} else {
54+
set seenOmitToken false
2255
}
23-
incr lineNumber
2456
}
2557
}

tools/vera++/scripts/rules/jerry_pointer_declarator_space.tcl

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,45 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18-
foreach f [getSourceFileNames] {
19-
set lineNumber 1
20-
foreach line [getAllLines $f] {
21-
if {[regexp {\w\*\s\w+} $line]
22-
|| [regexp {\w\*\)} $line]
23-
|| [regexp {\w\*$} $line]} {
24-
report $f $lineNumber "there should be a space between the referenced type and the pointer declarator."
18+
proc check_part_of_the_file {file line_num col_start col_end} {
19+
if {$col_start == $col_end} {
20+
return
21+
}
22+
23+
set line [getLine $file $line_num]
24+
set line [string range $line $col_start $col_end]
25+
26+
if {[regexp {\w\*\s\w+} $line]
27+
|| [regexp {\w\*\)} $line]
28+
|| [regexp {\w\*$} $line]} {
29+
report $file $line_num "there should be a space between the referenced type and the pointer declarator."
30+
}
31+
}
32+
33+
foreach fileName [getSourceFileNames] {
34+
set checkLine 1
35+
set checkColStart 0
36+
set seenOmitToken false
37+
foreach token [getTokens $fileName 1 0 -1 -1 {}] {
38+
set lineNumber [lindex $token 1]
39+
set colNumber [lindex $token 2]
40+
set tokenType [lindex $token 3]
41+
42+
if {$checkLine != $lineNumber} {
43+
if {!$seenOmitToken} {
44+
check_part_of_the_file $fileName $checkLine $checkColStart end
45+
}
46+
set checkColStart $colNumber
47+
set checkLine $lineNumber
48+
} elseif {$seenOmitToken} {
49+
set checkColStart $colNumber
50+
}
51+
52+
if {$tokenType in {ccomment cppcomment stringlit}} {
53+
check_part_of_the_file $fileName $checkLine $checkColStart $colNumber
54+
set seenOmitToken true
55+
} else {
56+
set seenOmitToken false
2557
}
26-
incr lineNumber
2758
}
2859
}

0 commit comments

Comments
 (0)