docscribe 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +465 -130
- data/lib/docscribe/cli/check_for_comments.rb +183 -0
- data/lib/docscribe/cli/config_builder.rb +107 -53
- data/lib/docscribe/cli/formatters/json.rb +294 -0
- data/lib/docscribe/cli/formatters/sarif.rb +235 -0
- data/lib/docscribe/cli/formatters/text.rb +208 -0
- data/lib/docscribe/cli/formatters.rb +26 -0
- data/lib/docscribe/cli/generate.rb +45 -45
- data/lib/docscribe/cli/init.rb +14 -6
- data/lib/docscribe/cli/options.rb +190 -88
- data/lib/docscribe/cli/rbs_gen.rb +529 -0
- data/lib/docscribe/cli/run.rb +210 -152
- data/lib/docscribe/cli/sigs.rb +366 -0
- data/lib/docscribe/cli/update_types.rb +103 -0
- data/lib/docscribe/cli.rb +21 -13
- data/lib/docscribe/config/defaults.rb +5 -1
- data/lib/docscribe/config/emit.rb +17 -0
- data/lib/docscribe/config/filtering.rb +18 -25
- data/lib/docscribe/config/loader.rb +15 -11
- data/lib/docscribe/config/plugin.rb +1 -1
- data/lib/docscribe/config/rbs.rb +41 -9
- data/lib/docscribe/config/sorbet.rb +9 -12
- data/lib/docscribe/config/sorting.rb +1 -1
- data/lib/docscribe/config/template.rb +9 -1
- data/lib/docscribe/config/utils.rb +11 -9
- data/lib/docscribe/config.rb +2 -4
- data/lib/docscribe/infer/ast_walk.rb +1 -1
- data/lib/docscribe/infer/literals.rb +6 -11
- data/lib/docscribe/infer/names.rb +2 -3
- data/lib/docscribe/infer/params.rb +15 -17
- data/lib/docscribe/infer/raises.rb +3 -5
- data/lib/docscribe/infer/returns.rb +542 -140
- data/lib/docscribe/infer.rb +22 -23
- data/lib/docscribe/inline_rewriter/collector.rb +159 -164
- data/lib/docscribe/inline_rewriter/doc_block.rb +145 -115
- data/lib/docscribe/inline_rewriter/doc_builder.rb +1026 -723
- data/lib/docscribe/inline_rewriter/source_helpers.rb +49 -49
- data/lib/docscribe/inline_rewriter/tag_sorter.rb +82 -85
- data/lib/docscribe/inline_rewriter.rb +495 -492
- data/lib/docscribe/parsing.rb +29 -10
- data/lib/docscribe/plugin/base/collector_plugin.rb +2 -1
- data/lib/docscribe/plugin/base/tag_plugin.rb +0 -1
- data/lib/docscribe/plugin/context.rb +28 -18
- data/lib/docscribe/plugin/registry.rb +26 -27
- data/lib/docscribe/plugin/tag.rb +9 -14
- data/lib/docscribe/plugin.rb +17 -16
- data/lib/docscribe/types/provider_chain.rb +4 -2
- data/lib/docscribe/types/rbs/collection_loader.rb +2 -2
- data/lib/docscribe/types/rbs/provider.rb +60 -44
- data/lib/docscribe/types/rbs/type_formatter.rb +224 -83
- data/lib/docscribe/types/signature.rb +22 -42
- data/lib/docscribe/types/sorbet/base_provider.rb +24 -19
- data/lib/docscribe/types/sorbet/rbi_provider.rb +3 -3
- data/lib/docscribe/types/sorbet/source_provider.rb +3 -2
- data/lib/docscribe/types/yard/formatter.rb +100 -0
- data/lib/docscribe/types/yard/parser.rb +240 -0
- data/lib/docscribe/types/yard/types.rb +52 -0
- data/lib/docscribe/version.rb +1 -1
- metadata +33 -1
data/lib/docscribe/infer.rb
CHANGED
|
@@ -31,7 +31,7 @@ module Docscribe
|
|
|
31
31
|
class << self
|
|
32
32
|
# Infer exception classes raised or rescued within an AST node.
|
|
33
33
|
#
|
|
34
|
-
# @param [Parser::AST::Node] node
|
|
34
|
+
# @param [Parser::AST::Node] node constant AST node to resolve
|
|
35
35
|
# @return [Array<String>]
|
|
36
36
|
def infer_raises_from_node(node)
|
|
37
37
|
Raises.infer_raises_from_node(node)
|
|
@@ -47,9 +47,9 @@ module Docscribe
|
|
|
47
47
|
# - trailing `:` for keyword args
|
|
48
48
|
#
|
|
49
49
|
# @param [String] name internal parameter name representation
|
|
50
|
-
# @param [String
|
|
51
|
-
# @param [String] fallback_type
|
|
52
|
-
# @param [Boolean] treat_options_keyword_as_hash
|
|
50
|
+
# @param [String?] default_str source for the default expression
|
|
51
|
+
# @param [String] fallback_type default type when uncertain
|
|
52
|
+
# @param [Boolean] treat_options_keyword_as_hash treat options: as Hash
|
|
53
53
|
# @return [String]
|
|
54
54
|
def infer_param_type(name, default_str, fallback_type: FALLBACK_TYPE, treat_options_keyword_as_hash: true)
|
|
55
55
|
Params.infer_param_type(
|
|
@@ -62,7 +62,7 @@ module Docscribe
|
|
|
62
62
|
|
|
63
63
|
# Parse a standalone expression source string for inference helpers.
|
|
64
64
|
#
|
|
65
|
-
# @param [String
|
|
65
|
+
# @param [String?] src expression source to parse
|
|
66
66
|
# @return [Parser::AST::Node, nil]
|
|
67
67
|
def parse_expr(src)
|
|
68
68
|
Params.parse_expr(src)
|
|
@@ -70,7 +70,7 @@ module Docscribe
|
|
|
70
70
|
|
|
71
71
|
# Infer a return type from full method source.
|
|
72
72
|
#
|
|
73
|
-
# @param [String
|
|
73
|
+
# @param [String?] method_source method definition source
|
|
74
74
|
# @return [String]
|
|
75
75
|
def infer_return_type(method_source)
|
|
76
76
|
Returns.infer_return_type(method_source)
|
|
@@ -78,7 +78,7 @@ module Docscribe
|
|
|
78
78
|
|
|
79
79
|
# Infer a return type from an already parsed `:def` / `:defs` node.
|
|
80
80
|
#
|
|
81
|
-
# @param [Parser::AST::Node] node
|
|
81
|
+
# @param [Parser::AST::Node] node constant AST node to resolve
|
|
82
82
|
# @return [String]
|
|
83
83
|
def infer_return_type_from_node(node)
|
|
84
84
|
Returns.infer_return_type_from_node(node)
|
|
@@ -90,12 +90,12 @@ module Docscribe
|
|
|
90
90
|
# - `:normal` => the normal return type
|
|
91
91
|
# - `:rescues` => rescue-branch conditional return info
|
|
92
92
|
#
|
|
93
|
-
# @param [Parser::AST::Node] node
|
|
94
|
-
# @param [String] fallback_type
|
|
95
|
-
# @param [Boolean] nil_as_optional
|
|
96
|
-
# @param [
|
|
97
|
-
# @param [
|
|
98
|
-
# @return [Hash]
|
|
93
|
+
# @param [Parser::AST::Node] node constant AST node to resolve
|
|
94
|
+
# @param [String] fallback_type default type when uncertain
|
|
95
|
+
# @param [Boolean] nil_as_optional render nil as optional
|
|
96
|
+
# @param [Docscribe::Types::RBS::Provider?] core_rbs_provider core RBS type lookup provider
|
|
97
|
+
# @param [Hash<String, String>?] param_types parameter name -> type map
|
|
98
|
+
# @return [Hash<Symbol, String, Array<(Array<String>, String)>>]
|
|
99
99
|
def returns_spec_from_node(node, fallback_type: FALLBACK_TYPE, nil_as_optional: true, core_rbs_provider: nil,
|
|
100
100
|
param_types: nil)
|
|
101
101
|
Returns.returns_spec_from_node(
|
|
@@ -109,9 +109,9 @@ module Docscribe
|
|
|
109
109
|
|
|
110
110
|
# Infer the type of the last expression in an AST node.
|
|
111
111
|
#
|
|
112
|
-
# @param [Parser::AST::Node, nil] node
|
|
113
|
-
# @param [String] fallback_type
|
|
114
|
-
# @param [Boolean] nil_as_optional
|
|
112
|
+
# @param [Parser::AST::Node, nil] node constant AST node to resolve
|
|
113
|
+
# @param [String] fallback_type default type when uncertain
|
|
114
|
+
# @param [Boolean] nil_as_optional render nil as optional
|
|
115
115
|
# @return [String, nil]
|
|
116
116
|
def last_expr_type(node, fallback_type: FALLBACK_TYPE, nil_as_optional: true)
|
|
117
117
|
Returns.last_expr_type(
|
|
@@ -123,7 +123,6 @@ module Docscribe
|
|
|
123
123
|
|
|
124
124
|
# Convert a constant AST node into its fully qualified name.
|
|
125
125
|
#
|
|
126
|
-
# @param [Parser::AST::Node, nil] n
|
|
127
126
|
# @param [Parser::AST::Node, nil] node constant AST node to resolve
|
|
128
127
|
# @return [String, nil]
|
|
129
128
|
def const_full_name(node)
|
|
@@ -132,8 +131,8 @@ module Docscribe
|
|
|
132
131
|
|
|
133
132
|
# Infer a YARD-ish type string from a literal AST node.
|
|
134
133
|
#
|
|
135
|
-
# @param [Parser::AST::Node, nil] node
|
|
136
|
-
# @param [String] fallback_type
|
|
134
|
+
# @param [Parser::AST::Node, nil] node constant AST node to resolve
|
|
135
|
+
# @param [String] fallback_type default type when uncertain
|
|
137
136
|
# @return [String]
|
|
138
137
|
def type_from_literal(node, fallback_type: FALLBACK_TYPE)
|
|
139
138
|
Literals.type_from_literal(node, fallback_type: fallback_type)
|
|
@@ -141,10 +140,10 @@ module Docscribe
|
|
|
141
140
|
|
|
142
141
|
# Unify two inferred type strings conservatively.
|
|
143
142
|
#
|
|
144
|
-
# @param [String, nil] type_a
|
|
145
|
-
# @param [String, nil] type_b
|
|
146
|
-
# @param [String] fallback_type
|
|
147
|
-
# @param [Boolean] nil_as_optional
|
|
143
|
+
# @param [String, nil] type_a first type to unify
|
|
144
|
+
# @param [String, nil] type_b second type to unify
|
|
145
|
+
# @param [String] fallback_type default type when uncertain
|
|
146
|
+
# @param [Boolean] nil_as_optional render nil as optional
|
|
148
147
|
# @return [String]
|
|
149
148
|
def unify_types(type_a, type_b, fallback_type: FALLBACK_TYPE, nil_as_optional: true)
|
|
150
149
|
Returns.unify_types(
|