Commit aaa4a8dc authored by Fabio Pelosin's avatar Fabio Pelosin

[Spec#lint] Simplified handling of directories and repos.

parent cfe61a69
...@@ -11,15 +11,16 @@ module Pod ...@@ -11,15 +11,16 @@ module Pod
Creates a PodSpec, in the current working dir, called `NAME.podspec'. Creates a PodSpec, in the current working dir, called `NAME.podspec'.
If a GitHub url is passed the spec is prepopulated. If a GitHub url is passed the spec is prepopulated.
$ pod spec lint [ NAME.podspec | REPO ] $ pod spec lint [ NAME.podspec | DIRECTORY ]
Validates `NAME.podspec'. In case `NAME.podspec' is omitted, it defaults Validates `NAME.podspec'. If a directory is provided it performs a quick
to `*.podspec' in the current working dir. If the name of a repo is validation on all the podspec files found, including subfolders. In case
provided it validates all its specs.} the argument is omitted, it defaults to the current working dir.
}
end end
def self.options def self.options
[ ["--quick", "Lint skips checks that would require to donwload and build the spec"], [ ["--quick", "Lint skips checks that would require to download and build the spec"],
["--only-errors", "Lint validates even if warnings are present"], ["--only-errors", "Lint validates even if warnings are present"],
["--no-clean", "Lint leaves the build directory intact for inspection"] ].concat(super) ["--no-clean", "Lint leaves the build directory intact for inspection"] ].concat(super)
end end
...@@ -74,10 +75,10 @@ module Pod ...@@ -74,10 +75,10 @@ module Pod
invalid_count = lint_podspecs invalid_count = lint_podspecs
count = specs_to_lint.count count = specs_to_lint.count
if invalid_count == 0 if invalid_count == 0
lint_passed_message = count == 1 ? "#{podspecs_to_lint.first.basename} passed validation" : "All the #{count} specs passed validation" lint_passed_message = count == 1 ? "#{podspecs_to_lint.first.basename} passed validation." : "All the specs passed validation."
puts lint_passed_message.green << "\n\n" unless config.silent? puts lint_passed_message.green << "\n\n" unless config.silent?
else else
raise Informative, count == 1 ? "The spec did not pass validation" : "#{invalid_count} out of #{count} specs failed validation" raise Informative, count == 1 ? "The spec did not pass validation." : "#{invalid_count} out of #{count} specs failed validation."
end end
end end
...@@ -87,12 +88,12 @@ module Pod ...@@ -87,12 +88,12 @@ module Pod
invalid_count = 0 invalid_count = 0
specs_to_lint.each do |spec| specs_to_lint.each do |spec|
# Show immediatly which pod is being processed. # Show immediatly which pod is being processed.
print " -> #{spec}\r" unless config.silent? || is_repo? print " -> #{spec}\r" unless config.silent? || @multiple_files
$stdout.flush $stdout.flush
linter = Linter.new(spec) linter = Linter.new(spec)
linter.lenient = @only_errors linter.lenient = @only_errors
linter.quick = @quick || is_repo? linter.quick = @quick || @multiple_files
linter.no_clean = @no_clean linter.no_clean = @no_clean
invalid_count += 1 unless linter.lint invalid_count += 1 unless linter.lint
...@@ -104,7 +105,7 @@ module Pod ...@@ -104,7 +105,7 @@ module Pod
puts unless config.silent? || should_skip?(linter) puts unless config.silent? || should_skip?(linter)
end end
puts "Analyzed #{specs_to_lint.count} specs in #{podspecs_to_lint.count} podspecs files.\n\n" if is_repo? && !config.silent? puts "Analyzed #{specs_to_lint.count} specs in #{podspecs_to_lint.count} podspecs files.\n\n" if @multiple_files && !config.silent?
invalid_count invalid_count
end end
...@@ -119,7 +120,7 @@ module Pod ...@@ -119,7 +120,7 @@ module Pod
end end
def should_skip?(linter) def should_skip?(linter)
is_repo? && linter.errors.empty? && linter.warnings.empty? && linter.notes.empty? @multiple_files && linter.errors.empty? && linter.warnings.empty? && linter.notes.empty?
end end
def print_messages(spec, type, messages) def print_messages(spec, type, messages)
...@@ -129,14 +130,14 @@ module Pod ...@@ -129,14 +130,14 @@ module Pod
def podspecs_to_lint def podspecs_to_lint
@podspecs_to_lint ||= begin @podspecs_to_lint ||= begin
if (is_repo?) path = Pathname.new(@repo_or_podspec || '.')
files = (config.repos_dir + @repo_or_podspec).glob('**/*.podspec') if path.directory?
elsif @repo_or_podspec files = path.glob('**/*.podspec')
files = [Pathname.new(@repo_or_podspec)] raise Informative, "No specs found in the current directory." if files.empty?
raise Informative, "Unable to find a spec named #{@repo_or_podspec}" unless files[0].exist? && @repo_or_podspec.include?('.podspec') @multiple_files = true
else else
files = Pathname.pwd.glob('**/*.podspec') files = [path]
raise Informative, "No specs found in the current directory" if files.empty? raise Informative, "Unable to find a spec named `#{@repo_or_podspec}'." unless files[0].exist? && @repo_or_podspec.include?('.podspec')
end end
files files
end end
...@@ -152,10 +153,6 @@ module Pod ...@@ -152,10 +153,6 @@ module Pod
end end
end end
def is_repo?
@is_repo ||= @repo_or_podspec && @repo_or_podspec != '.' && (config.repos_dir + @repo_or_podspec).exist? && !@repo_or_podspec.include?('/')
end
# Linter class # Linter class
# #
class Linter class Linter
...@@ -311,7 +308,7 @@ module Pod ...@@ -311,7 +308,7 @@ module Pod
# Some values are multiplaform # Some values are multiplaform
patterns = patterns.is_a?(Hash) ? patterns.values.flatten(1) : patterns patterns = patterns.is_a?(Hash) ? patterns.values.flatten(1) : patterns
patterns.each do |pattern| patterns.each do |pattern|
# Skip Filelist that would otherwise be resolved from the working directory resulting # Skip FileList that would otherwise be resolved from the working directory resulting
# in a potentially very expensi operation # in a potentially very expensi operation
next if pattern.is_a?(FileList) next if pattern.is_a?(FileList)
invalid = pattern.is_a?(Array) ? pattern.any? { |path| path.start_with?('/') } : pattern.start_with?('/') invalid = pattern.is_a?(Array) ? pattern.any? { |path| path.start_with?('/') } : pattern.start_with?('/')
......
...@@ -102,13 +102,13 @@ describe "Pod::Command::Spec#lint" do ...@@ -102,13 +102,13 @@ describe "Pod::Command::Spec#lint" do
it "lints a repo" do it "lints a repo" do
# The fixture has warnings so it raises # The fixture has warnings so it raises
cmd = command('spec', 'lint', 'master') cmd = command('spec', 'lint', "#{config.repos_dir}/master")
lambda { cmd.run }.should.raise Pod::Informative lambda { cmd.run }.should.raise Pod::Informative
cmd.output.should.include "WARN" cmd.output.should.include "WARN"
end end
it "complains if no repo name or url are provided and there a no specs in the current working directory" do it "complains if it can't find any spec to lint" do
Dir.chdir(fixture('spec-repos') + 'master/JSONKit/') do Dir.chdir(temporary_directory) do
lambda { command('spec', 'lint').run }.should.raise Pod::Informative lambda { command('spec', 'lint').run }.should.raise Pod::Informative
end 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