Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'json'
  4.  
  5. def puts_violation(violation)
  6. severity = violation['severity']
  7. filename = violation['file'].split('/').last
  8. line = violation['line']
  9. reason = violation['reason']
  10.  
  11. puts "#{severity} : #{filename}, line #{line}, #{reason}"
  12. end
  13.  
  14. config_file = File.file?('./.swiftlint.yml') ? './.swiftlint.yml' : nil
  15. swift_files = `git diff --cached --name-only --diff-filter=AMC | grep "\.swift$"`.lines
  16.  
  17. swiftlint_command = "swiftlint lint --quiet --reporter json"
  18. swiftlint_command += " --config #{config_file}" if config_file
  19.  
  20. result_json = swift_files.uniq.collect { |f| JSON.parse(`#{swiftlint_command} --path #{f}`.strip).flatten }.flatten
  21. warnings = result_json.select { |results| results['severity'] == 'Warning' }
  22. errors = result_json.select { |results| results['severity'] == 'Error' }
  23.  
  24. warnings.each { |violation| puts_violation violation }
  25. errors.each { |violation| puts_violation violation }
  26.  
  27. exit errors.count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement