Class: Homebrew::TapAuditor Private

Inherits:
Object show all
Defined in:
tap_auditor.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Auditor for checking common violations in Taps.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tap, strict:) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • tap (Tap)
  • strict (Boolean, nil)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'tap_auditor.rb', line 13

def initialize(tap, strict:)
  Homebrew.with_no_api_env do
    @name                      = tap.name
    @path                      = tap.path
    @cask_tokens               = tap.cask_tokens
    @tap_audit_exceptions      = tap.audit_exceptions
    @tap_style_exceptions      = tap.style_exceptions
    @tap_pypi_formula_mappings = tap.pypi_formula_mappings
    @problems                  = []

    @formula_aliases = tap.aliases.map do |formula_alias|
      formula_alias.split("/").last
    end
    @formula_renames = tap.formula_renames
    @formula_names = tap.formula_names.map do |formula_name|
      formula_name.split("/").last
    end
  end
end

Instance Attribute Details

#cask_tokensObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



9
10
11
# File 'tap_auditor.rb', line 9

def cask_tokens
  @cask_tokens
end

#formula_aliasesObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



9
10
11
# File 'tap_auditor.rb', line 9

def formula_aliases
  @formula_aliases
end

#formula_namesObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



9
10
11
# File 'tap_auditor.rb', line 9

def formula_names
  @formula_names
end

#formula_renamesObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



9
10
11
# File 'tap_auditor.rb', line 9

def formula_renames
  @formula_renames
end

#nameObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



9
10
11
# File 'tap_auditor.rb', line 9

def name
  @name
end

#pathObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



9
10
11
# File 'tap_auditor.rb', line 9

def path
  @path
end

#problemsObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



9
10
11
# File 'tap_auditor.rb', line 9

def problems
  @problems
end

#tap_audit_exceptionsObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



9
10
11
# File 'tap_auditor.rb', line 9

def tap_audit_exceptions
  @tap_audit_exceptions
end

#tap_pypi_formula_mappingsObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



9
10
11
# File 'tap_auditor.rb', line 9

def tap_pypi_formula_mappings
  @tap_pypi_formula_mappings
end

#tap_style_exceptionsObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



9
10
11
# File 'tap_auditor.rb', line 9

def tap_style_exceptions
  @tap_style_exceptions
end

Instance Method Details

#auditvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



34
35
36
37
38
# File 'tap_auditor.rb', line 34

def audit
  audit_json_files
  audit_tap_formula_lists
  audit_aliases_renames_duplicates
end

#audit_aliases_renames_duplicatesvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



58
59
60
61
62
63
# File 'tap_auditor.rb', line 58

def audit_aliases_renames_duplicates
  duplicates = formula_aliases & formula_renames.keys
  return if duplicates.none?

  problem "The following should either be an alias or a rename, not both: #{duplicates.to_sentence}"
end

#audit_json_filesvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



41
42
43
44
45
46
47
48
# File 'tap_auditor.rb', line 41

def audit_json_files
  json_patterns = Tap::HOMEBREW_TAP_JSON_FILES.map { |pattern| @path/pattern }
  Pathname.glob(json_patterns).each do |file|
    JSON.parse file.read
  rescue JSON::ParserError
    problem "#{file.to_s.delete_prefix("#{@path}/")} contains invalid JSON"
  end
end

#audit_tap_formula_listsvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



51
52
53
54
55
# File 'tap_auditor.rb', line 51

def audit_tap_formula_lists
  check_formula_list_directory "audit_exceptions", @tap_audit_exceptions
  check_formula_list_directory "style_exceptions", @tap_style_exceptions
  check_formula_list "pypi_formula_mappings", @tap_pypi_formula_mappings
end

#problem(message) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



66
67
68
# File 'tap_auditor.rb', line 66

def problem(message)
  @problems << ({ message: message, location: nil, corrected: false })
end