Commit e0e3b73f authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #3628 from CocoaPods/seg-linter-message

[Validator] Explain why linting failed
parents 85298a09 b16f25cc
...@@ -160,7 +160,7 @@ module Pod ...@@ -160,7 +160,7 @@ module Pod
else else
spec_name = podspec spec_name = podspec
spec_name = validator.spec.name if validator.spec spec_name = validator.spec.name if validator.spec
message = "#{spec_name} did not pass validation." message = "#{spec_name} did not pass validation, due to #{validator.failure_reason}."
if @clean if @clean
message << "\nYou can use the `--no-clean` option to inspect " \ message << "\nYou can use the `--no-clean` option to inspect " \
......
...@@ -42,7 +42,7 @@ module Pod ...@@ -42,7 +42,7 @@ module Pod
def run def run
UI.puts UI.puts
invalid_count = 0 failure_reasons = []
podspecs_to_lint.each do |podspec| podspecs_to_lint.each do |podspec|
validator = Validator.new(podspec, @source_urls) validator = Validator.new(podspec, @source_urls)
validator.quick = @quick validator.quick = @quick
...@@ -53,7 +53,7 @@ module Pod ...@@ -53,7 +53,7 @@ module Pod
validator.only_subspec = @only_subspec validator.only_subspec = @only_subspec
validator.use_frameworks = @use_frameworks validator.use_frameworks = @use_frameworks
validator.validate validator.validate
invalid_count += 1 unless validator.validated? failure_reasons << validator.failure_reason
unless @clean unless @clean
UI.puts "Pods project available at `#{validator.validation_dir}/Pods/Pods.xcodeproj` for inspection." UI.puts "Pods project available at `#{validator.validation_dir}/Pods/Pods.xcodeproj` for inspection."
...@@ -63,11 +63,17 @@ module Pod ...@@ -63,11 +63,17 @@ module Pod
count = podspecs_to_lint.count count = podspecs_to_lint.count
UI.puts "Analyzed #{count} #{'podspec'.pluralize(count)}.\n\n" UI.puts "Analyzed #{count} #{'podspec'.pluralize(count)}.\n\n"
if invalid_count == 0
failure_reasons.compact!
if failure_reasons.empty?
lint_passed_message = count == 1 ? "#{podspecs_to_lint.first.basename} passed validation." : 'All the specs passed validation.' lint_passed_message = count == 1 ? "#{podspecs_to_lint.first.basename} passed validation." : 'All the specs passed validation.'
UI.puts lint_passed_message.green << "\n\n" UI.puts lint_passed_message.green << "\n\n"
else else
raise Informative, count == 1 ? 'The spec did not pass validation.' : "#{invalid_count} out of #{count} specs failed validation." raise Informative, if count == 1
"The spec did not pass validation, due to #{failure_reasons.first}."
else
"#{invalid_count} out of #{count} specs failed validation."
end
end end
podspecs_tmp_dir.rmtree if podspecs_tmp_dir.exist? podspecs_tmp_dir.rmtree if podspecs_tmp_dir.exist?
end end
......
require 'active_support/core_ext/array'
require 'active_support/core_ext/string/inflections'
module Pod module Pod
# Validates a Specification. # Validates a Specification.
# #
...@@ -111,6 +114,23 @@ module Pod ...@@ -111,6 +114,23 @@ module Pod
UI.puts UI.puts
end end
def failure_reason
results_by_type = results.group_by(&:type)
results_by_type.default = []
return nil if validated?
reasons = []
if (size = results_by_type[:error].size) && size > 0
reasons << "#{size} #{'error'.pluralize(size)}"
end
if !allow_warnings && (size = results_by_type[:warning].size) && size > 0
reason = "#{size} #{'warning'.pluralize(size)}"
pronoun = size == 1 ? 'it' : 'them'
reason << " (but you can use `--allow-warnings` to ignore #{pronoun})" if reasons.empty?
reasons << reason
end
reasons.to_sentence
end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
#  @!group Configuration #  @!group Configuration
......
...@@ -197,8 +197,10 @@ module Pod ...@@ -197,8 +197,10 @@ module Pod
it 'lints a given podspec' do it 'lints a given podspec' do
cmd = command('spec', 'lint', '--quick', @spec_path) cmd = command('spec', 'lint', '--quick', @spec_path)
lambda { cmd.run }.should.raise Informative exception = lambda { cmd.run }.should.raise Informative
UI.output.should.include 'Missing license type' UI.output.should.include 'Missing license type'
exception.message.should.match /due to 1 warning /
exception.message.should.match /use `--allow-warnings` to ignore it\)/
end end
it 'respects the --allow-warnings option' do it 'respects the --allow-warnings option' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment