Fix Sorbet violations.

This commit is contained in:
Bo Anderson 2021-07-27 05:12:15 +01:00
parent a5ff1b0b2e
commit cee86846ce
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
6 changed files with 27 additions and 14 deletions

View File

@ -68,7 +68,7 @@ module Homebrew
def build_from_source_formulae
if build_from_source? || self[:HEAD?] || self[:build_bottle?]
named.to_formulae_and_casks.select { |f| f.is_a?(Formula) }.map(&:full_name)
named.to_formulae.map(&:full_name)
else
[]
end

View File

@ -36,7 +36,9 @@ module Homebrew
return
end
homepages = args.named.to_formulae_and_casks.map do |formula_or_cask|
# to_formulae_and_casks is typed to possibly return Kegs (but won't without explicitly asking)
formulae_or_casks = T.cast(args.named.to_formulae_and_casks, T::Array[T.any(Formula, Cask::Cask)])
homepages = formulae_or_casks.map do |formula_or_cask|
puts "Opening homepage for #{name_of(formula_or_cask)}"
formula_or_cask.homepage
end

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
# typed: true
# frozen_string_literal: true
require_relative "../warnings"
Warnings.ignore :parser_syntax do
@ -7,19 +7,21 @@ Warnings.ignore :parser_syntax do
end
module Homebrew
# Parlour type signature generator helper class for Homebrew.
module Parlour
extend T::Sig
ROOT_DIR = T.let(Pathname(__dir__).parent.realpath.freeze, Pathname)
ROOT_DIR = T.let(Pathname(__dir__).parent.realpath.freeze, Pathname).freeze
sig { returns(T::Array[Parser::AST::Node]) }
def self.ast_list
@@ast_list ||= begin
@ast_list ||= begin
ast_list = []
parser = Parser::CurrentRuby.new
prune_dirs = %w[sorbet shims test vendor].freeze
ROOT_DIR.find do |path|
Find.prune if path.directory? && %w[sorbet shims test vendor].any? { |subdir| path == ROOT_DIR/subdir }
Find.prune if path.directory? && prune_dirs.any? { |subdir| path == ROOT_DIR/subdir }
Find.prune if path.file? && path.extname != ".rb"

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
# typed: strict
# frozen_string_literal: true
# Parlour type signature generator plugin for Homebrew DSL attributes.
class Attr < Parlour::Plugin
sig { override.params(root: Parlour::RbiGenerator::Namespace).void }
def generate(root)
@ -13,7 +14,7 @@ class Attr < Parlour::Plugin
sig { override.returns(T.nilable(String)) }
def strictness
return "strict"
"strict"
end
private
@ -32,7 +33,7 @@ class Attr < Parlour::Plugin
traverse_module_name(node).join("::")
end
sig { params(node: Parser::AST::Node).returns(T::Array[T.untyped]) }
def find_custom_attr(node)
tree = T.let([], T::Array[T.untyped])
@ -46,15 +47,16 @@ class Attr < Parlour::Plugin
elsif node.type == :sclass
subtree = find_custom_attr(node.children[1])
return tree if subtree.empty?
tree << [:sclass, subtree]
elsif node.type == :class || node.type == :module
element = []
if node.type == :class
case node.type
when :class
element << :class
element << extract_module_name(children.shift)
element << extract_module_name(children.shift)
elsif node.type == :module
when :module
element << :module
element << extract_module_name(children.shift)
end
@ -69,7 +71,7 @@ class Attr < Parlour::Plugin
tree << element
elsif node.type == :send && children.shift.nil?
method_name = children.shift
if method_name == :attr_rw || method_name == :attr_predicate
if [:attr_rw, :attr_predicate].include?(method_name)
children.each do |name_node|
tree << [method_name, name_node.children.first.to_s]
end
@ -96,7 +98,7 @@ class Attr < Parlour::Plugin
name = node.shift
name = "self.#{name}" if sclass
namespace.create_method(name, parameters: [
Parlour::RbiGenerator::Parameter.new("arg", type: "T.untyped", default: "T.unsafe(nil)")
Parlour::RbiGenerator::Parameter.new("arg", type: "T.untyped", default: "T.unsafe(nil)"),
], return_type: "T.untyped")
when :attr_predicate
name = node.shift

View File

@ -39,6 +39,7 @@ class Version
when /\A#{PostToken::PATTERN}\z/o then PostToken
when /\A#{NumericToken::PATTERN}\z/o then NumericToken
when /\A#{StringToken::PATTERN}\z/o then StringToken
else raise "Cannot find a matching token pattern"
end.new(val)
end

View File

@ -0,0 +1,6 @@
# typed: strict
module YARD
class Docstring; end
class DocstringParser; end
end