diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index dca88f384e..c6667c3386 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -47,11 +47,6 @@ Cask/StanzaOrder: Description: "Ensure that cask stanzas are sorted correctly. More info at https://docs.brew.sh/Cask-Cookbook#stanza-order" Enabled: true -# This was intended to be an abstract Cop class for Homebrew formulae, but rubocop doesn't know that. -# TODO: refactor this as a module for formulae Cop classes to include instead -FormulaCop: - Enabled: false - # enable all formulae audits FormulaAudit: Enabled: true diff --git a/Library/Homebrew/rubocops/all.rb b/Library/Homebrew/rubocops/all.rb index 86cb5ab8e0..faad0fa2ba 100644 --- a/Library/Homebrew/rubocops/all.rb +++ b/Library/Homebrew/rubocops/all.rb @@ -13,29 +13,30 @@ Warnings.ignore :parser_syntax do end require_relative "io_read" +require_relative "move_to_extend_os" require_relative "shell_commands" -require_relative "platform" -require_relative "formula_desc" -require_relative "components_order" -require_relative "components_redundancy" -require_relative "dependency_order" -require_relative "homepage" -require_relative "text" +# formula audit cops +require_relative "bottle" require_relative "caveats" require_relative "checksum" -require_relative "patches" +require_relative "class" +require_relative "components_order" +require_relative "components_redundancy" require_relative "conflicts" -require_relative "options" -require_relative "urls" +require_relative "dependency_order" +require_relative "deprecate_disable" +require_relative "desc" +require_relative "files" +require_relative "homepage" +require_relative "keg_only" require_relative "lines" require_relative "livecheck" -require_relative "class" +require_relative "options" +require_relative "patches" +require_relative "text" +require_relative "urls" require_relative "uses_from_macos" -require_relative "files" -require_relative "keg_only" require_relative "version" -require_relative "deprecate_disable" -require_relative "bottle" require_relative "rubocop-cask" diff --git a/Library/Homebrew/rubocops/bottle.rb b/Library/Homebrew/rubocops/bottle.rb index fd69556cb6..1477d233ad 100644 --- a/Library/Homebrew/rubocops/bottle.rb +++ b/Library/Homebrew/rubocops/bottle.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -9,7 +9,8 @@ module RuboCop # This cop audits the `bottle` block in formulae. # # @api private - class BottleFormat < FormulaCop + class BottleFormat < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -56,7 +57,8 @@ module RuboCop # This cop audits the indentation of the bottle tags in the `bottle` block in formulae. # # @api private - class BottleTagIndentation < FormulaCop + class BottleTagIndentation < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -92,7 +94,8 @@ module RuboCop # This cop audits the indentation of the sha256 digests in the`bottle` block in formulae. # # @api private - class BottleDigestIndentation < FormulaCop + class BottleDigestIndentation < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -128,7 +131,8 @@ module RuboCop # This cop audits the order of the `bottle` block in formulae. # # @api private - class BottleOrder < FormulaCop + class BottleOrder < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) diff --git a/Library/Homebrew/rubocops/caveats.rb b/Library/Homebrew/rubocops/caveats.rb index 105a9796d4..1028ae2ad7 100644 --- a/Library/Homebrew/rubocops/caveats.rb +++ b/Library/Homebrew/rubocops/caveats.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -24,7 +24,9 @@ module RuboCop # end # # @api private - class Caveats < FormulaCop + class Caveats < Base + include FormulaCop + def audit_formula(_node, _class_node, _parent_class_node, _body_node) caveats_strings.each do |n| if regex_match_group(n, /\bsetuid\b/i) diff --git a/Library/Homebrew/rubocops/checksum.rb b/Library/Homebrew/rubocops/checksum.rb index e8035b8ee3..22842cacff 100644 --- a/Library/Homebrew/rubocops/checksum.rb +++ b/Library/Homebrew/rubocops/checksum.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -9,7 +9,9 @@ module RuboCop # This cop makes sure that deprecated checksums are not used. # # @api private - class Checksum < FormulaCop + class Checksum < Base + include FormulaCop + def audit_formula(_node, _class_node, _parent_class_node, body_node) return if body_node.nil? @@ -45,7 +47,8 @@ module RuboCop # This cop makes sure that checksum strings are lowercase. # # @api private - class ChecksumCase < FormulaCop + class ChecksumCase < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) diff --git a/Library/Homebrew/rubocops/class.rb b/Library/Homebrew/rubocops/class.rb index 4ed2192b04..d9133bd546 100644 --- a/Library/Homebrew/rubocops/class.rb +++ b/Library/Homebrew/rubocops/class.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -9,7 +9,8 @@ module RuboCop # This cop makes sure that {Formula} is used as superclass. # # @api private - class ClassName < FormulaCop + class ClassName < Base + include FormulaCop extend AutoCorrector DEPRECATED_CLASSES = %w[ @@ -31,7 +32,8 @@ module RuboCop # This cop makes sure that a `test` block contains a proper test. # # @api private - class Test < FormulaCop + class Test < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -74,7 +76,8 @@ module RuboCop # This cop makes sure that a `test` block exists. # # @api private - class TestPresent < FormulaCop + class TestPresent < Base + include FormulaCop def audit_formula(_node, class_node, _parent_class_node, body_node) return if find_block(body_node, :test) diff --git a/Library/Homebrew/rubocops/components_order.rb b/Library/Homebrew/rubocops/components_order.rb index 7a59d6acdb..a7aee8b60f 100644 --- a/Library/Homebrew/rubocops/components_order.rb +++ b/Library/Homebrew/rubocops/components_order.rb @@ -2,7 +2,7 @@ # frozen_string_literal: true require "ast_constants" -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -11,7 +11,8 @@ module RuboCop # # - `component_precedence_list` has component hierarchy in a nested list # where each sub array contains components' details which are at same precedence level - class ComponentsOrder < FormulaCop + class ComponentsOrder < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) diff --git a/Library/Homebrew/rubocops/components_redundancy.rb b/Library/Homebrew/rubocops/components_redundancy.rb index cf2067a701..f33ccb03a8 100644 --- a/Library/Homebrew/rubocops/components_redundancy.rb +++ b/Library/Homebrew/rubocops/components_redundancy.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -14,7 +14,9 @@ module RuboCop # - `stable do` should not be present without a `head` spec # # @api private - class ComponentsRedundancy < FormulaCop + class ComponentsRedundancy < Base + include FormulaCop + HEAD_MSG = "`head` and `head do` should not be simultaneously present" BOTTLE_MSG = "`bottle :modifier` and `bottle do` should not be simultaneously present" STABLE_MSG = "`stable do` should not be present without a `head` spec" diff --git a/Library/Homebrew/rubocops/conflicts.rb b/Library/Homebrew/rubocops/conflicts.rb index 411ba92e5c..46ed8ab814 100644 --- a/Library/Homebrew/rubocops/conflicts.rb +++ b/Library/Homebrew/rubocops/conflicts.rb @@ -1,13 +1,14 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop module FormulaAudit # This cop audits versioned formulae for `conflicts_with`. - class Conflicts < FormulaCop + class Conflicts < Base + include FormulaCop extend AutoCorrector MSG = "Versioned formulae should not use `conflicts_with`. " \ diff --git a/Library/Homebrew/rubocops/dependency_order.rb b/Library/Homebrew/rubocops/dependency_order.rb index d5660d5635..7b077f889c 100644 --- a/Library/Homebrew/rubocops/dependency_order.rb +++ b/Library/Homebrew/rubocops/dependency_order.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -10,7 +10,8 @@ module RuboCop # # precedence order: # build-time > test > normal > recommended > optional - class DependencyOrder < FormulaCop + class DependencyOrder < Base + include FormulaCop extend T::Sig extend AutoCorrector diff --git a/Library/Homebrew/rubocops/deprecate_disable.rb b/Library/Homebrew/rubocops/deprecate_disable.rb index 53c714123a..6ed42e3cef 100644 --- a/Library/Homebrew/rubocops/deprecate_disable.rb +++ b/Library/Homebrew/rubocops/deprecate_disable.rb @@ -1,13 +1,14 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop module FormulaAudit # This cop audits `deprecate!` and `disable!` dates. - class DeprecateDisableDate < FormulaCop + class DeprecateDisableDate < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -34,7 +35,8 @@ module RuboCop end # This cop audits `deprecate!` and `disable!` reasons. - class DeprecateDisableReason < FormulaCop + class DeprecateDisableReason < Base + include FormulaCop extend AutoCorrector PUNCTUATION_MARKS = %w[. ! ?].freeze diff --git a/Library/Homebrew/rubocops/formula_desc.rb b/Library/Homebrew/rubocops/desc.rb similarity index 87% rename from Library/Homebrew/rubocops/formula_desc.rb rename to Library/Homebrew/rubocops/desc.rb index 0093e752e1..d9f9bdd85f 100644 --- a/Library/Homebrew/rubocops/formula_desc.rb +++ b/Library/Homebrew/rubocops/desc.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" require "rubocops/shared/desc_helper" module RuboCop @@ -9,7 +9,8 @@ module RuboCop module FormulaAudit # This cop audits `desc` in formulae. # See the {DescHelper} module for details of the checks. - class Desc < FormulaCop + class Desc < Base + include FormulaCop include DescHelper extend AutoCorrector diff --git a/Library/Homebrew/rubocops/extend/formula.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb similarity index 97% rename from Library/Homebrew/rubocops/extend/formula.rb rename to Library/Homebrew/rubocops/extend/formula_cop.rb index 33359bd114..efdfc03615 100644 --- a/Library/Homebrew/rubocops/extend/formula.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -5,10 +5,11 @@ require "rubocops/shared/helper_functions" module RuboCop module Cop - # Superclass for all formula cops. + # Mixin for all formula cops. # # @api private - class FormulaCop < Base + module FormulaCop + extend RuboCop::AST::NodePattern::Macros include RangeHelp include HelperFunctions @@ -67,11 +68,7 @@ module RuboCop # Returns true if given dependency name and dependency type exist in given dependency method call node. # TODO: Add case where key of hash is an array def depends_on_name_type?(node, name = nil, type = :required) - name_match = if name - false - else - true # Match only by type when name is nil - end + name_match = !name # Match only by type when name is nil case type when :required diff --git a/Library/Homebrew/rubocops/files.rb b/Library/Homebrew/rubocops/files.rb index 63d3d7566a..88add54f23 100644 --- a/Library/Homebrew/rubocops/files.rb +++ b/Library/Homebrew/rubocops/files.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -9,7 +9,9 @@ module RuboCop # This cop makes sure that a formula's file permissions are correct. # # @api private - class Files < FormulaCop + class Files < Base + include FormulaCop + def audit_formula(node, _class_node, _parent_class_node, _body_node) return unless file_path diff --git a/Library/Homebrew/rubocops/homepage.rb b/Library/Homebrew/rubocops/homepage.rb index bae5437105..11df64a0f5 100644 --- a/Library/Homebrew/rubocops/homepage.rb +++ b/Library/Homebrew/rubocops/homepage.rb @@ -1,13 +1,14 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop module FormulaAudit # This cop audits the `homepage` URL in formulae. - class Homepage < FormulaCop + class Homepage < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, class_node, _parent_class_node, body_node) diff --git a/Library/Homebrew/rubocops/keg_only.rb b/Library/Homebrew/rubocops/keg_only.rb index ea2bd9131d..ea9df1a8ff 100644 --- a/Library/Homebrew/rubocops/keg_only.rb +++ b/Library/Homebrew/rubocops/keg_only.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -9,7 +9,8 @@ module RuboCop # This cop makes sure that a `keg_only` reason has the correct format. # # @api private - class KegOnly < FormulaCop + class KegOnly < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index c7538f8834..cb51711f76 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -2,7 +2,7 @@ # frozen_string_literal: true require "macos_versions" -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" require "rubocops/shared/on_system_conditionals_helper" module RuboCop @@ -11,7 +11,8 @@ module RuboCop # This cop checks for various miscellaneous Homebrew coding styles. # # @api private - class Lines < FormulaCop + class Lines < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, _body_node) [:automake, :ant, :autoconf, :emacs, :expat, :libtool, :mysql, :perl, :postgresql, :python, :python3, :rbenv, :ruby].each do |dependency| @@ -34,7 +35,8 @@ module RuboCop # This cop makes sure that a space is used for class inheritance. # # @api private - class ClassInheritance < FormulaCop + class ClassInheritance < Base + include FormulaCop def audit_formula(_node, class_node, parent_class_node, _body_node) begin_pos = start_column(parent_class_node) end_pos = end_column(class_node) @@ -48,7 +50,8 @@ module RuboCop # This cop makes sure that template comments are removed. # # @api private - class Comments < FormulaCop + class Comments < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, _body_node) audit_comments do |comment| [ @@ -89,7 +92,8 @@ module RuboCop # This cop makes sure that idiomatic `assert_*` statements are used. # # @api private - class AssertStatements < FormulaCop + class AssertStatements < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) return if body_node.nil? @@ -116,7 +120,8 @@ module RuboCop # This cop makes sure that `option`s are used idiomatically. # # @api private - class OptionDeclarations < FormulaCop + class OptionDeclarations < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) return if body_node.nil? @@ -201,7 +206,8 @@ module RuboCop # This cop makes sure that formulae depend on `open-mpi` instead of `mpich`. # # @api private - class MpiCheck < FormulaCop + class MpiCheck < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -223,7 +229,8 @@ module RuboCop # or run-time. # # @api private - class PyoxidizerCheck < FormulaCop + class PyoxidizerCheck < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) return if body_node.nil? @@ -250,7 +257,8 @@ module RuboCop # This cop makes sure that the safe versions of `popen_*` calls are used. # # @api private - class SafePopenCommands < FormulaCop + class SafePopenCommands < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -281,7 +289,8 @@ module RuboCop # This cop makes sure that environment variables are passed correctly to `popen_*` calls. # # @api private - class ShellVariables < FormulaCop + class ShellVariables < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -313,7 +322,8 @@ module RuboCop # This cop makes sure that `license` has the correct format. # # @api private - class LicenseArrays < FormulaCop + class LicenseArrays < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -334,7 +344,8 @@ module RuboCop # This cop makes sure that nested `license` declarations are split onto multiple lines. # # @api private - class Licenses < FormulaCop + class Licenses < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) return if body_node.nil? @@ -357,7 +368,8 @@ module RuboCop # This cop makes sure that Python versions are consistent. # # @api private - class PythonVersions < FormulaCop + class PythonVersions < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -395,7 +407,8 @@ module RuboCop # This cop makes sure that OS conditionals are consistent. # # @api private - class OnSystemConditionals < FormulaCop + class OnSystemConditionals < Base + include FormulaCop include OnSystemConditionalsHelper extend AutoCorrector @@ -436,7 +449,8 @@ module RuboCop # This cop makes sure that the `generate_completions_from_executable` DSL is used. # # @api private - class GenerateCompletionsDSL < FormulaCop + class GenerateCompletionsDSL < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -519,7 +533,8 @@ module RuboCop # a single, combined call for all shells. # # @api private - class SingleGenerateCompletionsDSLCall < FormulaCop + class SingleGenerateCompletionsDSLCall < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -581,7 +596,8 @@ module RuboCop # This cop checks for other miscellaneous style violations. # # @api private - class Miscellaneous < FormulaCop + class Miscellaneous < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) return if body_node.nil? @@ -852,7 +868,8 @@ module RuboCop # This cop makes sure that no build-time checks are performed. # # @api private - class MakeCheck < FormulaCop + class MakeCheck < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) return if formula_tap != "homebrew-core" @@ -876,7 +893,8 @@ module RuboCop end # This cop ensures that new formulae depending on removed Requirements are not used - class Requirements < FormulaCop + class Requirements < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, _body_node) problem "Formulae should depend on a versioned `openjdk` instead of :java" if depends_on? :java problem "Formulae should depend on specific X libraries instead of :x11" if depends_on? :x11 diff --git a/Library/Homebrew/rubocops/livecheck.rb b/Library/Homebrew/rubocops/livecheck.rb index 8ff8122f90..9efff5f820 100644 --- a/Library/Homebrew/rubocops/livecheck.rb +++ b/Library/Homebrew/rubocops/livecheck.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -10,7 +10,8 @@ module RuboCop # skipped formulae. # # @api private - class LivecheckSkip < FormulaCop + class LivecheckSkip < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -42,7 +43,8 @@ module RuboCop # This cop ensures that a `url` is specified in the `livecheck` block. # # @api private - class LivecheckUrlProvided < FormulaCop + class LivecheckUrlProvided < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) livecheck_node = find_block(body_node, :livecheck) return if livecheck_node.blank? @@ -66,7 +68,8 @@ module RuboCop # is used when the livecheck `url` is identical to one of these formula URLs. # # @api private - class LivecheckUrlSymbol < FormulaCop + class LivecheckUrlSymbol < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -123,7 +126,8 @@ module RuboCop # This cop ensures that the `regex` call in the `livecheck` block uses parentheses. # # @api private - class LivecheckRegexParentheses < FormulaCop + class LivecheckRegexParentheses < Base + include FormulaCop extend AutoCorrector def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -150,7 +154,8 @@ module RuboCop # `\.tgz`, `\.tar.gz` and variants. # # @api private - class LivecheckRegexExtension < FormulaCop + class LivecheckRegexExtension < Base + include FormulaCop extend AutoCorrector TAR_PATTERN = /\\?\.t(ar|(g|l|x)z$|[bz2]{2,4}$)(\\?\.((g|l|x)z)|[bz2]{2,4}|Z)?$/i.freeze @@ -183,7 +188,8 @@ module RuboCop # in the `livecheck` block. # # @api private - class LivecheckRegexIfPageMatch < FormulaCop + class LivecheckRegexIfPageMatch < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) livecheck_node = find_block(body_node, :livecheck) return if livecheck_node.blank? @@ -209,7 +215,8 @@ module RuboCop # unless sensitivity is explicitly required for proper matching. # # @api private - class LivecheckRegexCaseInsensitive < FormulaCop + class LivecheckRegexCaseInsensitive < Base + include FormulaCop extend AutoCorrector MSG = "Regexes should be case-insensitive unless sensitivity is explicitly required for proper matching." diff --git a/Library/Homebrew/rubocops/platform.rb b/Library/Homebrew/rubocops/move_to_extend_os.rb similarity index 100% rename from Library/Homebrew/rubocops/platform.rb rename to Library/Homebrew/rubocops/move_to_extend_os.rb diff --git a/Library/Homebrew/rubocops/options.rb b/Library/Homebrew/rubocops/options.rb index 817399e05b..deda466eea 100644 --- a/Library/Homebrew/rubocops/options.rb +++ b/Library/Homebrew/rubocops/options.rb @@ -1,13 +1,14 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop module FormulaAudit # This cop audits `option`s in formulae. - class Options < FormulaCop + class Options < Base + include FormulaCop DEPRECATION_MSG = "macOS has been 64-bit only since 10.6 so 32-bit options are deprecated." UNI_DEPRECATION_MSG = "macOS has been 64-bit only since 10.6 so universal options are deprecated." diff --git a/Library/Homebrew/rubocops/patches.rb b/Library/Homebrew/rubocops/patches.rb index e16c370686..30328df4f0 100644 --- a/Library/Homebrew/rubocops/patches.rb +++ b/Library/Homebrew/rubocops/patches.rb @@ -1,14 +1,15 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop module FormulaAudit # This cop audits `patch`es in formulae. # TODO: Many of these could be auto-corrected. - class Patches < FormulaCop + class Patches < Base + include FormulaCop extend T::Sig extend AutoCorrector diff --git a/Library/Homebrew/rubocops/text.rb b/Library/Homebrew/rubocops/text.rb index 11f7f67cf0..36523ede81 100644 --- a/Library/Homebrew/rubocops/text.rb +++ b/Library/Homebrew/rubocops/text.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -9,7 +9,8 @@ module RuboCop # This cop checks for various problems in a formula's source code. # # @api private - class Text < FormulaCop + class Text < Base + include FormulaCop extend AutoCorrector def audit_formula(node, _class_node, _parent_class_node, body_node) @@ -106,7 +107,8 @@ module RuboCop # This cop contains stricter checks for various problems in a formula's source code. # # @api private - class Text < FormulaCop + class Text < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) return if body_node.nil? diff --git a/Library/Homebrew/rubocops/urls.rb b/Library/Homebrew/rubocops/urls.rb index a2e66b55c7..a78990408b 100644 --- a/Library/Homebrew/rubocops/urls.rb +++ b/Library/Homebrew/rubocops/urls.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -9,7 +9,9 @@ module RuboCop # This cop audits `url`s and `mirror`s in formulae. # # @api private - class Urls < FormulaCop + class Urls < Base + include FormulaCop + def audit_formula(_node, _class_node, _parent_class_node, body_node) return if body_node.nil? @@ -260,7 +262,8 @@ module RuboCop # This cop makes sure that the correct format for PyPI URLs is used. # # @api private - class PyPiUrls < FormulaCop + class PyPiUrls < Base + include FormulaCop extend T::Sig def audit_formula(_node, _class_node, _parent_class_node, body_node) @@ -294,7 +297,8 @@ module RuboCop # This cop makes sure that git URLs have a `revision`. # # @api private - class GitUrls < FormulaCop + class GitUrls < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) return if body_node.nil? return unless formula_tap == "homebrew-core" @@ -318,7 +322,8 @@ module RuboCop # This cop makes sure that git URLs have a `tag`. # # @api private - class GitUrls < FormulaCop + class GitUrls < Base + include FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) return if body_node.nil? return unless formula_tap == "homebrew-core" diff --git a/Library/Homebrew/rubocops/uses_from_macos.rb b/Library/Homebrew/rubocops/uses_from_macos.rb index 62b9f325d7..a0fdc54ca3 100644 --- a/Library/Homebrew/rubocops/uses_from_macos.rb +++ b/Library/Homebrew/rubocops/uses_from_macos.rb @@ -1,13 +1,15 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop module FormulaAudit # This cop audits formulae that are keg-only because they are provided by macos. - class ProvidedByMacos < FormulaCop + class ProvidedByMacos < Base + include FormulaCop + PROVIDED_BY_MACOS_FORMULAE = %w[ apr bc @@ -73,7 +75,9 @@ module RuboCop end # This cop audits `uses_from_macos` dependencies in formulae. - class UsesFromMacos < FormulaCop + class UsesFromMacos < Base + include FormulaCop + # These formulae aren't `keg_only :provided_by_macos` but are provided by # macOS (or very similarly, e.g. OpenSSL where system provides LibreSSL). # TODO: consider making some of these keg-only. diff --git a/Library/Homebrew/rubocops/version.rb b/Library/Homebrew/rubocops/version.rb index a6afb74449..bf803b68e1 100644 --- a/Library/Homebrew/rubocops/version.rb +++ b/Library/Homebrew/rubocops/version.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require "rubocops/extend/formula" +require "rubocops/extend/formula_cop" module RuboCop module Cop @@ -9,7 +9,9 @@ module RuboCop # This cop makes sure that a `version` is in the correct format. # # @api private - class Version < FormulaCop + class Version < Base + include FormulaCop + def audit_formula(_node, _class_node, _parent_class_node, body_node) version_node = find_node_method_by_name(body_node, :version) return unless version_node diff --git a/Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi b/Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi index beb2a2a897..926c0a9f61 100644 --- a/Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi +++ b/Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi @@ -6963,7 +6963,7 @@ class RuboCop::Cop::FormulaAuditStrict::Text def share_path_starts_with(param0, param1); end end -class RuboCop::Cop::FormulaCop +module RuboCop::Cop::FormulaCop def dependency_name_hash_match?(param0, param1); end def dependency_type_hash_match?(param0, param1); end diff --git a/Library/Homebrew/test/rubocops/formula_desc_spec.rb b/Library/Homebrew/test/rubocops/desc_spec.rb similarity index 99% rename from Library/Homebrew/test/rubocops/formula_desc_spec.rb rename to Library/Homebrew/test/rubocops/desc_spec.rb index f1548f3173..392508ce83 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_spec.rb +++ b/Library/Homebrew/test/rubocops/desc_spec.rb @@ -1,7 +1,7 @@ # typed: false # frozen_string_literal: true -require "rubocops/formula_desc" +require "rubocops/desc" describe RuboCop::Cop::FormulaAudit::Desc do subject(:cop) { described_class.new } diff --git a/Library/Homebrew/test/rubocops/platform_spec.rb b/Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb similarity index 93% rename from Library/Homebrew/test/rubocops/platform_spec.rb rename to Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb index 4e8872c077..e49b1d2d03 100644 --- a/Library/Homebrew/test/rubocops/platform_spec.rb +++ b/Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb @@ -1,7 +1,7 @@ # typed: false # frozen_string_literal: true -require "rubocops/platform" +require "rubocops/move_to_extend_os" describe RuboCop::Cop::Homebrew::MoveToExtendOS do subject(:cop) { described_class.new }