You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.9 KiB

  1. #!/usr/bin/env ruby
  2. auth_keys = ['apiKey', 'OAuth', 'X-Mashape-Key', 'No']
  3. punctuation = ['.', '?', '!']
  4. https_keys = ['Yes', 'No']
  5. args = ARGV
  6. filename = args[0]
  7. $errors = []
  8. def add_error(line_num, message)
  9. $errors.push("(L%03d) #{message}" % line_num)
  10. end
  11. File.foreach(filename).with_index do | line, line_num |
  12. line_num += 1
  13. if line.start_with?('|')
  14. # Skip table schema lines
  15. if line.eql? "|---|---|---|---|---|\n"
  16. next
  17. end
  18. values = line.split("|")
  19. values.each.with_index do |val, val_index|
  20. msg = ""
  21. case val_index
  22. when 1..5
  23. if val[0] != " " || val[val.length-1] != " "
  24. case val_index
  25. when 1
  26. msg = "spacing on Title is invalid"
  27. when 2
  28. msg = "spacing on Description is invalid"
  29. when 3
  30. msg = "spacing on Auth is invalid"
  31. when 4
  32. msg = "spacing on HTTPS is invalid"
  33. when 5
  34. msg = "spacing on Link is invalid"
  35. end
  36. end
  37. end
  38. if msg != ""
  39. add_error(line_num, "#{msg} (pad before and after string)")
  40. end
  41. end
  42. ################# DESCRIPTION ################
  43. # First character should be capitalized
  44. desc_val = values[2].lstrip.chop
  45. if !/[[:upper:]]/.match(desc_val[0])
  46. add_error(line_num, "invalid Description (first char not uppercase): #{desc_val}")
  47. end
  48. # value should not be punctuated
  49. last_char = desc_val[desc_val.length-1]
  50. if punctuation.include?(last_char)
  51. add_error(line_num, "invalid Description (description should not end with \"#{last_char}\")")
  52. end
  53. #################### AUTH ####################
  54. # Values should conform to valid options only
  55. auth_val = values[3].lstrip.chop.tr('``', '')
  56. if !auth_keys.include?(auth_val)
  57. add_error(line_num, "invalid Auth (not a valid option): #{auth_val}")
  58. end
  59. #################### HTTPS ###################
  60. # Values should be either "Yes" or "No"
  61. https_val = values[4].lstrip.chop
  62. if !https_keys.include?(https_val)
  63. add_error(line_num, "invalid HTTPS (must use \"Yes\" or \"No\"): #{https_val}")
  64. end
  65. #################### LINK ####################
  66. # Url should be wrapped in "[Go!]" view
  67. link_val = values[5].lstrip.chop
  68. if !link_val.start_with?("[Go!](") || !link_val.end_with?(')')
  69. add_error(line_num, "invalid Link (format should be \"[Go!](<LINK>)\"): #{link_val}")
  70. end
  71. end
  72. end
  73. if $errors.length > 0
  74. $errors.each do | e |
  75. puts e
  76. end
  77. exit(1)
  78. else
  79. exit(0)
  80. end