• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
35sub checkfile {
36    my ($f) = @_;
37    chomp $f;
38    if($f !~ /\.md\z/) {
39        return;
40    }
41    open(my $fh, "<", "$f");
42    my $l = 1;
43    my $prevl;
44    my $ignore = 0;
45    while(<$fh>) {
46        my $line = $_;
47        chomp $line;
48        if($line =~ /^(\`\`\`|\~\~\~)/) {
49            # start or stop ignore-mode
50            $ignore ^= 1;
51        }
52        if(!$ignore) {
53            if(($prevl =~ /\.\z/) && ($line =~ /^( *)([a-z]+)/)) {
54                my ($prefix, $word) = ($1, $2);
55                if(!$accepted{$word}) {
56                    my $c = length($prefix);
57                    print STDERR
58                        "$f:$l:$c:error: lowercase $word after period\n";
59                    print STDERR "$line\n";
60                    print STDERR ' ' x $c;
61                    print STDERR "^\n";
62                    $errors++;
63                }
64            }
65            elsif($line =~ /^(.*)\. +([a-z]+)/) {
66                my ($prefix, $word) = ($1, $2);
67
68                if(($prefix =~ /\.\.\z/) ||
69                   ($prefix =~ /[0-9]\z/) ||
70                   ($prefix =~ /e.g\z/) ||
71                   ($prefix =~ /i.e\z/) ||
72                   ($prefix =~ /etc\z/) ||
73                   $accepted{$word}) {
74                }
75                else {
76                    my $c = length($prefix) + 2;
77                    print STDERR
78                        "$f:$l:$c:error: lowercase $word after period\n";
79                    print STDERR "$line\n";
80                    print STDERR ' ' x $c;
81                    print STDERR "^\n";
82                    $errors++;
83                }
84            }
85        }
86        $prevl = $line;
87        $l++;
88    }
89    close($fh);
90}
91
92
93for my $f (@m) {
94    checkfile($f);
95}
96
97if($errors) {
98    exit 1;
99}
100print "ok\n";
101