forked from mathieu/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.pl
More file actions
executable file
·47 lines (39 loc) · 994 Bytes
/
comment.pl
File metadata and controls
executable file
·47 lines (39 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl
# Missing comments (it is a good idea to write a comment before a variable declaration)
# usage:
# scripts/comment.pl lib/checkstl.cpp
sub checkfile
{
my $filename = $_[0];
# parse file
open(FILE, $filename);
my @lines = <FILE>;
close(FILE);
# check comments..
my $comment = false;
my $linenr = 0;
foreach $line (@lines)
{
$linenr = $linenr + 1;
# missing comment before variable declaration?
if (($comment == 0) &&
($line =~ /^\s+([a-z]+)? [a-z]+(\s)+[a-z][a-z0-9]*\s*[;=]/) &&
(!($line =~ /return|delete|operator/)))
{
print "[$filename:$linenr] No comment before variable declaration\n";
}
# set comment variable
if (($line =~ /\/\//) || ($line =~ /\/\*/))
{
$comment = 1;
}
else
{
$comment = 0;
}
}
}
foreach $filename (@ARGV)
{
checkfile($filename)
}