Commit 35a650f7 authored by Fabio Pelosin's avatar Fabio Pelosin

[Pod::Command::Spec] --quick option and misc

- renamed --no-build option to --quick, simplified options handling
- simplified initialization
- removed repo check for license warning
- minor cleaning
parent b2f67363
...@@ -19,23 +19,26 @@ module Pod ...@@ -19,23 +19,26 @@ module Pod
end end
def self.options def self.options
[ ["--no-install", "Lint skips checks that would require to donwload the spec"], [ ["--quick", "Lint skips checks that would require to donwload and build the spec"],
["--only-errors", "Lint validates even if warnings are present"] ].concat(super) ["--only-errors", "Lint validates even if warnings are present"] ].concat(super)
end end
def initialize(argv) def initialize(argv)
@no_install = argv.option('--no-install') @action = argv.shift_argument
@only_errors = argv.option('--only-errors') if @action == 'create'
@name_or_url = argv.shift_argument
args = argv.arguments @url = argv.shift_argument
unless (args[0] == 'create' && (2..3).member?(args.size)) || super if @name_or_url.nil?
(args[0] == 'lint' && args.size <= 2) elsif @action == 'lint'
@quick = argv.option('--quick')
@only_errors = argv.option('--only-errors')
@repo_or_podspec = argv.shift_argument unless argv.empty?
super unless argv.size <= 1
else
super super
end end
@action, @name_or_url = args.first(2)
if @action == 'create' && args.size == 3 super unless argv.empty?
@url = args[2]
end
end end
def run def run
...@@ -58,16 +61,22 @@ module Pod ...@@ -58,16 +61,22 @@ module Pod
end end
def lint def lint
is_repo = repo_with_name_exist(@name_or_url) if (is_repo = repo_with_name_exist(@repo_or_podspec))
if is_repo files = (config.repos_dir + @repo_or_podspec).glob('**/*.podspec')
files = (config.repos_dir + @name_or_url).glob('**/*.podspec')
else else
name = @name_or_url if @repo_or_podspec
files = name ? [Pathname.new(name)] : Pathname.pwd.glob('*.podspec') files = [Pathname.new(@repo_or_podspec)]
raise Informative, "[!] Unable to find a spec named #{@repo_or_podspec}".red unless files[0].exist?
else
files = Pathname.pwd.glob('*.podspec')
raise Informative, "[!] No specs found in the current directory".red if files.empty?
end
end end
puts puts
all_valid = lint_specs_files(files, is_repo) all_valid = lint_specs_files(files, is_repo)
unless all_valid if all_valid
puts (files.count == 1 ? "#{@repo_or_podspec} passed validation" : "All the specs passed validation").green
else
message = (files.count == 1 ? "[!] The spec did not pass validation" : "[!] Not all specs passed validation").red message = (files.count == 1 ? "[!] The spec did not pass validation" : "[!] Not all specs passed validation").red
raise Informative, message raise Informative, message
end end
...@@ -98,10 +107,11 @@ module Pod ...@@ -98,10 +107,11 @@ module Pod
print " -> #{spec}\r" unless config.silent? || is_repo print " -> #{spec}\r" unless config.silent? || is_repo
$stdout.flush $stdout.flush
# If the spec doesn't validate it raises and informative
spec.validate! spec.validate!
warnings = warnings_for_spec(spec, file, is_repo) warnings = warnings_for_spec(spec, file, is_repo)
deprecations = deprecation_notices_for_spec(spec, file, is_repo) deprecations = deprecation_notices_for_spec(spec, file, is_repo)
if is_repo || @no_install if is_repo || @quick
build_messages, file_errors = [], [] build_messages, file_errors = [], []
else else
tmp_dir.mkpath tmp_dir.mkpath
...@@ -109,10 +119,10 @@ module Pod ...@@ -109,10 +119,10 @@ module Pod
file_errors = Dir.chdir(tmp_dir) { file_errors_for_spec(spec, file, is_repo) } file_errors = Dir.chdir(tmp_dir) { file_errors_for_spec(spec, file, is_repo) }
tmp_dir.rmtree tmp_dir.rmtree
end end
# Errors compromise the functionality of a spec, warnings can be ignored
build_errors = build_messages.select {|msg| msg.include?('error')} build_errors = build_messages.select {|msg| msg.include?('error')}
build_warnings = build_messages - build_errors build_warnings = build_messages - build_errors
# Errors compromise the functionality of a spec, warnings can be ignored
all = warnings + deprecations + build_messages + file_errors all = warnings + deprecations + build_messages + file_errors
errors = file_errors + build_errors errors = file_errors + build_errors
warnings = all - errors warnings = all - errors
...@@ -171,10 +181,9 @@ module Pod ...@@ -171,10 +181,9 @@ module Pod
warnings << "Github repositories should end in `.git'" if source && source[:git] =~ /github.com/ && source[:git] !~ /.*\.git/ warnings << "Github repositories should end in `.git'" if source && source[:git] =~ /github.com/ && source[:git] !~ /.*\.git/
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.description !~ /.*\./
warnings << "The summary should end with a dot" if spec.summary !~ /.*\./ warnings << "The summary should end with a dot" if spec.summary !~ /.*\./
#TODO: the following 'is_repo' and '@no_install' checks are there only because at the time of 0.6.0rc1 it would be triggered in all specs warnings << "Missing license[:file] or [:text]" unless license && (license[:file] || license[:text])
warnings << "Missing license[:file] or [:text]" unless is_repo || @no_install || 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
# allow a single line comment as it is generally used in subspecs
warnings << "Comments must be deleted" if text =~ /^\w*#\n\w*#/
warnings warnings
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