Class: Pod::Specification::Linter

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-core/specification/linter.rb

Overview

The Linter check specifications for errors and warnings.

It is designed not only to guarantee the formal functionality of a specification, but also to support the maintenance of sources.

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec_or_path) ⇒ Linter

Returns a new instance of Linter.

Parameters:

  • spec_or_path (Specification, Pathname, String)

    the Specification or the path of the ‘podspec` file to lint.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cocoapods-core/specification/linter.rb', line 23

def initialize(spec_or_path)
  if spec_or_path.is_a?(Specification)
    @spec = spec_or_path
    @file = @spec.defined_in_file
  else
    @file = Pathname.new(spec_or_path)
    begin
      @spec = Specification.from_file(@file)
    rescue Exception => e
      @spec = nil
      @raise_message = e.message
    end
  end
end

Instance Attribute Details

#filePathname (readonly)

Returns the path of the ‘podspec` file where #spec is defined.

Returns:

  • (Pathname)

    the path of the ‘podspec` file where #spec is defined.



18
19
20
# File 'lib/cocoapods-core/specification/linter.rb', line 18

def file
  @file
end

#resultsArray<Result> (readonly)

Returns all the results generated by the Linter.

Returns:

  • (Array<Result>)

    all the results generated by the Linter.



65
66
67
# File 'lib/cocoapods-core/specification/linter.rb', line 65

def results
  @results
end

#specSpecification (readonly)

Returns the specification to lint.

Returns:



13
14
15
# File 'lib/cocoapods-core/specification/linter.rb', line 13

def spec
  @spec
end

Instance Method Details

#errorsArray<Result>

Returns all the errors generated by the Linter.

Returns:

  • (Array<Result>)

    all the errors generated by the Linter.



69
70
71
# File 'lib/cocoapods-core/specification/linter.rb', line 69

def errors
  @errors ||= results.select { |r| r.type == :error }
end

#lintBool

Lints the specification adding a Result for any failed check to the #results list.

Returns:

  • (Bool)

    whether the specification passed validation.



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cocoapods-core/specification/linter.rb', line 43

def lint
  @results = []
  if spec
    perform_textual_analysis
    check_required_root_attributes
    run_root_validation_hooks
    perform_all_specs_ananlysis
  else
    error "The specification defined in `#{file}` could not be loaded." \
      "\n\n#{@raise_message}"
  end
  results.empty?
end

#warningsArray<Result>

Returns all the warnings generated by the Linter.

Returns:

  • (Array<Result>)

    all the warnings generated by the Linter.



75
76
77
# File 'lib/cocoapods-core/specification/linter.rb', line 75

def warnings
  @warnings ||= results.select { |r| r.type == :warning }
end