Skip to content

Commit 3afe705

Browse files
committed
Add: Check comment style.
1 parent b3ea59a commit 3afe705

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

hooks/check-diff.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re, sys
44

55
PAT_TAB = re.compile("#?\t*[^\t]*$")
6+
PAT_BAD_COMMENT = re.compile(r"\s*//")
67

78
def checkascii(l):
89
return any((ord(c) < 32 or ord(c) > 127) and c != '\t' for c in l)
@@ -45,6 +46,9 @@ def checkascii(l):
4546
if is_source and l.startswith(" "):
4647
sys.stderr.write("*** {}:{}: Use tabs for indentation: '{}'\n".format(filename, line, l))
4748
status = 1
49+
if is_source and PAT_BAD_COMMENT.match(l):
50+
sys.stderr.write("*** {}:{}: Use /* */ for free standing comments: '{}'\n".format(filename, line, l))
51+
status = 1
4852
line += 1
4953
elif l.startswith(" "):
5054
line += 1

test/cases/case8.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Foo
2+
// bar
3+
4+
int foo()
5+
{
6+
return bar;
7+
}

test/cases/case9.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Foo
2+
// bar
3+
4+
int foo()
5+
{
6+
return bar;
7+
}

test/test.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ git_good add case7.cpp
163163
test_commit_bad "Add: Preprocessor hash indented"
164164
git_good reset case7.cpp
165165

166+
git_good add case8.cpp
167+
test_commit_bad "Add: Wrong comment style"
168+
git_good reset case8.cpp
169+
170+
git_good add case9.cpp
171+
test_commit_bad "Add: Wrong comment style"
172+
git_good reset case9.cpp
173+
166174
git_good push
167175

168176
# setup badguy

0 commit comments

Comments
 (0)