Skip to content

Commit

Permalink
Fix: Check comment blocks leading /* on separate line
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Gautier committed Feb 10, 2017
1 parent 2c55d79 commit 6694a40
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
9 changes: 9 additions & 0 deletions betty-style.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2952,6 +2952,15 @@ sub process {
"networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
}

# Block comments use /* on leading line
if ($rawline !~ m@^.\s*/\*\s*$@ && #leading /*
$rawline !~ m@^.*/\*.*\*/\s*$@ && #inline /*...*/
$rawline !~ m@^.*/\*{2,}\s*$@ && #leading /**
$rawline =~ m@^.\s*/\*+.+\s*$@) { #/* non blank
WARN("BLOCK_COMMENT_STYLE",
"Block comments use a leading /* on a separate line\n" . $herecurr);
}

# Block comments use * on subsequent lines
if ($prevline =~ /$;[ \t]*$/ && #ends in comment
$prevrawline =~ /^\+.*?\/\*/ && #starting /*
Expand Down
6 changes: 3 additions & 3 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ do
if [ "$output" != "$exp" ]
then
echo -e "\t${RED}Error. The output is not the one expected:${NC}"
echo $output
echo "$output"
let errors++
else
echo -e "\t${GREEN}Test passed successfully!${NC}"
Expand Down Expand Up @@ -122,15 +122,15 @@ do
if [ "$output" != "$exp_stdout" ]
then
echo -e "\t${RED}Error. The output (stdout) is not the one expected:${NC}"
echo $output
echo "$output"
let errors++
else
echo -e "\t${GREEN}Test passed successfully!${NC}"
fi
if [ "$err" != "$exp_stderr" ]
then
echo -e "\t${RED}Error. The error output (stderr) is not the one expected:${NC}"
echo $err
echo "$err"
let errors++
else
echo -e "\t${GREEN}Test passed successfully!${NC}"
Expand Down
4 changes: 4 additions & 0 deletions tests/style/comments/comments0.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
/* Bad
* multi-line
* comment */

/** Also
very bad
comment*/
6 changes: 5 additions & 1 deletion tests/style/comments/comments0.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
tests/style/comments/comments0.c:3: ERROR: do not use C99 // comments
tests/style/comments/comments0.c:14: WARNING: Block comments use a leading /* on a separate line
tests/style/comments/comments0.c:16: WARNING: Block comments use a trailing */ on a separate line
total: 1 errors, 1 warnings, 16 lines checked
tests/style/comments/comments0.c:18: WARNING: Block comments use a leading /* on a separate line
tests/style/comments/comments0.c:19: WARNING: Block comments use * on subsequent lines
tests/style/comments/comments0.c:20: WARNING: Block comments use a trailing */ on a separate line
total: 1 errors, 5 warnings, 20 lines checked

0 comments on commit 6694a40

Please sign in to comment.