Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'json'
- def puts_violation(violation)
- severity = violation['severity']
- filename = violation['file'].split('/').last
- line = violation['line']
- reason = violation['reason']
- puts "#{severity} : #{filename}, line #{line}, #{reason}"
- end
- config_file = File.file?('./.swiftlint.yml') ? './.swiftlint.yml' : nil
- swift_files = `git diff --cached --name-only --diff-filter=AMC | grep "\.swift$"`.lines
- swiftlint_command = "swiftlint lint --quiet --reporter json"
- swiftlint_command += " --config #{config_file}" if config_file
- result_json = swift_files.uniq.collect { |f| JSON.parse(`#{swiftlint_command} --path #{f}`.strip).flatten }.flatten
- warnings = result_json.select { |results| results['severity'] == 'Warning' }
- errors = result_json.select { |results| results['severity'] == 'Error' }
- warnings.each { |violation| puts_violation violation }
- errors.each { |violation| puts_violation violation }
- exit errors.count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement