docs: address typos in Git v2.45 changelog
[git.git] / Documentation / lint-gitlink.perl
blob1c61dd9512b9e3db1768416ede49686020d38662
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 # Parse arguments, a simple state machine for input like:
8 # <file-to-check.txt> <valid-files-to-link-to> --section=1 git.txt git-add.txt [...] --to-lint git-add.txt a-file.txt [...]
9 my %TXT;
10 my %SECTION;
11 my $section;
12 my $lint_these = 0;
13 my $to_check = shift @ARGV;
14 for my $arg (@ARGV) {
15 if (my ($sec) = $arg =~ /^--section=(\d+)$/s) {
16 $section = $sec;
17 next;
20 my ($name) = $arg =~ /^(.*?)\.txt$/s;
21 unless (defined $section) {
22 $TXT{$name} = $arg;
23 next;
26 $SECTION{$name} = $section;
29 my $exit_code = 0;
30 sub report {
31 my ($pos, $line, $target, $msg) = @_;
32 substr($line, $pos) = "' <-- HERE";
33 $line =~ s/^\s+//;
34 print STDERR "$ARGV:$.: error: $target: $msg, shown with 'HERE' below:\n";
35 print STDERR "$ARGV:$.:\t'$line\n";
36 $exit_code = 1;
39 @ARGV = sort values %TXT;
40 die "BUG: No list of valid linkgit:* files given" unless @ARGV;
41 @ARGV = $to_check;
42 while (<>) {
43 my $line = $_;
44 while ($line =~ m/linkgit:((.*?)\[(\d)\])/g) {
45 my $pos = pos $line;
46 my ($target, $page, $section) = ($1, $2, $3);
48 # De-AsciiDoc
49 $page =~ s/{litdd}/--/g;
51 if (!exists $TXT{$page}) {
52 report($pos, $line, $target, "link outside of our own docs");
53 next;
55 if (!exists $SECTION{$page}) {
56 report($pos, $line, $target, "link outside of our sectioned docs");
57 next;
59 my $real_section = $SECTION{$page};
60 if ($section != $SECTION{$page}) {
61 report($pos, $line, $target, "wrong section (should be $real_section)");
62 next;
65 # this resets our $. for each file
66 close ARGV if eof;
69 exit $exit_code;