Commit 40030b99 authored by Fabio Pelosin's avatar Fabio Pelosin

[#200, #133] Improvements to spec lint

- warning messages
- stronger validation
- validating pathnames starting with a slash
- cosmetics
parent 8aba4ca8
......@@ -159,7 +159,21 @@ module Pod
def lint
file = @name ? Pathname.new(@name) : Pathname.pwd.glob('*.podspec').first
spec = Specification.from_file(file)
puts "This pod specification contains all required attributes." if spec.validate!
puts "\nThe #{spec.name} specification contains all the required attributes.".green if spec.validate!
warnings = []
warnings << 'The name of the specificaiton should match the name of the podspec file' if spec.name + '.podspec' != @name
warnings << 'Missing license[:type]' unless spec.license && spec.license[:type]
warnings << 'Missing license[:file] or [:text]' unless spec.license && (spec.license[:file] || spec.license[:text])
warnings << "Github repositories should end in `.git'" if spec.source[:git] =~ /github.com/ && spec.source[:git] !~ /.*\.git/
unless warnings.empty?
puts "\n[!] The #{spec.name} specification raised the following warnings".yellow
warnings.each { |warn| puts ' - '+ warn }
end
puts
end
end
end
......
require 'xcodeproj/config'
require 'colored'
module Pod
extend Config::Mixin
......@@ -316,26 +317,32 @@ module Pod
def validate!
missing = []
missing << "`name'" unless name
missing << "`version'" unless version
missing << "`summary'" unless summary
missing << "`homepage'" unless homepage
missing << "`author(s)'" unless authors
missing << "either `source' or `part_of'" unless source || part_of
missing << "`source_files'" if source_files.empty? && subspecs.empty?
missing << "name" unless name
missing << "version" unless version
missing << "summary" unless summary
missing << "homepage" unless homepage
missing << "author(s)" unless authors
missing << "source or part_of" unless source || part_of
missing << "source_files" if source_files.empty? && subspecs.empty?
# TODO
# * validate subspecs
incorrect = []
allowed = [nil, :ios, :osx]
incorrect << ["`platform'", allowed] unless allowed.include?(platform.name)
incorrect << "platform - accepted values are (no value, :ios, :osx)" unless allowed.include?(platform.name)
[:source_files, :resources, :clean_paths].each do |m|
incorrect << "#{m} - paths cannot start with a slash" unless self.send(m) && self.send(m).reject{|f| !f.start_with?("/")}.empty?
end
incorrect << "source[:local] - paths cannot start with a slash" if source && source[:local] && source[:local].start_with?("/")
no_errors_found = missing.empty? && incorrect.empty?
unless no_errors_found
message = "The following #{(missing + incorrect).size == 1 ? 'attribute is' : 'attributes are'}:\n"
message << "* missing: #{missing.join(", ")}" unless missing.empty?
message << "* incorrect: #{incorrect.map { |x| "#{x[0]} (#{x[1..-1]})" }.join(", ")}" unless incorrect.empty?
message = "\n[!] The #{name || 'nameless'} specification is incorrect\n".red
missing.each {|s| message << " - Missing #{s}\n"}
incorrect.each {|s| message << " - Incorrect #{s}\n"}
message << "\n"
raise Informative, message
end
......
......@@ -250,7 +250,7 @@ describe "A Pod::Specification, in general," do
it "raises if the specification does not contain the minimum required attributes" do
exception = validate { @spec.validate! }
exception.message =~ /name.+?version.+?summary.+?homepage.+?authors.+?(source|part_of).+?source_files/
exception.message =~ /name.*version.*summary.*homepage.*authors.*(source.*part_of).*source_files/
end
it "raises if the platform is unrecognized" 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