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)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'tap_auditor.rb', line 40

def initialize(tap, strict:)
  @name                                           = T.let(tap.name, String)
  @path                                           = T.let(tap.path, Pathname)
  @tap_audit_exceptions                           = T.let(tap.audit_exceptions, T::Hash[Symbol, T.untyped])
  @tap_style_exceptions                           = T.let(tap.style_exceptions, T::Hash[Symbol, T.untyped])
  @tap_synced_versions_formulae                   = T.let(tap.synced_versions_formulae,
                                                          T::Array[T::Array[String]])
  @tap_disabled_new_usr_local_relocation_formulae = T.let(tap.disabled_new_usr_local_relocation_formulae,
                                                          T::Array[String])
  @tap_autobump                                   = T.let(tap.autobump, T::Array[String])
  @tap_official                                   = T.let(tap.official?, T::Boolean)
  @problems                                       = T.let([], T::Array[T::Hash[Symbol, T.untyped]])
  @cask_tokens                                    = T.let([], T::Array[String])
  @formula_aliases                                = T.let([], T::Array[String])
  @formula_renames                                = T.let({}, T::Hash[String, String])
  @cask_renames                                   = T.let({}, T::Hash[String, String])
  @formula_names                                  = T.let([], T::Array[String])

  Homebrew.with_no_api_env do
    tap.clear_cache if Homebrew::EnvConfig.automatically_set_no_install_from_api?

    @formula_renames = tap.formula_renames
    @cask_renames    = tap.cask_renames
    @cask_tokens = tap.cask_tokens.map do |cask_token|
      Utils.name_from_full_name(cask_token)
    end
    @formula_aliases = tap.aliases.map do |formula_alias|
      Utils.name_from_full_name(formula_alias)
    end
    @formula_names = tap.formula_names.map do |formula_name|
      Utils.name_from_full_name(formula_name)
    end
  end
end

Instance Attribute Details

#cask_renamesHash{String => String} (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.

Returns:



28
29
30
# File 'tap_auditor.rb', line 28

def cask_renames
  @cask_renames
end

#cask_tokensArray<String> (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.

Returns:



25
26
27
# File 'tap_auditor.rb', line 25

def cask_tokens
  @cask_tokens
end

#formula_aliasesArray<String> (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.

Returns:



19
20
21
# File 'tap_auditor.rb', line 19

def formula_aliases
  @formula_aliases
end

#formula_namesArray<String> (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.

Returns:



16
17
18
# File 'tap_auditor.rb', line 16

def formula_names
  @formula_names
end

#formula_renamesHash{String => String} (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.

Returns:



22
23
24
# File 'tap_auditor.rb', line 22

def formula_renames
  @formula_renames
end

#nameString (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.

Returns:



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

def name
  @name
end

#pathPathname (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.

Returns:



13
14
15
# File 'tap_auditor.rb', line 13

def path
  @path
end

#problemsArray<Hash{Symbol => T.untyped}> (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.

Returns:



37
38
39
# File 'tap_auditor.rb', line 37

def problems
  @problems
end

#tap_audit_exceptionsHash{Symbol => T.untyped} (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.

Returns:



31
32
33
# File 'tap_auditor.rb', line 31

def tap_audit_exceptions
  @tap_audit_exceptions
end

#tap_style_exceptionsHash{Symbol => T.untyped} (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.

Returns:



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

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.



76
77
78
79
80
# File 'tap_auditor.rb', line 76

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.



105
106
107
108
109
110
# File 'tap_auditor.rb', line 105

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.



83
84
85
86
87
88
89
90
# File 'tap_auditor.rb', line 83

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.



93
94
95
96
97
98
99
100
101
102
# File 'tap_auditor.rb', line 93

def audit_tap_formula_lists
  check_formula_list_directory "audit_exceptions", @tap_audit_exceptions
  check_formula_list_directory "style_exceptions", @tap_style_exceptions
  check_renames "formula_renames.json", @formula_renames, @formula_names, @formula_aliases
  check_renames "cask_renames.json", @cask_renames, @cask_tokens
  check_formula_list ".github/autobump.txt", @tap_autobump unless @tap_official
  check_formula_list "synced_versions_formulae", @tap_synced_versions_formulae.flatten
  check_formula_list "disabled_new_usr_local_relocation_formulae.json",
                     @tap_disabled_new_usr_local_relocation_formulae
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:



113
114
115
# File 'tap_auditor.rb', line 113

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