您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

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