Skip to content

Commit

Permalink
Add private lint option
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Aug 16, 2015
1 parent 22ff251 commit 45edab8
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 51 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Expand Up @@ -9,7 +9,7 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Bug Fixes

* Build settings specified in `pod_target_xcconfig` of a spec are also for
library targets only applied to the pod target.
library targets only applied to the pod target.
[Marius Rackwitz](https://github.com/mrackwitz)
[#3906](https://github.com/CocoaPods/CocoaPods/issues/3906)

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -15,7 +15,7 @@ gem 'json', '1.7.7'

group :development do
cp_gem 'claide', 'CLAide'
cp_gem 'cocoapods-core', 'Core'
cp_gem 'cocoapods-core', 'Core', 'seg-linter-private-mode'
cp_gem 'cocoapods-downloader', 'cocoapods-downloader'
cp_gem 'cocoapods-plugins', 'cocoapods-plugins'
cp_gem 'cocoapods-stats', 'cocoapods-stats'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -7,8 +7,8 @@ GIT

GIT
remote: https://github.com/CocoaPods/Core.git
revision: f2d6aeccba25972c44094572e3906ca4c886c568
branch: master
revision: 2b4ef62c5e1be45d04e417b6712e1651d40f8d63
branch: seg-linter-private-mode
specs:
cocoapods-core (0.38.2)
activesupport (>= 3.2.15)
Expand Down
25 changes: 15 additions & 10 deletions lib/cocoapods/command/lib.rb
Expand Up @@ -115,16 +115,19 @@ class Lint < Lib
DESC

def self.options
[['--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'],
['--no-clean', 'Lint leaves the build directory intact for inspection'],
['--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)
[
['--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'],
['--no-clean', 'Lint leaves the build directory intact for inspection'],
['--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.'],
['--private', 'Lint skips checks that apply only to public specs'],
].concat(super)
end

def initialize(argv)
Expand All @@ -136,6 +139,7 @@ def initialize(argv)
@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
Expand All @@ -156,6 +160,7 @@ def run
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
Expand Down
4 changes: 3 additions & 1 deletion lib/cocoapods/command/repo/lint.rb
Expand Up @@ -15,7 +15,9 @@ class Lint < Repo
]

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)
Expand Down
17 changes: 11 additions & 6 deletions lib/cocoapods/command/repo/push.rb
Expand Up @@ -20,12 +20,15 @@ class Push < Repo
]

def self.options
[['--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). '\
'Multiple sources must be comma-delimited.'],
['--local-only', 'Does not perform the step of pushing REPO to its remote']].concat(super)
[
['--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). ' \
'Multiple sources must be comma-delimited.'],
['--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)
Expand All @@ -35,6 +38,7 @@ def initialize(argv)
@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

Expand Down Expand Up @@ -91,6 +95,7 @@ def validate_podspec_files
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
Expand Down
25 changes: 15 additions & 10 deletions lib/cocoapods/command/spec/lint.rb
Expand Up @@ -15,16 +15,19 @@ class Lint < Spec
]

def self.options
[['--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'],
['--no-clean', 'Lint leaves the build directory intact for inspection'],
['--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)
[
['--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'],
['--no-clean', 'Lint leaves the build directory intact for inspection'],
['--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.'],
['--private', 'Lint skips checks that apply only to public specs'],
].concat(super)
end

def initialize(argv)
Expand All @@ -36,6 +39,7 @@ def initialize(argv)
@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
Expand All @@ -52,6 +56,7 @@ def run
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

Expand Down
51 changes: 31 additions & 20 deletions lib/cocoapods/validator.rb
Expand Up @@ -62,7 +62,7 @@ def file
# @return [Bool] whether the specification passed validation.
#
def validate
@results = []
@results = []

# Replace default spec with a subspec if asked for
a_spec = spec
Expand Down Expand Up @@ -127,9 +127,13 @@ def failure_reason
if !allow_warnings && (size = results_by_type[:warning].size) && size > 0
reason = "#{size} #{'warning'.pluralize(size)}"
pronoun = size == 1 ? 'it' : 'them'
reason << " (but you can use `--allow-warnings` to ignore #{pronoun})" if reasons.empty?
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

Expand Down Expand Up @@ -177,6 +181,11 @@ def failure_reason
#
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
Expand All @@ -195,7 +204,9 @@ def validated?
# 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
Expand Down Expand Up @@ -277,9 +288,9 @@ def validate_url(url)
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
Expand All @@ -297,8 +308,8 @@ def validate_homepage(spec)
#
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
Expand Down Expand Up @@ -395,7 +406,7 @@ def build_pod
UI.message "\nBuilding with xcodebuild.\n".yellow do
output = Dir.chdir(config.sandbox_root) { xcodebuild }
UI.puts output
parsed_output = parse_xcodebuild_output(output)
parsed_output = parse_xcodebuild_output(output)
parsed_output.each do |message|
# Checking the error for `InputFile` is to work around an Xcode
# issue where linting would fail even though `xcodebuild` actually
Expand Down Expand Up @@ -490,24 +501,24 @@ def _validate_header_files(attr_name)

# !@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
Expand All @@ -517,8 +528,8 @@ def add_result(type, attribute_name, message)
# 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

Expand Down Expand Up @@ -583,7 +594,7 @@ def podfile_from_spec(platform_name, deployment_target, use_frameworks = true)
def parse_xcodebuild_output(output)
lines = output.split("\n")
selected_lines = lines.select do |l|
l.include?('error: ') && (l !~ /errors? generated\./) && (l !~ /error: \(null\)/) ||
l.include?('error: ') && (l !~ /errors? generated\./) && (l !~ /error: \(null\)/) ||
l.include?('warning: ') && (l !~ /warnings? generated\./) && (l !~ /frameworks only run on iOS 8/) ||
l.include?('note: ') && (l !~ /expanded from macro/)
end
Expand Down

0 comments on commit 45edab8

Please sign in to comment.