test1275.pl 3.4 KB

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