Skip to content

Commit

Permalink
livecheck: finish expanding typed: strict
Browse files Browse the repository at this point in the history
I previously expanded use of `typed: strict` in livecheck files but
the exception was `livecheck/strategy.rb`. This addresses the
`@strategies` type errors in that file and upgrades it to
`typed: strict`.

This also updates `rubocops/livecheck.rb`, so all of the livecheck
files use `typed: strict`.

Co-authored-by: apainintheneck <[email protected]>
  • Loading branch information
samford and apainintheneck committed Jul 7, 2024
1 parent 8c4c731 commit d8a4b02
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
12 changes: 4 additions & 8 deletions Library/Homebrew/livecheck/strategy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module Homebrew
Expand Down Expand Up @@ -97,17 +97,13 @@ module Strategy
# @return [Hash]
sig { returns(T::Hash[Symbol, T.untyped]) }
def strategies
return @strategies if defined? @strategies

@strategies = {}
Strategy.constants.sort.each do |const_symbol|
@strategies ||= T.let(Strategy.constants.sort.each_with_object({}) do |const_symbol, hash|
constant = Strategy.const_get(const_symbol)
next unless constant.is_a?(Class)

key = Utils.underscore(const_symbol).to_sym
@strategies[key] = constant
end
@strategies
hash[key] = constant
end, T.nilable(T::Hash[Symbol, T.untyped]))
end
private_class_method :strategies

Expand Down
58 changes: 57 additions & 1 deletion Library/Homebrew/rubocops/livecheck.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "rubocops/extend/formula_cop"
Expand All @@ -11,6 +11,14 @@ module FormulaAudit
class LivecheckSkip < FormulaCop
extend AutoCorrector

sig {
override.params(
_node: RuboCop::AST::ClassNode,
_class_node: RuboCop::AST::ConstNode,
_parent_class_node: RuboCop::AST::ConstNode,
body_node: RuboCop::AST::Node,
).void
}
def audit_formula(_node, _class_node, _parent_class_node, body_node)
livecheck_node = find_block(body_node, :livecheck)
return if livecheck_node.blank?
Expand Down Expand Up @@ -39,6 +47,14 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)

# This cop ensures that a `url` is specified in the `livecheck` block.
class LivecheckUrlProvided < FormulaCop
sig {
override.params(
_node: RuboCop::AST::ClassNode,
_class_node: RuboCop::AST::ConstNode,
_parent_class_node: RuboCop::AST::ConstNode,
body_node: RuboCop::AST::Node,
).void
}
def audit_formula(_node, _class_node, _parent_class_node, body_node)
livecheck_node = find_block(body_node, :livecheck)
return unless livecheck_node
Expand All @@ -62,6 +78,14 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
class LivecheckUrlSymbol < FormulaCop
extend AutoCorrector

sig {
override.params(
_node: RuboCop::AST::ClassNode,
_class_node: RuboCop::AST::ConstNode,
_parent_class_node: RuboCop::AST::ConstNode,
body_node: RuboCop::AST::Node,
).void
}
def audit_formula(_node, _class_node, _parent_class_node, body_node)
livecheck_node = find_block(body_node, :livecheck)
return if livecheck_node.blank?
Expand Down Expand Up @@ -117,6 +141,14 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
class LivecheckRegexParentheses < FormulaCop
extend AutoCorrector

sig {
override.params(
_node: RuboCop::AST::ClassNode,
_class_node: RuboCop::AST::ConstNode,
_parent_class_node: RuboCop::AST::ConstNode,
body_node: RuboCop::AST::Node,
).void
}
def audit_formula(_node, _class_node, _parent_class_node, body_node)
livecheck_node = find_block(body_node, :livecheck)
return if livecheck_node.blank?
Expand Down Expand Up @@ -144,6 +176,14 @@ class LivecheckRegexExtension < FormulaCop

TAR_PATTERN = /\\?\.t(ar|(g|l|x)z$|[bz2]{2,4}$)(\\?\.((g|l|x)z)|[bz2]{2,4}|Z)?$/i

sig {
override.params(
_node: RuboCop::AST::ClassNode,
_class_node: RuboCop::AST::ConstNode,
_parent_class_node: RuboCop::AST::ConstNode,
body_node: RuboCop::AST::Node,
).void
}
def audit_formula(_node, _class_node, _parent_class_node, body_node)
livecheck_node = find_block(body_node, :livecheck)
return if livecheck_node.blank?
Expand Down Expand Up @@ -171,6 +211,14 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
# This cop ensures that a `regex` is provided when `strategy :page_match` is specified
# in the `livecheck` block.
class LivecheckRegexIfPageMatch < FormulaCop
sig {
override.params(
_node: RuboCop::AST::ClassNode,
_class_node: RuboCop::AST::ConstNode,
_parent_class_node: RuboCop::AST::ConstNode,
body_node: RuboCop::AST::Node,
).void
}
def audit_formula(_node, _class_node, _parent_class_node, body_node)
livecheck_node = find_block(body_node, :livecheck)
return if livecheck_node.blank?
Expand Down Expand Up @@ -199,6 +247,14 @@ class LivecheckRegexCaseInsensitive < FormulaCop

MSG = "Regexes should be case-insensitive unless sensitivity is explicitly required for proper matching."

sig {
override.params(
_node: RuboCop::AST::ClassNode,
_class_node: RuboCop::AST::ConstNode,
_parent_class_node: RuboCop::AST::ConstNode,
body_node: RuboCop::AST::Node,
).void
}
def audit_formula(_node, _class_node, _parent_class_node, body_node)
return if tap_style_exception? :regex_case_sensitive_allowlist

Expand Down

0 comments on commit d8a4b02

Please sign in to comment.