Skip to content

Commit

Permalink
All the endless defs
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Dec 4, 2023
1 parent 216535c commit 5333037
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 31 deletions.
4 changes: 1 addition & 3 deletions lib/yard-sorbet/directives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def self.extract_directives(docstring)
end

sig { params(docstring: String, directives: T::Array[String]).void }
def self.add_directives(docstring, directives)
directives.each { docstring.concat("\n#{_1}") }
end
def self.add_directives(docstring, directives) = directives.each { docstring.concat("\n#{_1}") }
end
end
4 changes: 1 addition & 3 deletions lib/yard-sorbet/handlers/enums_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ def process
private

sig { params(node: YARD::Parser::Ruby::AstNode).returns(T::Boolean) }
def const_assign_node?(node)
node.type == :assign && node[0][0].type == :const
end
def const_assign_node?(node) = node.type == :assign && node[0][0].type == :const
end
end
end
4 changes: 1 addition & 3 deletions lib/yard-sorbet/handlers/mixes_in_class_methods_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ class MixesInClassMethodsHandler < YARD::Handlers::Ruby::Base
@@mix_in_class_methods = T.let({}, T::Hash[String, T::Array[String]]) # rubocop:disable Style/ClassVars

sig { params(code_obj: String).returns(T.nilable(T::Array[String])) }
def self.mixed_in_class_methods(code_obj)
@@mix_in_class_methods[code_obj]
end
def self.mixed_in_class_methods(code_obj) = @@mix_in_class_methods[code_obj]

sig { void }
def process
Expand Down
6 changes: 2 additions & 4 deletions lib/yard-sorbet/handlers/sig_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ def merged_into_attr?(attr_node)
attrs = namespace.attributes[scope][names[0]]
return false if attrs.nil? || attrs.empty?

document_attr_methods(attrs.values.compact)
document_attrs(attrs.values.compact)
attr_node.docstring = nil
true
end

sig { params(method_objects: T::Array[YARD::CodeObjects::MethodObject]).void }
def document_attr_methods(method_objects)
method_objects.each { parse_node(_1, _1.docstring, include_params: false) }
end
def document_attrs(method_objects) = method_objects.each { parse_node(_1, _1.docstring, include_params: false) }

sig { params(attach_to: Documentable, docstring: T.nilable(String), include_params: T::Boolean).void }
def parse_node(attach_to, docstring, include_params: true)
Expand Down
12 changes: 3 additions & 9 deletions lib/yard-sorbet/handlers/struct_prop_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ def decorate_object(object, prop)
end

sig { returns(T::Boolean) }
def immutable?
statement.method_name(true) == :const || kw_arg('immutable:') == 'true'
end
def immutable? = statement.method_name(true) == :const || kw_arg('immutable:') == 'true'

# @return the value passed to the keyword argument, or nil
sig { params(kwd: String).returns(T.nilable(String)) }
def kw_arg(kwd)
params[2]&.find { _1[0].source == kwd }&.[](1)&.source
end
def kw_arg(kwd) = params[2]&.find { _1[0].source == kwd }&.[](1)&.source

sig { params(name: String).returns(TStructProp) }
def make_prop(name)
Expand All @@ -57,9 +53,7 @@ def make_prop(name)
end

sig { returns(T::Array[YARD::Parser::Ruby::AstNode]) }
def params
@params ||= T.let(statement.parameters(false), T.nilable(T::Array[YARD::Parser::Ruby::AstNode]))
end
def params = @params ||= T.let(statement.parameters(false), T.nilable(T::Array[YARD::Parser::Ruby::AstNode]))

# Register the field explicitly as an attribute.
sig { params(object: YARD::CodeObjects::MethodObject, name: String).void }
Expand Down
8 changes: 2 additions & 6 deletions lib/yard-sorbet/node_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def self.bfs_traverse(node, &_blk)
end

sig { params(node: YARD::Parser::Ruby::AstNode).void }
def self.delete_node(node)
node.parent.children.delete(node)
end
def self.delete_node(node) = node.parent.children.delete(node)

# Enqueue the eligible children of a node in the BFS queue
sig { params(queue: Queue, node: YARD::Parser::Ruby::AstNode).void }
Expand All @@ -47,9 +45,7 @@ def self.enque_children(queue, node)

# Gets the node that a sorbet `sig` can be attached do, bypassing visisbility modifiers and the like
sig { params(node: YARD::Parser::Ruby::AstNode).returns(SigableNode) }
def self.get_method_node(node)
sigable_node?(node) ? node : node.jump(:def, :defs)
end
def self.get_method_node(node) = sigable_node?(node) ? node : node.jump(:def, :defs)

# Find and return the adjacent node (ascending)
# @raise [IndexError] if the node does not have an adjacent sibling (ascending)
Expand Down
4 changes: 1 addition & 3 deletions lib/yard-sorbet/tag_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ module TagUtils
sig do
params(docstring: YARD::Docstring, tag_name: String, name: T.nilable(String)).returns(T.nilable(YARD::Tags::Tag))
end
def self.find_tag(docstring, tag_name, name)
docstring.tags.find { _1.tag_name == tag_name && _1.name == name }
end
def self.find_tag(docstring, tag_name, name) = docstring.tags.find { _1.tag_name == tag_name && _1.name == name }

# Create or update a `YARD` tag with type information
sig do
Expand Down

0 comments on commit 5333037

Please sign in to comment.