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