File Coverage

File:lib/CheckSpelling/SpellingCollator.pm
Coverage:84.4%

linestmtbrancondsubtimecode
1#! -*-perl-*-
2
3package CheckSpelling::SpellingCollator;
4
5our $VERSION='0.1.0';
6
1
1
1
105868
1
22
use warnings;
7
1
1
1
2
0
23
use File::Path qw(remove_tree);
8
1
1
1
199
1
2230
use CheckSpelling::Util;
9
10my %letter_map;
11my %ignored_event_map;
12my $disable_word_collating;
13
14my %last_seen;
15
16sub get_field {
17
40
35
  my ($record, $field) = @_;
18
40
468
  return 0 unless $record =~ (/\b$field:\s*(\d+)/);
19
28
36
  return $1;
20}
21
22sub get_array {
23
2
2
  my ($record, $field) = @_;
24
2
16
  return () unless $record =~ (/\b$field: \[([^\]]+)\]/);
25
2
2
  my $values = $1;
26
2
3
  return split /\s*,\s*/, $values;
27}
28
29sub maybe {
30
7
6
  my ($next, $value) = @_;
31
7
7
  $next = $value unless $next && $next < $value;
32
7
4
  return $next;
33}
34
35my %expected = ();
36sub expect_item {
37
104
72
  my ($item, $value) = @_;
38
104
41
  our %expected;
39
104
45
  my $next;
40
104
100
  if (defined $expected{$item}) {
41
26
27
    $next = $expected{$item};
42
26
22
    $next = $value if $value < $next;
43  } elsif ($item =~ /^([A-Z])(.*)/) {
44
12
8
    $item = $1 . lc $2;
45
12
10
    if (defined $expected{$item}) {
46
2
1
      $next = $expected{$item};
47
2
2
      $next = maybe($next, $value + .1);
48    } else {
49
10
4
      $item = lc $item;
50
10
9
      if (defined $expected{$item}) {
51
5
4
        $next = $expected{$item};
52
5
3
        $next = maybe($next, $value + .2);
53      }
54    }
55  }
56
104
93
  return 0 unless defined $next;
57
33
23
  $expected{$item} = $next;
58
33
67
  return $value;
59}
60
61sub skip_item {
62
55
29
  my ($word) = @_;
63
55
33
  return 1 if expect_item($word, 1);
64
35
20
  my $key = lc $word;
65
35
17
  return 2 if expect_item($key, 2);
66
35
46
  if ($key =~ /.s$/) {
67
2
3
    if ($key =~ /ies$/) {
68
1
2
      $key =~ s/ies$/y/;
69    } else {
70
1
2
      $key =~ s/s$//;
71    }
72  } elsif ($key =~ /^(.+[^aeiou])ed$/) {
73
1
1
    $key = $1;
74  } elsif ($key =~ /^(.+)'[ds]$/) {
75
6
5
    $key = $1;
76  } else {
77
26
20
    return 0;
78  }
79
9
5
  return 3 if expect_item($key, 3);
80
0
0
  return 0;
81}
82
83sub should_skip_warning {
84
75
50
  my ($warning) = @_;
85
75
97
  if ($warning =~ /\(([-\w]+)\)$/) {
86
71
40
    my ($code) = ($1);
87
71
25
    our %ignored_event_map;
88
71
52
    return 1 if $ignored_event_map{$code};
89  }
90
74
64
  return 0;
91}
92
93sub log_skip_item {
94
51
67
  my ($item, $file, $warning, $unknown_word_limit) = @_;
95
51
30
  return 1 if should_skip_warning $warning;
96
51
28
  return 1 if skip_item($item);
97
22
13
  our %seen;
98
22
10
  my $seen_count = $seen{$item};
99
22
16
  if (defined $seen_count) {
100
9
12
    if (!defined $unknown_word_limit || ($seen_count++ < $unknown_word_limit)) {
101
8
31
      print MORE_WARNINGS "$file$warning\n";
102    } else {
103
1
1
      our %last_seen;
104
1
1
      $last_seen{$item} = "$file$warning";
105    }
106
9
10
    $seen{$item} = $seen_count;
107
9
13
    return 1;
108  }
109
13
8
  $seen{$item} = 1;
110
13
11
  return 0;
111}
112
113sub stem_word {
114
22
17
  my ($key) = @_;
115
22
5
  our $disable_word_collating;
116
22
14
  return $key if $disable_word_collating;
117
118
22
20
  if ($key =~ /.s$/) {
119
3
3
    if ($key =~ /ies$/) {
120
1
4
      $key =~ s/ies$/y/;
121    } else {
122
2
4
      $key =~ s/s$//;
123    }
124  } elsif ($key =~ /.[^aeiou]ed$/) {
125
1
2
    $key =~ s/ed$//;
126  }
127
22
15
  return $key;
128}
129
130sub collate_key {
131
86
52
  my ($key) = @_;
132
86
29
  our $disable_word_collating;
133
86
51
  if ($disable_word_collating) {
134
16
16
    $char = lc substr $key, 0, 1;
135  } else {
136
70
43
    $key = lc $key;
137
70
45
    $key =~ s/''+/'/g;
138
70
53
    $key =~ s/'[sd]$//;
139
70
37
    $key =~ s/^[^Ii]?'+(.*)/$1/;
140
70
32
    $key =~ s/(.*?)'$/$1/;
141
70
61
    $char = substr $key, 0, 1;
142  }
143
86
118
  return ($key, $char);
144}
145
146sub load_expect {
147
12
444
  my ($expect) = @_;
148
12
4
  our %expected;
149
12
15
  %expected = ();
150
12
93
  if (open(EXPECT, '<:utf8', $expect)) {
151
12
75
    while ($word = <EXPECT>) {
152
43
60
      $word =~ s/\R//;
153
43
75
      $expected{$word} = 0;
154    }
155
12
30
    close EXPECT;
156  }
157}
158
159sub harmonize_expect {
160
11
5
  our $disable_word_collating;
161
11
5
  our %letter_map;
162
11
4
  our %expected;
163
164
11
16
  for my $word (keys %expected) {
165
40
19
    my ($key, $char) = collate_key $word;
166
40
35
    my %word_map = ();
167
40
45
    next unless defined $letter_map{$char}{$key};
168
15
15
4
21
    %word_map = %{$letter_map{$char}{$key}};
169
15
18
    next if defined $word_map{$word};
170
3
2
    my $words = scalar keys %word_map;
171
3
3
    next if $words > 2;
172
3
1
    if ($word eq $key) {
173
1
2
      next if ($words > 1);
174    }
175
2
3
    delete $expected{$word};
176  }
177}
178
179sub group_related_words {
180
12
5
  our %letter_map;
181
12
1
  our $disable_word_collating;
182
12
13
  return if $disable_word_collating;
183
184  # group related words
185
10
22
  for my $char (sort CheckSpelling::Util::number_biased keys %letter_map) {
186
19
19
6
18
    for my $plural_key (sort keys(%{$letter_map{$char}})) {
187
22
10
      my $key = stem_word $plural_key;
188
22
22
      next if $key eq $plural_key;
189
4
5
      next unless defined $letter_map{$char}{$key};
190
3
3
1
6
      my %word_map = %{$letter_map{$char}{$key}};
191
3
3
14
3
      for $word (keys(%{$letter_map{$char}{$plural_key}})) {
192
3
3
        $word_map{$word} = 1;
193      }
194
3
3
      $letter_map{$char}{$key} = \%word_map;
195
3
3
      delete $letter_map{$char}{$plural_key};
196    }
197  }
198}
199
200sub count_warning {
201
13
11
  my ($warning) = @_;
202
13
4
  our %counters;
203
13
7
  our %ignored_event_map;
204
13
21
  if ($warning =~ /\(([-\w]+)\)$/) {
205
8
5
    my ($code) = ($1);
206
8
7
    next if defined $ignored_event_map{$code};
207
8
9
    ++$counters{$code};
208  }
209}
210
211sub report_timing {
212
0
0
  my ($name, $start_time, $directory, $marker) = @_;
213
0
0
  my $end_time = (stat "$directory/$marker")[9];
214
0
0
  $name =~ s/"/\\"/g;
215
0
0
  print TIMING_REPORT "\"$name\", $start_time, $end_time\n";
216}
217
218sub get_pattern_with_context {
219
24
15
  my ($path) = @_;
220
24
21
  return unless defined $ENV{$path};
221
12
13
  $ENV{$path} =~ /(.*)/;
222
12
67
  return unless open ITEMS, '<:utf8', $1;
223
224
12
7
  my @items;
225
12
6
  my $context = '';
226
12
64
  while (<ITEMS>) {
227
2
3
    my $pattern = $_;
228
2
3
    if ($pattern =~ /^#/) {
229
1
2
      if ($pattern =~ /^# /) {
230
1
2
        $context .= $pattern;
231      } else {
232
0
0
        $context = '';
233      }
234
1
2
      next;
235    }
236
1
1
    chomp $pattern;
237
1
1
    unless ($pattern =~ /./) {
238
0
0
      $context = '';
239
0
0
      next;
240    }
241
1
2
    push @items, $context.$pattern;
242
1
3
    $context = '';
243  }
244
12
28
  close ITEMS;
245
12
14
  return @items;
246}
247
248sub summarize_totals {
249
24
21
  my ($formatter, $path, $items, $totals, $file_counts) = @_;
250
24
24
9
25
  return unless @{$totals};
251
1
22
  return unless open my $fh, '>:utf8', $path;
252
1
1
0
1
  my $totals_count = scalar(@{$totals}) - 1;
253
1
1
  my @indices;
254
1
1
  if ($file_counts) {
255    @indices = sort {
256
0
0
0
0
      $totals->[$b] <=> $totals->[$a] ||
257      $file_counts->[$b] <=> $file_counts->[$a]
258    } 0 .. $totals_count;
259  } else {
260    @indices = sort {
261
1
0
1
0
      $totals->[$b] <=> $totals->[$a]
262    } 0 .. $totals_count;
263  }
264
1
1
  for my $i (@indices) {
265
1
1
    last unless $totals->[$i] > 0;
266
1
1
    my $rule_with_context = $items->[$i];
267
1
1
    my ($description, $rule);
268
1
3
    if ($rule_with_context =~ /^(.*\n)([^\n]+)$/s) {
269
1
1
      ($description, $rule) = ($1, $2);
270    } else {
271
0
0
      ($description, $rule) = ('', $rule_with_context);
272    }
273
1
1
    print $fh $formatter->(
274      $totals->[$i],
275      ($file_counts ? " file-count: $file_counts->[$i]" : ""),
276      $description,
277      $rule
278    );
279  }
280
1
38
  close $fh;
281}
282
283sub get_special {
284
20
17
  my ($file, $special) = @_;
285
20
25
  return 'file-list' if $file eq $special->{'file_list'};
286
18
21
  return 'pr-title' if $file eq $special->{'pr_title_file'};
287
16
15
  return 'pr-description' if $file eq $special->{'pr_description_file'};
288
14
29
  return 'commit-message' if !rindex($file, $special->{'commit_messages'});
289
12
15
  return 'file';
290}
291
292sub main {
293
12
19871
  my @directories;
294  my @cleanup_directories;
295
12
0
  my @check_file_paths;
296
297
12
12
  my $early_warnings = CheckSpelling::Util::get_file_from_env('early_warnings', '/dev/null');
298
12
10
  my $warning_output = CheckSpelling::Util::get_file_from_env('warning_output', '/dev/stderr');
299
12
7
  my $more_warnings = CheckSpelling::Util::get_file_from_env('more_warnings', '/dev/stderr');
300
12
9
  my $counter_summary = CheckSpelling::Util::get_file_from_env('counter_summary', '/dev/stderr');
301
12
7
  my $ignored_events = CheckSpelling::Util::get_file_from_env('ignored_events', '');
302
12
11
  if ($ignored_events) {
303
5
2
    our %ignored_event_map;
304
5
6
    for my $event (split /,/, $ignored_events) {
305
5
5
      $ignored_event_map{$event} = 1;
306    }
307  }
308
12
7
  my $should_exclude_file = CheckSpelling::Util::get_file_from_env('should_exclude_file', '/dev/null');
309
12
7
  my $unknown_word_limit = CheckSpelling::Util::get_val_from_env('unknown_word_limit', undef);
310
12
12
  my $unknown_file_word_limit = CheckSpelling::Util::get_val_from_env('unknown_file_word_limit', undef);
311
12
6
  my $candidate_example_limit = CheckSpelling::Util::get_file_from_env('INPUT_CANDIDATE_EXAMPLE_LIMIT', '3');
312
12
4
  my $disable_flags = CheckSpelling::Util::get_file_from_env('INPUT_DISABLE_CHECKS', '');
313
12
4
  my $only_check_changed_files = CheckSpelling::Util::get_file_from_env('INPUT_ONLY_CHECK_CHANGED_FILES', '');
314
12
8
  my $disable_noisy_file = $disable_flags =~ /(?:^|,|\s)noisy-file(?:,|\s|$)/;
315
12
31
  our $disable_word_collating = $only_check_changed_files || $disable_flags =~ /(?:^|,|\s)word-collating(?:,|\s|$)/;
316
12
8
  my $file_list = CheckSpelling::Util::get_file_from_env('check_file_names', '');
317
12
8
  my $pr_title_file = CheckSpelling::Util::get_file_from_env('pr_title_file', '');
318
12
8
  my $pr_description_file = CheckSpelling::Util::get_file_from_env('pr_description_file', '');
319
12
7
  my $commit_messages = CheckSpelling::Util::get_file_from_env('commit_messages', '');
320
12
6
  my $timing_report = CheckSpelling::Util::get_file_from_env('timing_report', '');
321
12
16
  my $special = {
322    'file_list' => $file_list,
323    'pr_title_file' => $pr_title_file,
324    'pr_description_file' => $pr_description_file,
325    'commit_messages' => $commit_messages,
326  };
327
12
9
  my ($start_time, $end_time);
328
329
12
234
  open WARNING_OUTPUT, '>:utf8', $warning_output;
330
12
170
  open MORE_WARNINGS, '>:utf8', $more_warnings;
331
12
146
  open COUNTER_SUMMARY, '>:utf8', $counter_summary;
332
12
86
  open SHOULD_EXCLUDE, '>:utf8', $should_exclude_file;
333
12
12
  if ($timing_report) {
334
0
0
    open TIMING_REPORT, '>:utf8', $timing_report;
335
0
0
    print TIMING_REPORT "file, start, finish\n";
336  }
337
338
12
11
  my @candidates = get_pattern_with_context('candidates_path');
339
12
8
  my @candidate_totals = (0) x scalar @candidates;
340
12
8
  my @candidate_file_counts = (0) x scalar @candidates;
341
342
12
5
  my @forbidden = get_pattern_with_context('forbidden_path');
343
12
8
  my @forbidden_totals = (0) x scalar @forbidden;
344
345
12
4
  my @delayed_warnings;
346
12
23
  our %letter_map = ();
347
348
12
7
  my %file_map = ();
349
350
12
28
  for my $directory (<>) {
351
15
10
    chomp $directory;
352
15
27
    next unless $directory =~ /^(.*)$/;
353
15
11
    $directory = $1;
354
15
49
    unless (-e $directory) {
355
1
2
      print STDERR "Could not find: $directory\n";
356
1
10
      next;
357    }
358
14
33
    unless (-d $directory) {
359
1
10
      print STDERR "Not a directory: $directory\n";
360
1
2
      next;
361    }
362
363    # if there's no filename, we can't report
364
13
83
    next unless open(NAME, '<:utf8', "$directory/name");
365
12
51
    my $file=<NAME>;
366
12
24
    close NAME;
367
368
12
24
    $file_map{$file} = $directory;
369  }
370
371
12
18
  for my $file (sort keys %file_map) {
372
12
10
    my $directory = $file_map{$file};
373
12
12
    if ($timing_report) {
374
0
0
      $start_time = (stat "$directory/name")[9];
375    }
376
377
12
54
    if (-e "$directory/skipped") {
378
1
7
      open SKIPPED, '<:utf8', "$directory/skipped";
379
1
5
      my $reason=<SKIPPED>;
380
1
2
      close SKIPPED;
381
1
1
      chomp $reason;
382
1
3
      push @delayed_warnings, "$file:1:1 ... 1, Warning - Skipping `$file` because $reason\n";
383
1
2
      print SHOULD_EXCLUDE "$file\n";
384
1
1
      push @cleanup_directories, $directory;
385
1
1
      report_timing($file, $start_time, $directory, 'skipped') if ($timing_report);
386
1
1
      next;
387    }
388
389
11
10
    push @directories, $directory;
390    # stats isn't written if there was nothing interesting in the file
391
11
33
    unless (-s "$directory/stats") {
392
1
1
      report_timing($file, $start_time, $directory, 'warnings') if ($timing_report);
393
1
1
      next;
394    }
395
396
10
9
    if ($file eq $file_list) {
397
1
5
      open FILE_LIST, '<:utf8', $file_list;
398
1
1
      push @check_file_paths, '0 placeholder';
399
1
6
      for my $check_file_path (<FILE_LIST>) {
400
4
2
        chomp $check_file_path;
401
4
4
        push @check_file_paths, $check_file_path;
402      }
403
1
3
      close FILE_LIST;
404    }
405
406
10
4
    my ($words, $unrecognized, $unknown, $unique);
407
408    {
409
10
10
7
51
      open STATS, '<:utf8', "$directory/stats";
410
10
33
      my $stats=<STATS>;
411
10
20
      close STATS;
412
10
6
      $words=get_field($stats, 'words');
413
10
7
      $unrecognized=get_field($stats, 'unrecognized');
414
10
7
      $unknown=get_field($stats, 'unknown');
415
10
7
      $unique=get_field($stats, 'unique');
416
10
4
      my @candidate_list;
417
10
8
      if (@candidate_totals) {
418
0
0
        @candidate_list=get_array($stats, 'candidates');
419
0
0
        my @lines=get_array($stats, 'candidate_lines');
420
0
0
        if (@candidate_list) {
421
0
0
          for (my $i=0; $i < scalar @candidate_list; $i++) {
422
0
0
            my $hits = $candidate_list[$i];
423
0
0
            if ($hits) {
424
0
0
              $candidate_totals[$i] += $hits;
425
0
0
              if ($candidate_file_counts[$i]++ < $candidate_example_limit) {
426
0
0
                my $pattern = (split /\n/,$candidates[$i])[-1];
427
0
0
                my $position = $lines[$i];
428
0
0
                $position =~ s/:(\d+)$/ ... $1/;
429
0
0
                my $wrapped = CheckSpelling::Util::wrap_in_backticks($pattern);
430
0
0
                push @delayed_warnings, "$file:$position, Notice - Line matches candidate pattern $wrapped (candidate-pattern)\n";
431              }
432            }
433          }
434        }
435      }
436
10
9
      if (@forbidden_totals) {
437
1
1
        @forbidden_list=get_array($stats, 'forbidden');
438
1
1
        my @lines=get_array($stats, 'forbidden_lines');
439
1
1
        if (@forbidden_list) {
440
1
2
          for (my $i=0; $i < scalar @forbidden_list; $i++) {
441
1
1
            my $hits = $forbidden_list[$i];
442
1
1
            if ($hits) {
443
1
2
              $forbidden_totals[$i] += $hits;
444            }
445          }
446        }
447      }
448      #print STDERR "$file (unrecognized: $unrecognized; unique: $unique; unknown: $unknown, words: $words, candidates: [".join(", ", @candidate_list)."])\n";
449    }
450
451
10
10
    report_timing($file, $start_time, $directory, 'unknown') if ($timing_report);
452
10
4
    my $kind = get_special($file, $special);
453    # These heuristics are very new and need tuning/feedback
454
10
16
    if (
455        ($unknown > $unique)
456        # || ($unrecognized > $words / 2)
457    ) {
458
0
0
      unless ($disable_noisy_file) {
459
0
0
        if ($kind eq 'file') {
460
0
0
          print SHOULD_EXCLUDE "$file\n";
461        }
462
0
0
        $warning = "noisy-$kind";
463
0
0
        count_warning $warning;
464
0
0
        push @delayed_warnings, "$file:1:1 ... 1, Warning - Skipping `$file` because it seems to have more noise ($unknown) than unique words ($unique) (total: $unrecognized / $words). ($warning)\n";
465
0
0
        next;
466      }
467    }
468
10
45
    unless ($kind =~ /^file/ && -s "$directory/unknown") {
469
4
4
      next;
470    }
471
6
40
    open UNKNOWN, '<:utf8', "$directory/unknown";
472
6
49
    for $token (<UNKNOWN>) {
473
49
56
      $token =~ s/\R//;
474
49
46
      next unless $token =~ /./;
475
46
24
      my ($key, $char) = collate_key $token;
476
46
44
      $letter_map{$char} = () unless defined $letter_map{$char};
477
46
28
      my %word_map = ();
478
46
14
37
17
      %word_map = %{$letter_map{$char}{$key}} if defined $letter_map{$char}{$key};
479
46
40
      $word_map{$token} = 1;
480
46
60
      $letter_map{$char}{$key} = \%word_map;
481    }
482
6
22
    close UNKNOWN;
483  }
484
12
29
  close SHOULD_EXCLUDE;
485
12
9
  close TIMING_REPORT if $timing_report;
486
487  summarize_totals(
488    sub {
489
0
0
      my ($hits, $files, $context, $pattern) = @_;
490
0
0
      return "# hit-count: $hits$files\n$context$pattern\n\n",
491    },
492
12
31
    CheckSpelling::Util::get_file_from_env('candidate_summary', '/dev/stderr'),
493    \@candidates,
494    \@candidate_totals,
495    \@candidate_file_counts,
496  );
497
498  summarize_totals(
499    sub {
500
1
2
      my (undef, undef, $context, $pattern) = @_;
501
1
2
      $context =~ s/^# //gm;
502
1
1
      chomp $context;
503
1
0
      my $details;
504
1
3
      if ($context =~ /^(.*?)$(.*)/ms) {
505
1
2
        ($context, $details) = ($1, $2);
506
1
0
        $details = "\n$details" if $details;
507      }
508
1
1
      $context = 'Pattern' unless $context;
509
1
3
      return "#### $context$details\n```\n$pattern\n```\n\n";
510    },
511
12
31
    CheckSpelling::Util::get_file_from_env('forbidden_summary', '/dev/stderr'),
512    \@forbidden,
513    \@forbidden_totals,
514  );
515
516
12
33
  group_related_words;
517
518
12
13
  if (defined $ENV{'expect'}) {
519
11
27
    $ENV{'expect'} =~ /(.*)/;
520
11
10
    load_expect $1;
521
11
7
    harmonize_expect;
522  }
523
524
12
5
  my %seen = ();
525
12
8
  our %counters;
526
12
4
  %counters = ();
527
528
12
40
  if (-s $early_warnings) {
529
1
7
    open WARNINGS, '<:utf8', $early_warnings;
530
1
8
    for my $warning (<WARNINGS>) {
531
1
1
      chomp $warning;
532
1
1
      count_warning $warning;
533
1
1
      next if should_skip_warning $warning;
534
1
4
      print WARNING_OUTPUT "$warning\n";
535    }
536
1
3
    close WARNINGS;
537  }
538
539
12
5
  our %last_seen;
540
12
7
  my %unknown_file_word_count;
541
12
9
  for my $directory (@directories) {
542
11
29
    next unless (-s "$directory/warnings");
543
10
62
    next unless open(NAME, '<:utf8', "$directory/name");
544
10
38
    my $file=<NAME>;
545
10
20
    close NAME;
546
10
7
    my $kind = get_special($file, $special);
547
10
54
    open WARNINGS, '<:utf8', "$directory/warnings";
548
10
9
    if ($kind ne 'file-list') {
549
9
69
      for $warning (<WARNINGS>) {
550
55
39
        chomp $warning;
551
55
95
        if ($warning =~ m/:(\d+):(\d+ \.\.\. \d+): `(.*)`/) {
552
51
49
          my ($line, $range, $item) = ($1, $2, $3);
553
51
40
          my $wrapped = CheckSpelling::Util::wrap_in_backticks($item);
554
51
34
          my $reason = 'unrecognized-spelling';
555
51
26
          $reason .= "-$kind" unless $kind eq 'file';
556
51
130
          $warning =~ s/:\d+:\d+ \.\.\. \d+: `.*`/:$line:$range, Warning - $wrapped is not a recognized word. ($reason)/;
557
51
39
          next if log_skip_item($item, $file, $warning, $unknown_word_limit);
558
13
23
          count_warning $warning if $kind ne 'file';
559        } else {
560
4
4
          if ($warning =~ /\`(.*?)\` in line\. \(token-is-substring\)/) {
561
0
0
            next if skip_item($1);
562          }
563
4
4
          count_warning $warning;
564        }
565
17
10
        next if should_skip_warning $warning;
566
17
57
        print WARNING_OUTPUT "$file$warning\n";
567      }
568    } else {
569
1
7
      for $warning (<WARNINGS>) {
570
6
5
        chomp $warning;
571
6
16
        next unless $warning =~ s/^:(\d+)/:1/;
572
6
4
        $file = $check_file_paths[$1];
573
6
12
        if ($warning =~ m/:(\d+ \.\.\. \d+): `(.*)`/) {
574
4
2
          my ($range, $item) = ($1, $2);
575
4
4
          my $wrapped = CheckSpelling::Util::wrap_in_backticks($item);
576
4
10
          $warning =~ s/:\d+ \.\.\. \d+: `.*`/:$range, Warning - $wrapped is not a recognized word. (check-file-path)/;
577
4
5
          next if skip_item($item);
578
4
2
          if (defined $unknown_file_word_limit) {
579
4
6
            next if ++$unknown_file_word_count{$item} > $unknown_file_word_limit;
580          }
581        }
582
5
3
        next if should_skip_warning $warning;
583
4
9
        print WARNING_OUTPUT "$file$warning\n";
584
4
4
        count_warning $warning;
585      }
586    }
587
10
40
    close WARNINGS;
588  }
589
12
273
  close MORE_WARNINGS;
590
591
12
12
  for my $warning (@delayed_warnings) {
592
1
1
    next if should_skip_warning $warning;
593
1
1
    count_warning $warning;
594
1
1
    print WARNING_OUTPUT $warning;
595  }
596
12
7
  if (defined $unknown_word_limit) {
597
1
2
    for my $warned_word (sort keys %last_seen) {
598
1
3
      my $warning_count = $seen{$warned_word} || 0;
599
1
2
      next unless $warning_count >= $unknown_word_limit;
600
0
0
      my $warning = $last_seen{$warned_word};
601
0
0
      $warning =~ s/\Q. (unrecognized-spelling)\E/ -- found $warning_count times. (limited-references)\n/;
602
0
0
      next if should_skip_warning $warning;
603
0
0
      print WARNING_OUTPUT $warning;
604
0
0
      count_warning $warning;
605    }
606  }
607
12
268
  close WARNING_OUTPUT;
608
609
12
12
  if (%counters) {
610
2
2
    my $continue='';
611
2
2
    print COUNTER_SUMMARY "{\n";
612
2
4
    for my $code (sort keys %counters) {
613
4
6
      print COUNTER_SUMMARY qq<$continue"$code": $counters{$code}\n>;
614
4
3
      $continue=',';
615    }
616
2
2
    print COUNTER_SUMMARY "}\n";
617  }
618
12
76
  close COUNTER_SUMMARY;
619
620  # display the current unknown
621
12
34
  for my $char (sort keys %letter_map) {
622
43
43
28
89
    for $key (sort CheckSpelling::Util::case_biased keys(%{$letter_map{$char}})) {
623
29
29
14
39
      my %word_map = %{$letter_map{$char}{$key}};
624
29
25
      my @words = keys(%word_map);
625
29
18
      if (scalar(@words) > 1) {
626
13
20
10
74
        print $key." (".(join ", ", sort { length($a) <=> length($b) || $a cmp $b } @words).")";
627      } else {
628
16
52
        print $words[0];
629      }
630
29
101
      print "\n";
631    }
632  }
633}
634
6351;