i18n: turn even more messages into "cannot be used together" ones
[git/debian.git] / Documentation / lint-man-section-order.perl
blob425377dfeb7fc0856773fd5eaaac7dd3b7b1c999
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 my %SECTIONS;
8 my $order = 0;
9 %SECTIONS = (
10 'NAME' => {
11 required => 1,
12 order => $order++,
14 'SYNOPSIS' => {
15 required => 1,
16 order => $order++,
18 'DESCRIPTION' => {
19 required => 1,
20 order => $order++,
22 'OPTIONS' => {
23 order => $order++,
24 required => 0,
26 'CONFIGURATION' => {
27 order => $order++,
29 'BUGS' => {
30 order => $order++,
32 'SEE ALSO' => {
33 order => $order++,
35 'GIT' => {
36 required => 1,
37 order => $order++,
41 my $SECTION_RX = do {
42 my ($names) = join "|", keys %SECTIONS;
43 qr/^($names)$/s;
46 my $exit_code = 0;
47 sub report {
48 my ($msg) = @_;
49 print STDERR "$ARGV:$.: $msg\n";
50 $exit_code = 1;
53 my $last_was_section;
54 my @actual_order;
55 while (my $line = <>) {
56 chomp $line;
57 if ($line =~ $SECTION_RX) {
58 push @actual_order => $line;
59 $last_was_section = 1;
60 # Have no "last" section yet, processing NAME
61 next if @actual_order == 1;
63 my @expected_order = sort {
64 $SECTIONS{$a}->{order} <=> $SECTIONS{$b}->{order}
65 } @actual_order;
67 my $expected_last = $expected_order[-2];
68 my $actual_last = $actual_order[-2];
69 if ($actual_last ne $expected_last) {
70 report("section '$line' incorrectly ordered, comes after '$actual_last'");
72 next;
74 if ($last_was_section) {
75 my $last_section = $actual_order[-1];
76 if (length $last_section ne length $line) {
77 report("dashes under '$last_section' should match its length!");
79 if ($line !~ /^-+$/) {
80 report("dashes under '$last_section' should be '-' dashes!");
82 $last_was_section = 0;
85 if (eof) {
86 # We have both a hash and an array to consider, for
87 # convenience
88 my %actual_sections;
89 @actual_sections{@actual_order} = ();
91 for my $section (sort keys %SECTIONS) {
92 next if !$SECTIONS{$section}->{required} or exists $actual_sections{$section};
93 report("has no required '$section' section!");
96 # Reset per-file state
98 @actual_order = ();
99 # this resets our $. for each file
100 close ARGV;
105 exit $exit_code;