Class: Pod::Validator
- Inherits:
-
Object
- Object
- Pod::Validator
- Includes:
- Config::Mixin
- Defined in:
- lib/cocoapods/validator.rb
Overview
Validates a Specification.
Extends the Linter from the Core to add additional which require the LocalPod and the Installer.
In detail it checks that the file patterns defined by the user match actually do match at least a file and that the Pod builds, by installing it without integration and building the project with xcodebuild.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- DEFAULT_SWIFT_VERSION =
The default version of Swift to use when linting pods
'3.2'.freeze
- VALID_PLATFORMS =
The valid platforms for linting
Platform.all.freeze
Instance Attribute Summary collapse
-
#allow_warnings ⇒ Bool
Whether the validator should fail on warnings, or only on errors.
-
#fail_fast ⇒ Bool
Whether the linter should fail as soon as the first build variant causes an error.
-
#file_accessor ⇒ Sandbox::FileAccessor
The file accessor for the spec.
-
#ignore_public_only_results ⇒ Boolean
Whether attributes that affect only public sources Bool be skipped.
-
#linter ⇒ Specification::Linter
readonly
The linter instance from CocoaPods Core.
-
#local ⇒ Bool
(also: #local?)
Whether the validation should be performed against the root of the podspec instead to its original source.
-
#no_clean ⇒ Bool
Whether the linter should not clean up temporary files for inspection.
-
#no_subspecs ⇒ Bool
Whether the validator should validate all subspecs.
-
#only_subspec ⇒ String
Name of the subspec to check, if nil all subspecs are checked.
-
#quick ⇒ Bool
Whether the validation should skip the checks that requires the download of the library.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#skip_import_validation ⇒ Object
(also: #skip_import_validation?)
Returns the value of attribute skip_import_validation.
-
#skip_tests ⇒ Bool
Whether the validator should skip building and running tests.
-
#swift_version ⇒ String
The SWIFT_VERSION to use for validation.
-
#use_frameworks ⇒ Bool
Whether frameworks should be used for the installation.
Instance Method Summary collapse
-
#dot_swift_version ⇒ String
The SWIFT_VERSION in the .swift-version file or nil.
- #failure_reason ⇒ Object
-
#file ⇒ Pathname
The path of the ‘podspec` file where #spec is defined.
-
#initialize(spec_or_path, source_urls, platforms = []) ⇒ Validator
constructor
Initialize a new instance.
-
#platforms_to_lint(spec) ⇒ Array<Platform>
Returns a list of platforms to lint for a given Specification.
-
#print_results ⇒ void
Prints the result of the validation to the user.
-
#result_color ⇒ Symbol
The color, which should been used to display the result.
-
#result_type ⇒ Symbol
The type, which should been used to display the result.
- #results_message ⇒ Object
-
#spec ⇒ Specification
The specification to lint.
-
#uses_swift? ⇒ Boolean
Whether any of the pod targets part of this validator use Swift or not.
- #validate ⇒ Bool
- #validated? ⇒ Boolean
-
#validation_dir ⇒ Pathname
The temporary directory used by the linter.
Methods included from Config::Mixin
Constructor Details
#initialize(spec_or_path, source_urls, platforms = []) ⇒ Validator
Initialize a new instance
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cocoapods/validator.rb', line 41 def initialize(spec_or_path, source_urls, platforms = []) @linter = Specification::Linter.new(spec_or_path) @source_urls = if @linter.spec && @linter.spec.dependencies.empty? && @linter.spec.recursive_subspecs.all? { |s| s.dependencies.empty? } [] else source_urls.map { |url| config.sources_manager.source_with_name_or_url(url) }.map(&:url) end @platforms = platforms.map do |platform| result = case platform.to_s.downcase # Platform doesn't recognize 'macos' as being the same as 'osx' when initializing when 'macos' then Platform.macos else Platform.new(platform, nil) end unless valid_platform?(result) raise Informative, "Unrecognized platform `#{platform}`. Valid platforms: #{VALID_PLATFORMS.join(', ')}" end result end end |
Instance Attribute Details
#allow_warnings ⇒ Bool
Returns Whether the validator should fail on warnings, or only on errors.
228 229 230 |
# File 'lib/cocoapods/validator.rb', line 228 def allow_warnings @allow_warnings end |
#fail_fast ⇒ Bool
Returns whether the linter should fail as soon as the first build variant causes an error. Helpful for i.e. multi-platforms specs, specs with subspecs.
216 217 218 |
# File 'lib/cocoapods/validator.rb', line 216 def fail_fast @fail_fast end |
#file_accessor ⇒ Sandbox::FileAccessor
Returns the file accessor for the spec.
101 102 103 |
# File 'lib/cocoapods/validator.rb', line 101 def file_accessor @file_accessor end |
#ignore_public_only_results ⇒ Boolean
Returns Whether attributes that affect only public sources Bool be skipped.
249 250 251 |
# File 'lib/cocoapods/validator.rb', line 249 def ignore_public_only_results @ignore_public_only_results end |
#linter ⇒ Specification::Linter (readonly)
Returns the linter instance from CocoaPods Core.
28 29 30 |
# File 'lib/cocoapods/validator.rb', line 28 def linter @linter end |
#local ⇒ Bool Also known as: local?
Uses the ‘:path` option of the Podfile.
Returns whether the validation should be performed against the root of the podspec instead to its original source.
223 224 225 |
# File 'lib/cocoapods/validator.rb', line 223 def local @local end |
#no_clean ⇒ Bool
Returns whether the linter should not clean up temporary files for inspection.
210 211 212 |
# File 'lib/cocoapods/validator.rb', line 210 def no_clean @no_clean end |
#no_subspecs ⇒ Bool
Returns Whether the validator should validate all subspecs.
236 237 238 |
# File 'lib/cocoapods/validator.rb', line 236 def no_subspecs @no_subspecs end |
#only_subspec ⇒ String
Returns name of the subspec to check, if nil all subspecs are checked.
232 233 234 |
# File 'lib/cocoapods/validator.rb', line 232 def only_subspec @only_subspec end |
#quick ⇒ Bool
Returns whether the validation should skip the checks that requires the download of the library.
205 206 207 |
# File 'lib/cocoapods/validator.rb', line 205 def quick @quick end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
260 261 262 |
# File 'lib/cocoapods/validator.rb', line 260 def results @results end |
#skip_import_validation ⇒ Object Also known as: skip_import_validation?
Returns the value of attribute skip_import_validation.
251 252 253 |
# File 'lib/cocoapods/validator.rb', line 251 def skip_import_validation @skip_import_validation end |
#skip_tests ⇒ Bool
Returns Whether the validator should skip building and running tests.
240 241 242 |
# File 'lib/cocoapods/validator.rb', line 240 def skip_tests @skip_tests end |
#swift_version ⇒ String
Returns the SWIFT_VERSION to use for validation.
299 300 301 302 303 304 305 306 |
# File 'lib/cocoapods/validator.rb', line 299 def swift_version return @swift_version unless @swift_version.nil? if (version = spec.swift_version) || (version = dot_swift_version) @swift_version = version.to_s else DEFAULT_SWIFT_VERSION end end |
#use_frameworks ⇒ Bool
Returns Whether frameworks should be used for the installation.
244 245 246 |
# File 'lib/cocoapods/validator.rb', line 244 def use_frameworks @use_frameworks end |
Instance Method Details
#dot_swift_version ⇒ String
Returns the SWIFT_VERSION in the .swift-version file or nil.
314 315 316 317 318 319 |
# File 'lib/cocoapods/validator.rb', line 314 def dot_swift_version return unless file swift_version_path = file.dirname + '.swift-version' return unless swift_version_path.exist? swift_version_path.read.strip end |
#failure_reason ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/cocoapods/validator.rb', line 176 def failure_reason results_by_type = results.group_by(&:type) results_by_type.default = [] return nil if validated? reasons = [] if (size = results_by_type[:error].size) && size > 0 reasons << "#{size} #{'error'.pluralize(size)}" end 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? 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 |
#file ⇒ Pathname
Returns the path of the ‘podspec` file where #spec is defined.
73 74 75 |
# File 'lib/cocoapods/validator.rb', line 73 def file @linter.file end |
#platforms_to_lint(spec) ⇒ Array<Platform>
Returns a list of platforms to lint for a given Specification
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cocoapods/validator.rb', line 84 def platforms_to_lint(spec) return spec.available_platforms if @platforms.empty? # Validate that the platforms specified are actually supported by the spec results = @platforms.map do |platform| matching_platform = spec.available_platforms.find { |p| p.name == platform.name } unless matching_platform raise Informative, "Platform `#{platform}` is not supported by specification `#{spec}`." end matching_platform end.uniq results end |
#print_results ⇒ void
This method returns an undefined value.
Prints the result of the validation to the user.
139 140 141 |
# File 'lib/cocoapods/validator.rb', line 139 def print_results UI.puts end |
#result_color ⇒ Symbol
Returns The color, which should been used to display the result. One of: ‘:green`, `:yellow`, `:red`.
284 285 286 287 288 289 |
# File 'lib/cocoapods/validator.rb', line 284 def result_color case result_type when :error then :red when :warning then :yellow else :green end end |
#result_type ⇒ Symbol
Returns The type, which should been used to display the result. One of: ‘:error`, `:warning`, `:note`.
271 272 273 274 275 276 277 278 279 |
# File 'lib/cocoapods/validator.rb', line 271 def result_type 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 end end |
#results_message ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/cocoapods/validator.rb', line 143 def = '' results.each do |result| if result.platforms == [:ios] = '[iOS] ' elsif result.platforms == [:osx] = '[OSX] ' elsif result.platforms == [:watchos] = '[watchOS] ' elsif result.platforms == [:tvos] = '[tvOS] ' end = '' if result.is_a?(Result) subspecs = result.subspecs.uniq if subspecs.count > 2 = '[' + subspecs[0..2].join(', ') + ', and more...] ' elsif subspecs.count > 0 = '[' + subspecs.join(',') + '] ' end end case result.type when :error then type = 'ERROR' when :warning then type = 'WARN' when :note then type = 'NOTE' else raise "#{result.type}" end << " - #{type.ljust(5)} | #{}#{}#{result.attribute_name}: #{result.}\n" end << "\n" end |
#spec ⇒ Specification
Returns the specification to lint.
66 67 68 |
# File 'lib/cocoapods/validator.rb', line 66 def spec @linter.spec end |
#uses_swift? ⇒ Boolean
Returns Whether any of the pod targets part of this validator use Swift or not.
323 324 325 |
# File 'lib/cocoapods/validator.rb', line 323 def uses_swift? @installer.pod_targets.any?(&:uses_swift?) end |
#validate ⇒ Bool
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/cocoapods/validator.rb', line 113 def validate @results = [] # Replace default spec with a subspec if asked for a_spec = spec if spec && @only_subspec subspec_name = @only_subspec.start_with?(spec.root.name) ? @only_subspec : "#{spec.root.name}/#{@only_subspec}" a_spec = spec.subspec_by_name(subspec_name, true, true) @subspec_name = a_spec.name end UI.print " -> #{a_spec ? a_spec.name : file.basename}\r" unless config.silent? $stdout.flush perform_linting perform_extensive_analysis(a_spec) if a_spec && !quick UI.puts ' -> '.send(result_color) << (a_spec ? a_spec.to_s : file.basename.to_s) print_results validated? end |
#validated? ⇒ Boolean
264 265 266 |
# File 'lib/cocoapods/validator.rb', line 264 def validated? result_type != :error && (result_type != :warning || allow_warnings) end |
#validation_dir ⇒ Pathname
Returns the temporary directory used by the linter.
293 294 295 |
# File 'lib/cocoapods/validator.rb', line 293 def validation_dir @validation_dir ||= Pathname(Dir.mktmpdir(['CocoaPods-Lint-', "-#{spec.name}"])) end |