2
0

test1275.pl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. my $root=$ARGV[0] || "..";
  26. my @m = `git ls-files -- $root`;
  27. my $errors;
  28. my %accepted=('curl' => 1,
  29. 'libcurl' => 1,
  30. 'macOS' => 1,
  31. 'mbedTLS' => 1,
  32. 'c-ares' => 1);
  33. sub checkfile {
  34. my ($f) = @_;
  35. chomp $f;
  36. if($f !~ /\.md\z/) {
  37. return;
  38. }
  39. open(my $fh, "<", "$f");
  40. my $l;
  41. my $prevl;
  42. my $ignore = 0;
  43. my $metadata = 0;
  44. while(<$fh>) {
  45. my $line = $_;
  46. chomp $line;
  47. $l++;
  48. if(($l == 1) && ($line =~ /^---/)) {
  49. # first line is a meta-data divider, skip to the next one
  50. $metadata = 1;
  51. next;
  52. }
  53. elsif($metadata) {
  54. if($line !~ /^---/) {
  55. next;
  56. }
  57. $metadata = 0;
  58. next;
  59. }
  60. if($line =~ /^(\`\`\`|\~\~\~)/) {
  61. # start or stop ignore-mode
  62. $ignore ^= 1;
  63. }
  64. if(!$ignore) {
  65. if(($prevl =~ /\.\z/) && ($line =~ /^( *)([a-z][A-Za-z-]*)/)) {
  66. my ($prefix, $word) = ($1, $2);
  67. if($word =~ /^[a-z]/ && !$accepted{$word}) {
  68. my $c = length($prefix);
  69. print STDERR
  70. "$f:$l:$c:error: lowercase $word after period\n";
  71. print STDERR "$line\n";
  72. print STDERR ' ' x $c;
  73. print STDERR "^\n";
  74. $errors++;
  75. }
  76. }
  77. elsif($line =~ /^(.*)\. +([a-z-]+)/) {
  78. my ($prefix, $word) = ($1, $2);
  79. if(($prefix =~ /\.\.\z/) ||
  80. ($prefix =~ /[0-9]\z/) ||
  81. ($prefix =~ /e.g\z/) ||
  82. ($prefix =~ /i.e\z/) ||
  83. ($prefix =~ /E.g\z/) ||
  84. ($prefix =~ /etc\z/) ||
  85. ($word !~ /^[a-z]/) ||
  86. $accepted{$word}) {
  87. }
  88. else {
  89. my $c = length($prefix) + 2;
  90. print STDERR
  91. "$f:$l:$c:error: lowercase $word after period\n";
  92. print STDERR "$line\n";
  93. print STDERR ' ' x $c;
  94. print STDERR "^\n";
  95. $errors++;
  96. }
  97. }
  98. }
  99. $prevl = $line;
  100. }
  101. close($fh);
  102. }
  103. for my $f (@m) {
  104. checkfile($f);
  105. }
  106. if($errors) {
  107. exit 1;
  108. }
  109. print "ok\n";