docscribe 1.4.1 → 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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +588 -104
  3. data/lib/docscribe/cli/check_for_comments.rb +183 -0
  4. data/lib/docscribe/cli/config_builder.rb +180 -36
  5. data/lib/docscribe/cli/formatters/json.rb +294 -0
  6. data/lib/docscribe/cli/formatters/sarif.rb +235 -0
  7. data/lib/docscribe/cli/formatters/text.rb +208 -0
  8. data/lib/docscribe/cli/formatters.rb +26 -0
  9. data/lib/docscribe/cli/generate.rb +296 -125
  10. data/lib/docscribe/cli/init.rb +58 -14
  11. data/lib/docscribe/cli/options.rb +410 -133
  12. data/lib/docscribe/cli/rbs_gen.rb +529 -0
  13. data/lib/docscribe/cli/run.rb +503 -189
  14. data/lib/docscribe/cli/sigs.rb +366 -0
  15. data/lib/docscribe/cli/update_types.rb +103 -0
  16. data/lib/docscribe/cli.rb +35 -9
  17. data/lib/docscribe/config/defaults.rb +16 -12
  18. data/lib/docscribe/config/emit.rb +18 -0
  19. data/lib/docscribe/config/filtering.rb +37 -31
  20. data/lib/docscribe/config/loader.rb +20 -13
  21. data/lib/docscribe/config/plugin.rb +2 -1
  22. data/lib/docscribe/config/rbs.rb +68 -27
  23. data/lib/docscribe/config/sorbet.rb +40 -17
  24. data/lib/docscribe/config/sorting.rb +2 -1
  25. data/lib/docscribe/config/template.rb +10 -1
  26. data/lib/docscribe/config/utils.rb +12 -9
  27. data/lib/docscribe/config.rb +3 -4
  28. data/lib/docscribe/infer/ast_walk.rb +1 -1
  29. data/lib/docscribe/infer/constants.rb +15 -0
  30. data/lib/docscribe/infer/literals.rb +39 -26
  31. data/lib/docscribe/infer/names.rb +24 -16
  32. data/lib/docscribe/infer/params.rb +57 -13
  33. data/lib/docscribe/infer/raises.rb +23 -15
  34. data/lib/docscribe/infer/returns.rb +784 -199
  35. data/lib/docscribe/infer.rb +28 -28
  36. data/lib/docscribe/inline_rewriter/collector.rb +816 -430
  37. data/lib/docscribe/inline_rewriter/doc_block.rb +323 -150
  38. data/lib/docscribe/inline_rewriter/doc_builder.rb +1837 -648
  39. data/lib/docscribe/inline_rewriter/source_helpers.rb +119 -71
  40. data/lib/docscribe/inline_rewriter/tag_sorter.rb +165 -107
  41. data/lib/docscribe/inline_rewriter.rb +1144 -727
  42. data/lib/docscribe/parsing.rb +29 -10
  43. data/lib/docscribe/plugin/base/collector_plugin.rb +3 -3
  44. data/lib/docscribe/plugin/base/tag_plugin.rb +1 -2
  45. data/lib/docscribe/plugin/context.rb +28 -18
  46. data/lib/docscribe/plugin/registry.rb +49 -23
  47. data/lib/docscribe/plugin/tag.rb +9 -14
  48. data/lib/docscribe/plugin.rb +54 -22
  49. data/lib/docscribe/types/provider_chain.rb +4 -2
  50. data/lib/docscribe/types/rbs/collection_loader.rb +2 -3
  51. data/lib/docscribe/types/rbs/provider.rb +127 -62
  52. data/lib/docscribe/types/rbs/type_formatter.rb +286 -77
  53. data/lib/docscribe/types/signature.rb +22 -42
  54. data/lib/docscribe/types/sorbet/base_provider.rb +51 -27
  55. data/lib/docscribe/types/sorbet/rbi_provider.rb +3 -3
  56. data/lib/docscribe/types/sorbet/source_provider.rb +3 -2
  57. data/lib/docscribe/types/yard/formatter.rb +100 -0
  58. data/lib/docscribe/types/yard/parser.rb +240 -0
  59. data/lib/docscribe/types/yard/types.rb +52 -0
  60. data/lib/docscribe/version.rb +1 -1
  61. metadata +34 -2
@@ -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, nil] default_str source for the default expression
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, nil] src
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, nil] method_source
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 [nil] core_rbs_provider Param documentation.
97
- # @param [nil] param_types Param documentation.
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,16 +123,16 @@ 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
126
+ # @param [Parser::AST::Node, nil] node constant AST node to resolve
127
127
  # @return [String, nil]
128
- def const_full_name(n)
129
- Names.const_full_name(n)
128
+ def const_full_name(node)
129
+ Names.const_full_name(node)
130
130
  end
131
131
 
132
132
  # Infer a YARD-ish type string from a literal AST node.
133
133
  #
134
- # @param [Parser::AST::Node, nil] node
135
- # @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
136
136
  # @return [String]
137
137
  def type_from_literal(node, fallback_type: FALLBACK_TYPE)
138
138
  Literals.type_from_literal(node, fallback_type: fallback_type)
@@ -140,15 +140,15 @@ module Docscribe
140
140
 
141
141
  # Unify two inferred type strings conservatively.
142
142
  #
143
- # @param [String, nil] a
144
- # @param [String, nil] b
145
- # @param [String] fallback_type
146
- # @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
147
147
  # @return [String]
148
- def unify_types(a, b, fallback_type: FALLBACK_TYPE, nil_as_optional: true)
148
+ def unify_types(type_a, type_b, fallback_type: FALLBACK_TYPE, nil_as_optional: true)
149
149
  Returns.unify_types(
150
- a,
151
- b,
150
+ type_a,
151
+ type_b,
152
152
  fallback_type: fallback_type,
153
153
  nil_as_optional: nil_as_optional
154
154
  )