Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

91 wiersze
2.8 KiB

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