Added some code to peer into a data structure in Maemian/Schedule.pm. Also added the
[maemian] / nokia-lintian / checks / description
1 # description -- lintian check script -*- perl -*-
2
3 # Copyright (C) 1998 Christian Schwarz
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, you can find it on the World Wide
17 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
18 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20
21 package Lintian::description;
22 use strict;
23 use Spelling;
24 use Tags;
25 use Util;
26
27 sub run {
28
29 my $pkg = shift;
30 my $type = shift;
31
32 my $ppkg = quotemeta($pkg);
33 my $cf = "fields/description";
34 my $tabs = 0;
35 my $lines = 0;
36 my $template = 0;
37 my $unindented_list = 0;
38 my $synopsis;
39 my $description;
40
41 # description?
42 unless (-f $cf) {
43     tag "package-has-no-description", "";
44     return 0;
45 }
46
47 open(IN, '<', $cf) or fail("cannot open $cf for reading: $!");
48
49 # 1st line contains synopsis
50 $synopsis = <IN>;
51 $description = $synopsis;
52 chomp $synopsis;
53
54 if ($synopsis =~ m/^\s*$/) {
55     tag "description-synopsis-is-empty", "";
56 } else {
57     # Current dpkg-gencontrol appears to fix this automatically so this
58     # tag will never trigger with a current dpkg-dev.
59     if ($synopsis =~ m/^\s/) {
60         tag "description-synopsis-has-leading-spaces", "";
61     }
62     if ($synopsis =~ m/^\s*$ppkg\b/i) {
63         tag "description-starts-with-package-name", "";
64     }
65     if ($synopsis =~ m/\.\s*$/) {
66         tag "description-synopsis-might-not-be-phrased-properly", "";
67     }
68     if ($synopsis =~ m/\t/) {
69         tag "description-contains-tabs", "" unless $tabs++;
70     }
71     if (length($synopsis) >= 80) {
72         tag "description-too-long", "";
73     }
74     if ($synopsis =~ m/^\s*missing\s*$/i) {
75         tag "description-is-debmake-template", "" unless $template++;
76     } elsif ($synopsis =~ m/<insert up to 60 chars description>/) {
77         tag "description-is-dh_make-template", "" unless $template++;
78     }
79 }
80
81 while (<IN>) {
82     $description .= $_;
83     chomp;
84     next if m/^\s*$/o;
85     next if m/^\.\s*$/o;
86
87     if ($lines == 0) {
88         my $firstline = lc $_;
89         my $lsyn = lc $synopsis;
90         if ($firstline =~ /^\Q$lsyn\E$/) {
91             tag "description-synopsis-is-duplicated", "";
92         } else {
93             $firstline =~ s/[^a-zA-Z0-9]+//g;
94             $lsyn =~ s/[^a-zA-Z0-9]+//g;
95             if ($firstline eq $lsyn) {
96                 tag "description-synopsis-is-duplicated", "";
97             }
98         }
99     }
100
101     $lines++;
102
103     if (m/^\.\s*\S/o) {
104         tag "description-contains-invalid-control-statement", "";
105     } elsif (m/^[\-\*]/o) {
106         # Print it only the second time.  Just one is not enough to be sure that
107         # it's a list, and after the second there's no need to repeat it.
108         tag "possible-unindented-list-in-extended-description", "" if $unindented_list++ == 2;
109     }
110
111     if (m/\t/o) {
112         tag "description-contains-tabs", "" unless $tabs++;
113     }
114
115     if (m,^\s*Homepage: https?://,i) {
116         tag "description-contains-homepage";
117     }
118
119     my $wo_quotes = $_;
120     $wo_quotes =~ s,(\"|\')(.*?)(\1),,;
121     while ($wo_quotes =~ m,(?:\W|^)((\w+)(\s+(\2))+)(?:\W|$),i) {
122         my $words = $1;
123         $wo_quotes =~ s/\Q$words//;
124         tag "description-contains-duplicated-word", "$words";
125     }
126
127     if ($lines == 1) {
128         # checks for the first line of the extended description:
129         if (m/^\s/o) {
130             tag "description-starts-with-leading-spaces", "";
131         }
132         if (m/^\s*missing\s*$/oi) {
133             tag "description-is-debmake-template", "" unless $template++;
134         } elsif (m/<insert long description, indented with spaces>/) {
135             tag "description-is-dh_make-template", "" unless $template++;
136         }
137     }
138
139     if (length($_) >= 80) {
140         tag "extended-description-line-too-long", "";
141     }
142 }
143 close(IN);
144
145 if ($lines == 0) {
146     tag "extended-description-is-empty", "" unless $type eq 'udeb';
147 }
148
149 if ($description) {
150     spelling_check('spelling-error-in-description', $description);
151     spelling_check_picky('spelling-error-in-description', $description);
152 }
153
154 }
155
156 1;
157
158 # Local Variables:
159 # indent-tabs-mode: t
160 # cperl-indent-level: 4
161 # End:
162 # vim: syntax=perl sw=4 ts=8