xref: /curl/tests/test1275.pl (revision 79cdae4f)
1#!/usr/bin/env perl
2#***************************************************************************
3#                                  _   _ ____  _
4#  Project                     ___| | | |  _ \| |
5#                             / __| | | | |_) | |
6#                            | (__| |_| |  _ <| |___
7#                             \___|\___/|_| \_\_____|
8#
9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10#
11# This software is licensed as described in the file COPYING, which
12# you should have received as part of this distribution. The terms
13# are also available at https://curl.se/docs/copyright.html.
14#
15# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16# copies of the Software, and permit persons to whom the Software is
17# furnished to do so, under the terms of the COPYING file.
18#
19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20# KIND, either express or implied.
21#
22# SPDX-License-Identifier: curl
23#
24###########################################################################
25
26my $root=$ARGV[0] || "..";
27
28my @m = `git ls-files -- $root`;
29
30my $errors;
31
32my %accepted=('curl' => 1,
33              'libcurl' => 1,
34              'macOS' => 1,
35              'c-ares' => 1);
36
37sub checkfile {
38    my ($f) = @_;
39    chomp $f;
40    if($f !~ /\.md\z/) {
41        return;
42    }
43    open(my $fh, "<", "$f");
44    my $l;
45    my $prevl;
46    my $ignore = 0;
47    my $metadata = 0;
48    while(<$fh>) {
49        my $line = $_;
50        chomp $line;
51        $l++;
52        if(($l == 1) && ($line =~ /^---/)) {
53            # first line is a meta-data divider, skip to the next one
54            $metadata = 1;
55            next;
56        }
57        elsif($metadata) {
58            if($line !~ /^---/) {
59                next;
60            }
61            $metadata = 0;
62            next;
63        }
64        if($line =~ /^(\`\`\`|\~\~\~)/) {
65            # start or stop ignore-mode
66            $ignore ^= 1;
67        }
68        if(!$ignore) {
69            if(($prevl =~ /\.\z/) && ($line =~ /^( *)([a-z][A-Za-z-]*)/)) {
70                my ($prefix, $word) = ($1, $2);
71                if($word =~ /^[a-z]/ && !$accepted{$word}) {
72                    my $c = length($prefix);
73                    print STDERR
74                        "$f:$l:$c:error: lowercase $word after period\n";
75                    print STDERR "$line\n";
76                    print STDERR ' ' x $c;
77                    print STDERR "^\n";
78                    $errors++;
79                }
80            }
81            elsif($line =~ /^(.*)\. +([a-z-]+)/) {
82                my ($prefix, $word) = ($1, $2);
83
84                if(($prefix =~ /\.\.\z/) ||
85                   ($prefix =~ /[0-9]\z/) ||
86                   ($prefix =~ /e.g\z/) ||
87                   ($prefix =~ /i.e\z/) ||
88                   ($prefix =~ /E.g\z/) ||
89                   ($prefix =~ /etc\z/) ||
90                   ($word !~ /^[a-z]/) ||
91                   $accepted{$word}) {
92                }
93                else {
94                    my $c = length($prefix) + 2;
95                    print STDERR
96                        "$f:$l:$c:error: lowercase $word after period\n";
97                    print STDERR "$line\n";
98                    print STDERR ' ' x $c;
99                    print STDERR "^\n";
100                    $errors++;
101                }
102            }
103        }
104        $prevl = $line;
105    }
106    close($fh);
107}
108
109
110for my $f (@m) {
111    checkfile($f);
112}
113
114if($errors) {
115    exit 1;
116}
117print "ok\n";
118