Commit ab1f9050 authored by Fabio Pelosin's avatar Fabio Pelosin

[Pod::Command::Spec#lint] Refinement and minor changes

parent 7f1ae489
......@@ -73,28 +73,34 @@ module Pod
end
end
puts
all_valid = lint_specs_files(files, is_repo)
all_valid = Linter.new(files, is_repo).lint!
if all_valid
puts (files.count == 1 ? "#{files[0].basename} passed validation" : "All the specs passed validation").green
puts (files.count == 1 ? "#{files[0].basename} passed validation" : "All the specs passed validation").green << "\n\n"
else
message = (files.count == 1 ? "[!] The spec did not pass validation" : "[!] Not all specs passed validation").red
raise Informative, message
end
end
private
def repo_with_name_exist(name)
name && (config.repos_dir + name).exist? && !name.include?('/')
end
class Linter
include Config::Mixin
def initialize(files, is_repo)
@files = files
@is_repo = is_repo
end
# Takes an array of podspec files and lints them all
#
# It returns true if **all** the files passed validation
#
def lint_specs_files(files, is_repo)
def lint!
all_valid = true
files.each do |file|
@files.each do |file|
file = file.realpath
file_spec = Specification.from_file(file)
......@@ -102,21 +108,20 @@ module Pod
specs.each do |spec|
# Show immediatly which pod is being processed.
# This line will be overwritten once the result is known
print " -> #{spec}\r" unless config.silent? || is_repo
print " -> #{spec}\r" unless config.silent? || @is_repo
$stdout.flush
# If the spec doesn't validate it raises and informative
spec.validate!
warnings = warnings_for_spec(spec, file, is_repo)
deprecations = deprecation_notices_for_spec(spec, file, is_repo)
if is_repo || @quick
warnings = warnings_for_spec(spec, file)
deprecations = deprecation_notices_for_spec(spec, file)
build_messages, file_patterns_errors = [], []
else
unless @is_repo || @quick
platform_names(spec).each do |platform_name|
set_up_lint_environment
build_messages = build_errors_for_spec(spec, file, platform_name)
file_patterns_errors = file_patterns_errors_for_spec(spec, file, platform_name)
build_messages += build_errors_for_spec(spec, file, platform_name)
file_patterns_errors += file_patterns_errors_for_spec(spec, file, platform_name)
tear_down_lint_environment
end
end
......@@ -141,7 +146,7 @@ module Pod
# This overwrites the previously printed text
unless config.silent?
if errors.empty? && warnings.empty?
puts " -> ".green + "#{spec} passed validation" unless is_repo
puts " -> ".green + "#{spec} passed validation" unless @is_repo
elsif errors.empty?
puts " -> ".yellow + spec.to_s
else
......@@ -151,7 +156,7 @@ module Pod
warnings.each {|msg| puts " - WARN | #{msg}"} unless config.silent?
errors.each {|msg| puts " - ERROR | #{msg}"} unless config.silent?
puts unless config.silent? || ( is_repo && all.flatten.empty? )
puts unless config.silent? || ( @is_repo && all.flatten.empty? )
end
end
all_valid
......@@ -192,7 +197,7 @@ module Pod
#
# It returns a array of messages
#
def warnings_for_spec(spec, file, is_repo)
def warnings_for_spec(spec, file)
license = spec.license
source = spec.source
text = file.read
......@@ -201,7 +206,7 @@ module Pod
warnings << "Missing license[:type]" unless license && license[:type]
warnings << "Github repositories should end in `.git'" if source && source[:git] =~ /github.com/ && source[:git] !~ /.*\.git/
warnings << "Github repositories should start with `https'" if source && source[:git] =~ /github.com/ && source[:git] !~ /https:\/\/github.com/
warnings << "The description should end with a dot" if spec.description && spec.description !~ /.*\./
warnings << "The description should end with a dot" if spec.description != spec.summary && spec.description !~ /.*\./
warnings << "The summary should end with a dot" if spec.summary !~ /.*\./
warnings << "Missing license[:file] or [:text]" unless license && (license[:file] || license[:text])
warnings << "Comments must be deleted" if text =~ /^\w*#\n\w*#/ # allow a single line comment as it is generally used in subspecs
......@@ -218,11 +223,11 @@ module Pod
#
# It returns a array of messages
#
def deprecation_notices_for_spec(spec, file, is_repo)
def deprecation_notices_for_spec(spec, file)
text = file.read
deprecations = []
deprecations << "`config.ios?' and `config.osx' will be removed in version 0.7" if text. =~ /config\..os?/
deprecations << "Currently there is no known reason to use the `post_install' hook" if text. =~ /post_install/
deprecations << "The `post_install' hook is reserved for edge cases" if text. =~ /post_install/
deprecations
end
......@@ -233,7 +238,7 @@ module Pod
#
def build_errors_for_spec(spec, file, platform_name)
messages = []
puts "\n\nGenerating build errors for #{platform_name} platform".yellow.reversed if config.verbose?
puts "\n\n#{spec} - generating build errors for #{platform_name} platform".yellow.reversed if config.verbose?
podfile = podfile_from_spec(spec, file, platform_name)
Installer.new(podfile).install!
......@@ -255,8 +260,8 @@ module Pod
def process_xcode_build_output(output)
output_by_line = output.split("\n")
selected_lines = output_by_line.select do |l|
l.include?('error') && !l.include?('error generated.')\
|| l.include?('warning') && !l.include?('warning generated.')\
l.include?('error') && (l !~ /errors? generated\./) \
|| l.include?('warning') && (l !~ /warnings? generated\./)\
|| l.include?('note')
end
# Remove the unnecessary tmp path
......@@ -272,20 +277,24 @@ module Pod
def file_patterns_errors_for_spec(spec, file, platform_name)
Dir.chdir(config.project_pods_root + spec.name ) do
messages = []
messages += check_spec_files_exists(spec, :source_files, platform_name)
messages += check_spec_files_exists(spec, :source_files, platform_name, '*.{h,m,mm,c,cpp}')
messages += check_spec_files_exists(spec, :resources, platform_name)
messages << "license[:file] = '#{spec.license[:file]}' -> did not match any file" if spec.license[:file] && Pathname.pwd.glob(spec.license[:file]).empty?
messages.compact
end
end
def check_spec_files_exists(spec, accessor, platform_name)
# TODO: FileList doesn't work and always adds the error message
# pod spec lint ~/.cocoapods/master/MKNetworkKit/0.83/MKNetworkKit.podspec
def check_spec_files_exists(spec, accessor, platform_name, options = {})
result = []
patterns = spec.send(accessor)[platform_name]
unless patterns.empty?
patterns.each do |pattern|
result << "#{platform_name}: [#{accessor} = '#{pattern}'] -> did not match any file" if Pathname.pwd.glob(pattern).empty?
patterns.map do |pattern|
pattern = Pathname.pwd + pattern
if pattern.directory? && options[:glob]
pattern += options[:glob]
end
result << "#{platform_name}: [#{accessor} = '#{pattern}'] -> did not match any file" if pattern.glob.empty?
end
result
end
......@@ -293,6 +302,7 @@ module Pod
def platform_names(spec)
spec.platform.name ? [spec.platform.name] : [:ios, :osx]
end
end
# Templates and github information retrival for spec create
......@@ -460,14 +470,14 @@ Pod::Spec.new do |s|
#
# s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2' }
end
SPEC
end
SPEC
end
def semantic_versioning_notice(repo_id, repo)
return <<-EOS
#{'――― MARKDOWN TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――'.reversed}
#{'――― MARKDOWN TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――'.reversed}
I’ve recently added [#{repo}](https://github.com/CocoaPods/Specs/tree/master/#{repo}) to the [CocoaPods](https://github.com/CocoaPods/CocoaPods) package manager repo.
......@@ -484,14 +494,14 @@ $ git tag -a 1.0.0 -m "Tag release 1.0.0"
$ git push --tags
```
#{'――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――'.reversed}
#{'――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――'.reversed}
#{'[!] This repo does not appear to have semantic version tags.'.yellow}
#{'[!] This repo does not appear to have semantic version tags.'.yellow}
After commiting the specification, consider opening a ticket with the template displayed above:
- link: https://github.com/#{repo_id}/issues/new
- title: Please add semantic version tags
EOS
EOS
end
end
end
......
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