test1275.pl 3.5 KB

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