File: grep-pod-section-end-comma.pl

package info (click to toggle)
libperl-critic-pulp-perl 96-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,684 kB
  • sloc: perl: 13,643; sh: 267; makefile: 6; ansic: 1
file content (280 lines) | stat: -rw-r--r-- 6,038 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/perl -w

# Copyright 2012, 2013 Kevin Ryde

# This file is part of Perl-Critic-Pulp.
#
# Perl-Critic-Pulp is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 3, or (at your option) any
# later version.
#
# Perl-Critic-Pulp is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Perl-Critic-Pulp.  If not, see <http://www.gnu.org/licenses/>.


# Usage: perl grep-pod-section-end-comma.pl
#
# Search for POD paragraphs ending with a comma.


use strict;
use warnings;
use FindBin;
use Perl6::Slurp;

use lib::abs '.';
use MyLocatePerl;
use MyStuff;

# uncomment this to run the ### lines
# use Smart::Comments;


my $verbose = 0;

my $l = MyLocatePerl->new (include_pod => 1,
                           under_directory => '/usr/share/perl5');
my $filename;
# {
#   $filename = "$FindBin::Bin/$FindBin::Script";
#   if ($verbose) { print "look at $filename\n"; }
#   my $str = Perl6::Slurp::slurp ($filename);
#   my $p = MyParser->new;
#   $p->parse_from_string ($str);
# }
my $count = 0;
while (($filename, my $str) = $l->next) {
  if ($verbose) { print "look at $filename\n"; }
  my $p = MyParser->new;
  $p->parse_from_string ($str);
  $p->check_last();
  $count++;
}
print "total $count\n";

exit 0;

package MyParser;
use base 'Perl::Critic::Pulp::PodParser';
sub new {
  my $class = shift;
  ### new() ...
  return $class->SUPER::new (last_text => '',
                             last_command => '',
                             @_);
}
sub command {
  my ($self, $command, $text, $linenum, $paraobj) = @_;
  ### command(): $command

  if ($command eq 'for' || $command eq 'pod') {
    ### ignore ...
    return;
  }

  # my $this_level = $command_level{$command} || 0;
  # my $prev_level = $command_level{$self->{'last_command'}} || 0;

  if ($command eq 'item' && $self->{'last_command'} eq 'item') {

  } elsif ($command eq 'over'
           || $command eq 'back') {

  } else {
    $self->check_last;
  }
  $self->{'last_text'} = '';
  $self->{'last_command'} = $command;
}
sub textblock {
  my ($self, $text, $linenum, $paraobj) = @_;
  ### textblock(): $text
  $self->check_last;
  if (! defined $text) {
    $text = '';
  }
  $self->{'last_linenum'} = $linenum;
  $self->{'last_text'} = $text;
}
sub verbatim {
  my ($self, $text, $linenum, $paraobj) = @_;
  ### verbatim() ...
  $self->{'last_text'} = '';
}
sub check_last {
  my ($self) = @_;
  ### check_last(): $self->{'last_text'}
  if ($self->{'last_text'} =~ /,\s*$/s) {
    print "$filename:$self->{'last_linenum'}:1: end comma\n";
    $self->{'last_text'} = '';
  }
}

=pod

=head1 ONE

Using pages like,

=for Finance_Quote_Grab symbols MNG

=over 4

blah

=back

=head1 TWO

This one bad,

This one ok.

=head2

This one ok,

=cut

=pod

    verbatim para

Blah.












=cut

# Old stuff for comma following L<> link.

# sub new {
#   my $class = shift;
#   my $self = $class->SUPER::new (last => '',
#                                  @_);
#   $self->parseopts(-process_cut_cmd => 1);
#   return $self;
# }
# 
# sub parse_from_filehandle {
#   my $self = shift;
#   $self->SUPER::parse_from_filehandle(@_);
#   $self->comma_violation_maybe;
# }
# 
# sub comma_violation_maybe {
#   my ($self) = @_;
#   if ($self->{'last'} eq 'L-comma') {
#     $self->violation_at_linenum_and_textpos
#       ("Comma after L<> at end of section, should it be a full stop, or removed?",
#        $self->{'saw_comma_linenum'},
#        $self->{'saw_comma_text'},
#        $self->{'saw_comma_textpos'});
#   }
# }
# 
# my %command_non_text = (for   => 1,
#                         begin => 1,
#                         end   => 1,
#                         cut   => 1);
# 
# sub command {
#   my ($self, $command, $text, $linenum, $paraobj) = @_;
#   ### $command
#   ### last: $self->{'last'}
#   # ### $text
# 
#   if ($command_non_text{$command}) {
#     # skip directives
#     return '';
#   }
# 
#   if (# before =over is ok
#       $command eq 'over'
# 
#       # in between successive =item is ok
#       || ($command eq 'item' && $self->{'last'} eq '=item')) {
# 
#   } else {
#     # before =head or =cut is bad
#     $self->comma_violation_maybe;
#   }
# 
#   $self->{'last'} = '';
#   return '';
# }
# 
# sub verbatim {
#   my ($self) = @_;
#   ### verbatim
#   $self->{'last'} = '';
#   return '';
# }
# 
# sub textblock {
#   my ($self, $text, $linenum, $pod_para) = @_;
#   ### textblock
#   ### $text
#   $self->{'saw_comma_linenum'} = $linenum;
#   $self->{'saw_comma_text'} = $text;
#   $self->parse_text({-expand_seq => 'textblock_seq',
#                      -expand_text => 'textblock_text' },
#                     $text, $linenum);
#   ### last now: $self->{'last'}
#   return '';
# }
# sub textblock_seq {
#   my ($self, $seq) = @_;
#   ### seqsubr: $seq
#   my $cmd = $seq->cmd_name;
#   if ($cmd eq 'L') {
#     if ($self->{'last'} eq 'L') {
#       $self->violation_at_linenum_and_textpos
#         ("Missing comma between L<> sequences",
#          $self->{'saw_comma_linenum'},
#          '', 0);
#     }
#     $self->{'last'} = 'L';
# 
#   } elsif ($cmd eq 'X') {
#     # ignore X<>
# 
#   } else {
#     # other like C<> as text
#     ### raw_text: $seq->raw_text
#     $self->textblock_text ($seq->raw_text, $seq);
#   }
#   return;
# }
# sub textblock_text {
#   my ($self, $text, $textnode) = @_;
#   ### textsubr: $text
#   ### $textnode
#   if ($text =~ /^(\s.*),\s*$/) {
#     if ($self->{'last'} eq 'L') {
#       $self->{'last'} = 'L-comma';
#       $self->{'saw_comma_textpos'} = length($text) - length($1);
#       return;
#     }
#   }
#   if ($text !~ /^\s.*$/) {
#     $self->{'last'} = '';
#   }
#   ### last now: $self->{'last'}
#   return;
# }