Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

61 строка
2.1 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. ################# DESCRIPTION ################
  20. # First character should be capitalized
  21. desc_val = values[2].lstrip.chop
  22. if !/[[:upper:]]/.match(desc_val[0])
  23. add_error(line_num, "Invalid Description (first char not uppercase): #{desc_val}")
  24. end
  25. # value should not be punctuated
  26. last_char = desc_val[desc_val.length-1]
  27. if punctuation.include?(last_char)
  28. add_error(line_num, "Invalid Description (description should not end with \"#{last_char}\")")
  29. end
  30. #################### AUTH ####################
  31. # Values should conform to valid options only
  32. auth_val = values[3].lstrip.chop.tr('``', '')
  33. if !auth_keys.include?(auth_val)
  34. add_error(line_num, "Invalid Auth (not a valid option): #{auth_val}")
  35. end
  36. #################### HTTPS ###################
  37. # Values should be either "Yes" or "No"
  38. https_val = values[4].lstrip.chop
  39. if !https_keys.include?(https_val)
  40. add_error(line_num, "(#{line_num}) Invalid HTTPS: (must use \"Yes\" or \"No\"): #{https_val}")
  41. end
  42. #################### LINK ####################
  43. # Url should be wrapped in "[Go!]" view
  44. link_val = values[5].lstrip.chop
  45. if !link_val.start_with?("[Go!](") || !link_val.end_with?(')')
  46. add_error(line_num, "(#{line_num}) Invalid Link: (format should be \"[Go!](<LINK>)\"): #{link_val}")
  47. end
  48. end
  49. end
  50. if $errors.length > 0
  51. $errors.each do | e |
  52. puts e
  53. end
  54. exit(1)
  55. else
  56. exit(0)
  57. end