From 5333037485d8fa88ddfa9ca7354fb55f6db299d6 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Fri, 1 Dec 2023 16:32:44 -0800 Subject: [PATCH] All the endless defs --- lib/yard-sorbet/directives.rb | 4 +--- lib/yard-sorbet/handlers/enums_handler.rb | 4 +--- .../handlers/mixes_in_class_methods_handler.rb | 4 +--- lib/yard-sorbet/handlers/sig_handler.rb | 6 ++---- lib/yard-sorbet/handlers/struct_prop_handler.rb | 12 +++--------- lib/yard-sorbet/node_utils.rb | 8 ++------ lib/yard-sorbet/tag_utils.rb | 4 +--- 7 files changed, 11 insertions(+), 31 deletions(-) diff --git a/lib/yard-sorbet/directives.rb b/lib/yard-sorbet/directives.rb index 1b4fa714..8146e510 100644 --- a/lib/yard-sorbet/directives.rb +++ b/lib/yard-sorbet/directives.rb @@ -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 diff --git a/lib/yard-sorbet/handlers/enums_handler.rb b/lib/yard-sorbet/handlers/enums_handler.rb index c3687997..78aff33e 100644 --- a/lib/yard-sorbet/handlers/enums_handler.rb +++ b/lib/yard-sorbet/handlers/enums_handler.rb @@ -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 diff --git a/lib/yard-sorbet/handlers/mixes_in_class_methods_handler.rb b/lib/yard-sorbet/handlers/mixes_in_class_methods_handler.rb index f4f0a18c..3e890f1a 100644 --- a/lib/yard-sorbet/handlers/mixes_in_class_methods_handler.rb +++ b/lib/yard-sorbet/handlers/mixes_in_class_methods_handler.rb @@ -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 diff --git a/lib/yard-sorbet/handlers/sig_handler.rb b/lib/yard-sorbet/handlers/sig_handler.rb index e05c9c7c..d30f317f 100644 --- a/lib/yard-sorbet/handlers/sig_handler.rb +++ b/lib/yard-sorbet/handlers/sig_handler.rb @@ -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) diff --git a/lib/yard-sorbet/handlers/struct_prop_handler.rb b/lib/yard-sorbet/handlers/struct_prop_handler.rb index a3050707..32cd1cf6 100644 --- a/lib/yard-sorbet/handlers/struct_prop_handler.rb +++ b/lib/yard-sorbet/handlers/struct_prop_handler.rb @@ -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) @@ -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 } diff --git a/lib/yard-sorbet/node_utils.rb b/lib/yard-sorbet/node_utils.rb index 89ddf304..633b4507 100644 --- a/lib/yard-sorbet/node_utils.rb +++ b/lib/yard-sorbet/node_utils.rb @@ -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 } @@ -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) diff --git a/lib/yard-sorbet/tag_utils.rb b/lib/yard-sorbet/tag_utils.rb index 7bff02e9..6c2da49f 100644 --- a/lib/yard-sorbet/tag_utils.rb +++ b/lib/yard-sorbet/tag_utils.rb @@ -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