File Coverage

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

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