summaryrefslogtreecommitdiff
path: root/src/haddock/haddock-check.perl
blob: 57e311ed2dfd873c16a45428d21af6b6e2f71816 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

# checking that a file is haddocky

# limitations:
#   - does not check that type aliases are put in the export list
#   - there might be some problems with nested comments

$operSym = qr/[\!\#\$\%\&\*\+\.\/\<\=\>\?\@\\\^\|\-\~\:]+/;
$funSym = qr/[a-z]\w*\'*/;

for $file (@ARGV) {
  $file =~ s/\.hs//;

  open F, "<$file.hs";
  $_ = join "", <F>;
  close F;

  # print "- $file\n";

  # removing comments
  s/\{-.*?-\}//gs;
  s/--.*?\n/\n/g;

  # export list
  if (/\nmodule\s+(\w+)\s+\((.*?)\)\s+where/s) {
    ($module, $exportlist) = ($1, $2);

    # removing modules from exportlist
    $exportlist =~ s/module\s+[A-Z]\w*//gs;

    # type signatures
    while (/\n($funSym)\s*::/gs) {
      $function = $1;
      # print "- $function\n";
      $exportlist =~ s/\b$function\b//;
    }

    while (/\n(\($operSym\))\s*::/gs) {
      $function = $1;
      # print ": $function\n";
      $exportlist =~ s/\Q$function\E//;
    }

    # type aliases
    while (/\ntype\s+(\w+)/gs) {
      $type = $1;
      next if $exportlist =~ /\b$type\b/;
      printf "%-30s | Type alias not in export list: %s\n", $file, $type;
    }

    # exported functions without type signatures
    while ($exportlist =~ /(\b$funSym\b|\($operSym\))/gs) {
      $function = $1;
      # print "+ $function\n";
      next if $function =~ /^[A-Z]/;
      next if $function =~ /^\((\.\.|\:\:?|\=|\\|\||\<\-|\-\>|\@|\~|\=\>)\)$/;
      printf "%-30s | No type signature for function: %s\n", $file, $function;
    }

  } else {
    # modules without export lists
    printf "%-30s | No export list\n", $file;
  }

}