2
0

markdown-uppercase.pl 2.9 KB

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