pop main logic out one level by reversing condition

This commit is contained in:
Dave Machado 2017-07-28 14:35:32 -04:00
parent 8c74f6fe68
commit 01161074fa

View File

@ -31,54 +31,53 @@ end
File.foreach(filename).with_index do | line, line_num | File.foreach(filename).with_index do | line, line_num |
line_num += 1 line_num += 1
if line.start_with?('|')
# Skip table schema lines # Skip non-markdown table lines and table schema lines
if line.eql? "|---|---|---|---|---|\n" if !line.start_with?('|') || line.eql?("|---|---|---|---|---|\n")
next next
end end
values = line.split("|") values = line.split("|")
################### GLOBAL ################### ################### GLOBAL ###################
values.each.with_index do |val, val_index| values.each.with_index do |val, val_index|
msg = "" msg = ""
case val_index case val_index
when INDEX_TITLE..INDEX_LINK when INDEX_TITLE..INDEX_LINK
# every line segment should start and end with exactly 1 space # every line segment should start and end with exactly 1 space
if val[/\A */].size != 1 || val[/ *\z/].size != 1 if val[/\A */].size != 1 || val[/ *\z/].size != 1
add_error(line_num, val_index, "string should start and end with exactly 1 space") add_error(line_num, val_index, "string should start and end with exactly 1 space")
end
end end
end end
################# DESCRIPTION ################ end
# First character should be capitalized ################# DESCRIPTION ################
desc_val = values[INDEX_DESCRIPTION].lstrip.chop # First character should be capitalized
if !/[[:upper:]]/.match(desc_val[0]) desc_val = values[INDEX_DESCRIPTION].lstrip.chop
add_error(line_num, INDEX_DESCRIPTION, "first char not uppercase") if !/[[:upper:]]/.match(desc_val[0])
end add_error(line_num, INDEX_DESCRIPTION, "first char not uppercase")
# value should not be punctuated end
last_char = desc_val[desc_val.length-1] # value should not be punctuated
if punctuation.include?(last_char) last_char = desc_val[desc_val.length-1]
add_error(line_num, INDEX_DESCRIPTION, "description should not end with \"#{last_char}\"") if punctuation.include?(last_char)
end add_error(line_num, INDEX_DESCRIPTION, "description should not end with \"#{last_char}\"")
#################### AUTH #################### end
# Values should conform to valid options only #################### AUTH ####################
auth_val = values[INDEX_AUTH].lstrip.chop.tr('``', '') # Values should conform to valid options only
if !auth_keys.include?(auth_val) auth_val = values[INDEX_AUTH].lstrip.chop.tr('``', '')
add_error(line_num, INDEX_AUTH, "not a valid option: #{auth_val}") if !auth_keys.include?(auth_val)
end add_error(line_num, INDEX_AUTH, "not a valid option: #{auth_val}")
#################### HTTPS ################### end
# Values should be either "Yes" or "No" #################### HTTPS ###################
https_val = values[INDEX_HTTPS].lstrip.chop # Values should be either "Yes" or "No"
if !https_keys.include?(https_val) https_val = values[INDEX_HTTPS].lstrip.chop
add_error(line_num, INDEX_HTTPS, "must use \"Yes\" or \"No\": #{https_val}") if !https_keys.include?(https_val)
end add_error(line_num, INDEX_HTTPS, "must use \"Yes\" or \"No\": #{https_val}")
#################### LINK #################### end
# Url should be wrapped in "[Go!]" view #################### LINK ####################
link_val = values[INDEX_LINK].lstrip.chop # Url should be wrapped in "[Go!]" view
if !link_val.start_with?("[Go!](") || !link_val.end_with?(')') link_val = values[INDEX_LINK].lstrip.chop
add_error(line_num, INDEX_LINK, "format should be \"[Go!](<LINK>)\": #{link_val}") if !link_val.start_with?("[Go!](") || !link_val.end_with?(')')
end add_error(line_num, INDEX_LINK, "format should be \"[Go!](<LINK>)\": #{link_val}")
end end
end end
$errors.each do | e | $errors.each do | e |