Skip to content

Commit 7c334cd

Browse files
committed
pr-check: Complain about trailing punctuation in descriptions
1 parent 1a87922 commit 7c334cd

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

.github/workflows/pr-check.rb

+25-19
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,14 @@ def sort_and_check(arr, label)
5151

5252
File.open("index.md") do |f|
5353
state = :header
54-
libraries = []
55-
software = []
56-
non_believers = []
54+
groups = { :libraries => [], :software => [], :non_believers => [] }
5755
lc = 0
5856
fails = false
5957

6058
while f && !f.eof?
6159
line = f.gets
6260
lc += 1
61+
descr = nil
6362

6463
case state
6564
when :header, :header_2, :header_3
@@ -70,43 +69,50 @@ def sort_and_check(arr, label)
7069
if line.match(/^\{: rules/)
7170
state = next_state(state)
7271
else
72+
parts = []
73+
if m = line.match(/^\| (.+) \|$/)
74+
parts = m[1].split(/ \| /).flatten
75+
end
76+
7377
if state == :non_believers
74-
if !line.match(/^\| [^\|]+ \| [^\|]+ \|$/)
78+
if parts.count != 2
7579
puts "Line #{lc} does not match format | |", line
7680
fails = true
7781
end
7882
elsif state == :libraries
79-
if !line.match(/^\| [^\|]+ \| [^\|]+ \| [^\|]+ \| [^\|]+ \|$/)
83+
if parts.count == 4
84+
descr = parts[2]
85+
else
8086
puts "Line #{lc} does not match format | | | |", line
8187
fails = true
8288
end
83-
else
84-
if !line.match(/^\| [^\|]+ \| [^\|]+ \| [^\|]+ \|$/)
89+
elsif state == :software
90+
if parts.count == 3
91+
descr = parts[1]
92+
else
8593
puts "Line #{lc} does not match format | | |", line
8694
fails = true
8795
end
96+
else
97+
raise "invalid state #{state}"
8898
end
8999

90-
case state
91-
when :libraries
92-
libraries.push line
93-
when :software
94-
software.push line
95-
when :non_believers
96-
non_believers.push line
97-
else
98-
raise "bogus state?"
100+
if descr.to_s.match(/[.!]$/)
101+
puts "Line #{lc} description has trailing punctuation", line
102+
fails = true
99103
end
104+
105+
groups[state].push line
100106
end
101107
when :trailer
102108
puts "Trailing junk at the end of the file on line #{lc}: #{line.inspect}"
103109
fails = true
104110
end
105111
end
106112

107-
fails |= !sort_and_check(libraries, "Library")
108-
fails |= !sort_and_check(software, "Software")
109-
fails |= !sort_and_check(non_believers, "Non-supporting software")
113+
fails |= !sort_and_check(groups[:libraries], "Library")
114+
fails |= !sort_and_check(groups[:software], "Software")
115+
fails |= !sort_and_check(groups[:non_believers], "Non-supporting software")
110116

111117
if fails
112118
exit 1

0 commit comments

Comments
 (0)