diff --git a/hooks/check-diff.py b/hooks/check-diff.py index 36f5b69..d2dc140 100755 --- a/hooks/check-diff.py +++ b/hooks/check-diff.py @@ -3,6 +3,7 @@ import re, sys PAT_TAB = re.compile("#?\t*[^\t]*$") +PAT_BAD_COMMENT = re.compile(r"\s*//") def checkascii(l): return any((ord(c) < 32 or ord(c) > 127) and c != '\t' for c in l) @@ -45,6 +46,9 @@ def checkascii(l): if is_source and l.startswith(" "): sys.stderr.write("*** {}:{}: Use tabs for indentation: '{}'\n".format(filename, line, l)) status = 1 + if is_source and PAT_BAD_COMMENT.match(l): + sys.stderr.write("*** {}:{}: Use /* */ for free standing comments: '{}'\n".format(filename, line, l)) + status = 1 line += 1 elif l.startswith(" "): line += 1 diff --git a/test/cases/case8.cpp b/test/cases/case8.cpp new file mode 100644 index 0000000..2ff60ae --- /dev/null +++ b/test/cases/case8.cpp @@ -0,0 +1,7 @@ +// Foo +// bar + +int foo() +{ + return bar; +} diff --git a/test/cases/case9.cpp b/test/cases/case9.cpp new file mode 100644 index 0000000..783a668 --- /dev/null +++ b/test/cases/case9.cpp @@ -0,0 +1,7 @@ + // Foo + // bar + +int foo() +{ + return bar; +} diff --git a/test/test.sh b/test/test.sh index ede5ea4..815c7a0 100755 --- a/test/test.sh +++ b/test/test.sh @@ -163,6 +163,14 @@ git_good add case7.cpp test_commit_bad "Add: Preprocessor hash indented" git_good reset case7.cpp +git_good add case8.cpp +test_commit_bad "Add: Wrong comment style" +git_good reset case8.cpp + +git_good add case9.cpp +test_commit_bad "Add: Wrong comment style" +git_good reset case9.cpp + git_good push # setup badguy