Commit 0de9eca7 authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #2749 from CocoaPods/seg-linter-private-mode

[Validator] Add private mode
parents 22ff2516 573310b5
......@@ -51,6 +51,13 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[#3905](https://github.com/CocoaPods/CocoaPods/issues/3905)
[#4028](https://github.com/CocoaPods/CocoaPods/pull/4028)
* Add a `--private` option to `pod spec lint`, `pod lib lint`, and
`pod repo push` that will ignore warnings that only apply to public
specifications and sources.
[Samuel Giddins](https://github.com/segiddins)
[Core#190](https://github.com/CocoaPods/Core/issues/190)
[#2682](https://github.com/CocoaPods/CocoaPods/issues/2682)
## 0.38.2
......
......@@ -7,7 +7,7 @@ GIT
GIT
remote: https://github.com/CocoaPods/Core.git
revision: f2d6aeccba25972c44094572e3906ca4c886c568
revision: fd41ee938a5687a39711b0f3d1f9e76dd506dd5d
branch: master
specs:
cocoapods-core (0.38.2)
......
......@@ -115,7 +115,8 @@ module Pod
DESC
def self.options
[['--quick', 'Lint skips checks that would require to download and build the spec'],
[
['--quick', 'Lint skips checks that would require to download and build the spec'],
['--allow-warnings', 'Lint validates even if warnings are present'],
['--subspec=NAME', 'Lint validates only the given subspec'],
['--no-subspecs', 'Lint skips validation of subspecs'],
......@@ -123,8 +124,10 @@ module Pod
['--fail-fast', 'Lint stops on the first failing platform or subspec'],
['--use-libraries', 'Lint uses static libraries to install the spec'],
['--sources=https://github.com/artsy/Specs,master', 'The sources from which to pull dependant pods ' \
'(defaults to https://github.com/CocoaPods/Specs.git). '\
'Multiple sources must be comma-delimited.']].concat(super)
'(defaults to https://github.com/CocoaPods/Specs.git). ' \
'Multiple sources must be comma-delimited.'],
['--private', 'Lint skips checks that apply only to public specs'],
].concat(super)
end
def initialize(argv)
......@@ -136,6 +139,7 @@ module Pod
@only_subspec = argv.option('subspec')
@use_frameworks = !argv.flag?('use-libraries')
@source_urls = argv.option('sources', 'https://github.com/CocoaPods/Specs.git').split(',')
@private = argv.flag?('private', false)
@podspecs_paths = argv.arguments!
super
end
......@@ -156,6 +160,7 @@ module Pod
validator.no_subspecs = !@subspecs || @only_subspec
validator.only_subspec = @only_subspec
validator.use_frameworks = @use_frameworks
validator.ignore_public_only_results = @private
validator.validate
unless @clean
......
......@@ -15,7 +15,9 @@ module Pod
]
def self.options
[['--only-errors', 'Lint presents only the errors']].concat(super)
[
['--only-errors', 'Lint presents only the errors'],
].concat(super)
end
def initialize(argv)
......
......@@ -20,12 +20,15 @@ module Pod
]
def self.options
[['--allow-warnings', 'Allows pushing even if there are warnings'],
[
['--allow-warnings', 'Allows pushing even if there are warnings'],
['--use-libraries', 'Linter uses static libraries to install the spec'],
['--sources=https://github.com/artsy/Specs,master', 'The sources from which to pull dependant pods ' \
'(defaults to all available repos). '\
'(defaults to all available repos). ' \
'Multiple sources must be comma-delimited.'],
['--local-only', 'Does not perform the step of pushing REPO to its remote']].concat(super)
['--local-only', 'Does not perform the step of pushing REPO to its remote'],
['--no-private', 'Lint includes checks that apply only to public repos'],
].concat(super)
end
def initialize(argv)
......@@ -35,6 +38,7 @@ module Pod
@source_urls = argv.option('sources', SourcesManager.all.map(&:url).join(',')).split(',')
@podspec = argv.shift_argument
@use_frameworks = !argv.flag?('use-libraries')
@private = argv.flag?('private', true)
super
end
......@@ -91,6 +95,7 @@ module Pod
validator = Validator.new(podspec, @source_urls)
validator.allow_warnings = @allow_warnings
validator.use_frameworks = @use_frameworks
validator.ignore_public_only_results = @private
begin
validator.validate
rescue => e
......
......@@ -15,7 +15,8 @@ module Pod
]
def self.options
[['--quick', 'Lint skips checks that would require to download and build the spec'],
[
['--quick', 'Lint skips checks that would require to download and build the spec'],
['--allow-warnings', 'Lint validates even if warnings are present'],
['--subspec=NAME', 'Lint validates only the given subspec'],
['--no-subspecs', 'Lint skips validation of subspecs'],
......@@ -23,8 +24,10 @@ module Pod
['--fail-fast', 'Lint stops on the first failing platform or subspec'],
['--use-libraries', 'Lint uses static libraries to install the spec'],
['--sources=https://github.com/artsy/Specs,master', 'The sources from which to pull dependant pods ' \
'(defaults to https://github.com/CocoaPods/Specs.git). '\
'Multiple sources must be comma-delimited.']].concat(super)
'(defaults to https://github.com/CocoaPods/Specs.git). ' \
'Multiple sources must be comma-delimited.'],
['--private', 'Lint skips checks that apply only to public specs'],
].concat(super)
end
def initialize(argv)
......@@ -36,6 +39,7 @@ module Pod
@only_subspec = argv.option('subspec')
@use_frameworks = !argv.flag?('use-libraries')
@source_urls = argv.option('sources', 'https://github.com/CocoaPods/Specs.git').split(',')
@private = argv.flag?('private', false)
@podspecs_paths = argv.arguments!
super
end
......@@ -52,6 +56,7 @@ module Pod
validator.no_subspecs = !@subspecs || @only_subspec
validator.only_subspec = @only_subspec
validator.use_frameworks = @use_frameworks
validator.ignore_public_only_results = @private
validator.validate
failure_reasons << validator.failure_reason
......
......@@ -130,6 +130,10 @@ module Pod
reason << " (but you can use `--allow-warnings` to ignore #{pronoun})" if reasons.empty?
reasons << reason
end
if results.all?(&:public_only)
reasons << 'All results apply only to public specs, but you can use ' \
'`--private` to ignore them if linting the specification for a private pod.'
end
reasons.to_sentence
end
......@@ -177,6 +181,11 @@ module Pod
#
attr_accessor :use_frameworks
# @return [Boolean] Whether attributes that affect only public sources
# Bool be skipped.
#
attr_accessor :ignore_public_only_results
#-------------------------------------------------------------------------#
# !@group Lint results
......@@ -195,7 +204,9 @@ module Pod
# One of: `:error`, `:warning`, `:note`.
#
def result_type
types = results.map(&:type).uniq
applicable_results = results
applicable_results = applicable_results.reject(&:public_only?) if ignore_public_only_results
types = applicable_results.map(&:type).uniq
if types.include?(:error) then :error
elsif types.include?(:warning) then :warning
else :note
......@@ -277,9 +288,9 @@ module Pod
resp = Pod::HTTP.validate_url(url)
if !resp
warning('url', "There was a problem validating the URL #{url}.")
warning('url', "There was a problem validating the URL #{url}.", true)
elsif !resp.success?
warning('url', "The URL (#{url}) is not reachable.")
warning('url', "The URL (#{url}) is not reachable.", true)
end
resp
......@@ -297,8 +308,8 @@ module Pod
#
def validate_screenshots(spec)
spec.screenshots.compact.each do |screenshot|
request = validate_url(screenshot)
if request && !(request.headers['content-type'] && request.headers['content-type'].first =~ /image\/.*/i)
response = validate_url(screenshot)
if response && !(response.headers['content-type'] && response.headers['content-type'].first =~ /image\/.*/i)
warning('screenshot', "The screenshot #{screenshot} is not a valid image.")
end
end
......@@ -490,24 +501,24 @@ module Pod
# !@group Result Helpers
def error(attribute_name, message)
add_result(:error, attribute_name, message)
def error(*args)
add_result(:error, *args)
end
def warning(attribute_name, message)
add_result(:warning, attribute_name, message)
def warning(*args)
add_result(:warning, *args)
end
def note(attribute_name, message)
add_result(:note, attribute_name, message)
def note(*args)
add_result(:note, *args)
end
def add_result(type, attribute_name, message)
def add_result(type, attribute_name, message, public_only = false)
result = results.find do |r|
r.type == type && r.attribute_name && r.message == message
r.type == type && r.attribute_name && r.message == message && r.public_only? == public_only
end
unless result
result = Result.new(type, attribute_name, message)
result = Result.new(type, attribute_name, message, public_only)
results << result
end
result.platforms << consumer.platform_name if consumer
......@@ -517,8 +528,8 @@ module Pod
# Specialized Result to support subspecs aggregation
#
class Result < Specification::Linter::Results::Result
def initialize(type, attribute_name, message)
super(type, attribute_name, message)
def initialize(type, attribute_name, message, public_only = false)
super(type, attribute_name, message, public_only)
@subspecs = []
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