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.
- checksums.yaml +4 -4
- data/README.md +588 -104
- data/lib/docscribe/cli/check_for_comments.rb +183 -0
- data/lib/docscribe/cli/config_builder.rb +180 -36
- 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 +296 -125
- data/lib/docscribe/cli/init.rb +58 -14
- data/lib/docscribe/cli/options.rb +410 -133
- data/lib/docscribe/cli/rbs_gen.rb +529 -0
- data/lib/docscribe/cli/run.rb +503 -189
- data/lib/docscribe/cli/sigs.rb +366 -0
- data/lib/docscribe/cli/update_types.rb +103 -0
- data/lib/docscribe/cli.rb +35 -9
- data/lib/docscribe/config/defaults.rb +16 -12
- data/lib/docscribe/config/emit.rb +18 -0
- data/lib/docscribe/config/filtering.rb +37 -31
- data/lib/docscribe/config/loader.rb +20 -13
- data/lib/docscribe/config/plugin.rb +2 -1
- data/lib/docscribe/config/rbs.rb +68 -27
- data/lib/docscribe/config/sorbet.rb +40 -17
- data/lib/docscribe/config/sorting.rb +2 -1
- data/lib/docscribe/config/template.rb +10 -1
- data/lib/docscribe/config/utils.rb +12 -9
- data/lib/docscribe/config.rb +3 -4
- data/lib/docscribe/infer/ast_walk.rb +1 -1
- data/lib/docscribe/infer/constants.rb +15 -0
- data/lib/docscribe/infer/literals.rb +39 -26
- data/lib/docscribe/infer/names.rb +24 -16
- data/lib/docscribe/infer/params.rb +57 -13
- data/lib/docscribe/infer/raises.rb +23 -15
- data/lib/docscribe/infer/returns.rb +784 -199
- data/lib/docscribe/infer.rb +28 -28
- data/lib/docscribe/inline_rewriter/collector.rb +816 -430
- data/lib/docscribe/inline_rewriter/doc_block.rb +323 -150
- data/lib/docscribe/inline_rewriter/doc_builder.rb +1837 -648
- data/lib/docscribe/inline_rewriter/source_helpers.rb +119 -71
- data/lib/docscribe/inline_rewriter/tag_sorter.rb +165 -107
- data/lib/docscribe/inline_rewriter.rb +1144 -727
- data/lib/docscribe/parsing.rb +29 -10
- data/lib/docscribe/plugin/base/collector_plugin.rb +3 -3
- data/lib/docscribe/plugin/base/tag_plugin.rb +1 -2
- data/lib/docscribe/plugin/context.rb +28 -18
- data/lib/docscribe/plugin/registry.rb +49 -23
- data/lib/docscribe/plugin/tag.rb +9 -14
- data/lib/docscribe/plugin.rb +54 -22
- data/lib/docscribe/types/provider_chain.rb +4 -2
- data/lib/docscribe/types/rbs/collection_loader.rb +2 -3
- data/lib/docscribe/types/rbs/provider.rb +127 -62
- data/lib/docscribe/types/rbs/type_formatter.rb +286 -77
- data/lib/docscribe/types/signature.rb +22 -42
- data/lib/docscribe/types/sorbet/base_provider.rb +51 -27
- 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 +34 -2
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Docscribe
|
|
4
|
+
module CLI
|
|
5
|
+
module Formatters
|
|
6
|
+
# Text output formatter preserving the original CLI output format.
|
|
7
|
+
class Text
|
|
8
|
+
# Format and print check summary.
|
|
9
|
+
#
|
|
10
|
+
# @param [Docscribe::CLI::Formatters::state] state formatter state hash
|
|
11
|
+
# @param [Docscribe::CLI::Formatters::opts] options runtime options hash
|
|
12
|
+
# @return [void]
|
|
13
|
+
def format_check_summary(state:, options:)
|
|
14
|
+
puts
|
|
15
|
+
format_fail_paths(state, options)
|
|
16
|
+
format_check_status_line(state)
|
|
17
|
+
format_type_mismatch_paths(state, options)
|
|
18
|
+
format_error_paths(state)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Format and print write summary.
|
|
22
|
+
#
|
|
23
|
+
# @param [Docscribe::CLI::Formatters::state] state formatter state hash
|
|
24
|
+
# @param [Docscribe::CLI::Formatters::opts] options runtime options hash
|
|
25
|
+
# @return [void]
|
|
26
|
+
def format_write_summary(state:, options:)
|
|
27
|
+
puts
|
|
28
|
+
puts "Docscribe: updated #{state[:corrected]} file(s)" if state[:corrected].positive?
|
|
29
|
+
format_corrected_paths(state, options)
|
|
30
|
+
|
|
31
|
+
return unless state[:had_errors]
|
|
32
|
+
|
|
33
|
+
warn "Docscribe: #{state[:error_paths].size} file(s) had errors"
|
|
34
|
+
format_error_paths(state)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Print files needing updates.
|
|
38
|
+
#
|
|
39
|
+
# @param [Docscribe::CLI::Formatters::state] state formatter state hash
|
|
40
|
+
# @param [Docscribe::CLI::Formatters::opts] options runtime options hash
|
|
41
|
+
# @return [void]
|
|
42
|
+
def format_fail_paths(state, options)
|
|
43
|
+
state[:fail_paths].each do |p|
|
|
44
|
+
puts "Would update: #{p}"
|
|
45
|
+
|
|
46
|
+
next if options[:verbose] || options[:quiet]
|
|
47
|
+
|
|
48
|
+
Array(state[:fail_changes][p]).each do |change|
|
|
49
|
+
puts " - #{format_change_reason(change)}"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Print check status line.
|
|
55
|
+
#
|
|
56
|
+
# @param [Docscribe::CLI::Formatters::state] state formatter state hash
|
|
57
|
+
# @return [void]
|
|
58
|
+
def format_check_status_line(state)
|
|
59
|
+
checked_error = state[:error_paths].size
|
|
60
|
+
type_mismatch_count = state[:type_mismatch_paths].size
|
|
61
|
+
|
|
62
|
+
if all_fine?(state, checked_error, type_mismatch_count)
|
|
63
|
+
puts "Docscribe: OK (#{state[:checked_ok]} files checked)"
|
|
64
|
+
elsif mismatch_only?(state, checked_error)
|
|
65
|
+
puts "Docscribe: OK (#{state[:checked_ok]} files checked, #{type_mismatch_count} with type mismatches)"
|
|
66
|
+
else
|
|
67
|
+
puts failure_line(state, type_mismatch_count, checked_error)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Print type mismatch warnings.
|
|
72
|
+
#
|
|
73
|
+
# @param [Docscribe::CLI::Formatters::state] state formatter state hash
|
|
74
|
+
# @param [Docscribe::CLI::Formatters::opts] options runtime options hash
|
|
75
|
+
# @return [void]
|
|
76
|
+
def format_type_mismatch_paths(state, options)
|
|
77
|
+
return if options[:quiet]
|
|
78
|
+
return unless options[:verbose] || options[:explain]
|
|
79
|
+
|
|
80
|
+
state[:type_mismatch_paths].each do |p|
|
|
81
|
+
warn "Type mismatches: #{p}"
|
|
82
|
+
Array(state[:type_mismatch_changes][p]).each do |change|
|
|
83
|
+
warn " - #{format_change_reason(change)}"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Print updated file paths.
|
|
89
|
+
#
|
|
90
|
+
# @param [Docscribe::CLI::Formatters::state] state formatter state hash
|
|
91
|
+
# @param [Docscribe::CLI::Formatters::opts] options runtime options hash
|
|
92
|
+
# @return [void]
|
|
93
|
+
def format_corrected_paths(state, options)
|
|
94
|
+
state[:corrected_paths].each do |p|
|
|
95
|
+
puts "Updated: #{p}"
|
|
96
|
+
|
|
97
|
+
next if options[:verbose] || options[:quiet]
|
|
98
|
+
|
|
99
|
+
Array(state[:corrected_changes][p]).each do |change|
|
|
100
|
+
puts " - #{format_change_reason(change)}"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Print error file messages.
|
|
106
|
+
#
|
|
107
|
+
# @param [Docscribe::CLI::Formatters::state] state formatter state hash
|
|
108
|
+
# @return [void]
|
|
109
|
+
def format_error_paths(state)
|
|
110
|
+
return if state[:error_paths].empty?
|
|
111
|
+
|
|
112
|
+
warn ''
|
|
113
|
+
state[:error_paths].each do |p|
|
|
114
|
+
warn "Error processing: #{p}"
|
|
115
|
+
warn " #{state[:error_messages][p]}" if state[:error_messages][p]
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
private
|
|
120
|
+
|
|
121
|
+
# Check if all files passed.
|
|
122
|
+
#
|
|
123
|
+
# @private
|
|
124
|
+
# @param [Docscribe::CLI::Formatters::state] state formatter state hash
|
|
125
|
+
# @param [Integer] checked_error count of error files
|
|
126
|
+
# @param [Integer] type_mismatch_count count of type mismatches
|
|
127
|
+
# @return [Boolean]
|
|
128
|
+
def all_fine?(state, checked_error, type_mismatch_count)
|
|
129
|
+
state[:checked_fail].zero? && checked_error.zero? && type_mismatch_count.zero?
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Check only type mismatches.
|
|
133
|
+
#
|
|
134
|
+
# @private
|
|
135
|
+
# @param [Docscribe::CLI::Formatters::state] state formatter state hash
|
|
136
|
+
# @param [Integer] checked_error count of error files
|
|
137
|
+
# @return [Boolean]
|
|
138
|
+
def mismatch_only?(state, checked_error)
|
|
139
|
+
state[:checked_fail].zero? && checked_error.zero?
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Build failure status line.
|
|
143
|
+
#
|
|
144
|
+
# @private
|
|
145
|
+
# @param [Docscribe::CLI::Formatters::state] state formatter state hash
|
|
146
|
+
# @param [Integer] type_mismatch_count count of type mismatches
|
|
147
|
+
# @param [Integer] checked_error count of error files
|
|
148
|
+
# @return [String]
|
|
149
|
+
def failure_line(state, type_mismatch_count, checked_error)
|
|
150
|
+
parts = ["#{state[:checked_fail]} need updates"]
|
|
151
|
+
parts << "#{type_mismatch_count} type mismatches" if type_mismatch_count.positive?
|
|
152
|
+
parts << "#{checked_error} errors"
|
|
153
|
+
parts << "#{state[:checked_ok]} ok"
|
|
154
|
+
"Docscribe: FAILED (#{parts.join(', ')})"
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Format change reason string.
|
|
158
|
+
#
|
|
159
|
+
# @private
|
|
160
|
+
# @param [Docscribe::CLI::Formatters::change] change change info hash
|
|
161
|
+
# @return [String]
|
|
162
|
+
def format_change_reason(change)
|
|
163
|
+
line = change_line_suffix(change)
|
|
164
|
+
method = change_method_suffix(change)
|
|
165
|
+
|
|
166
|
+
return "unsorted tags#{line}" if change[:type] == :unsorted_tags
|
|
167
|
+
return "#{change[:message]}#{method}#{line}" if direct_message_change?(change)
|
|
168
|
+
|
|
169
|
+
"#{change[:message] || change[:type].to_s.tr('_', ' ')}#{method}#{line}"
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Build change line suffix.
|
|
173
|
+
#
|
|
174
|
+
# @private
|
|
175
|
+
# @param [Docscribe::CLI::Formatters::change] change change info hash
|
|
176
|
+
# @return [String]
|
|
177
|
+
def change_line_suffix(change)
|
|
178
|
+
change[:line] ? " at line #{change[:line]}" : ''
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# Build change method suffix.
|
|
182
|
+
#
|
|
183
|
+
# @private
|
|
184
|
+
# @param [Docscribe::CLI::Formatters::change] change change info hash
|
|
185
|
+
# @return [String]
|
|
186
|
+
def change_method_suffix(change)
|
|
187
|
+
change[:method] ? " for #{change[:method]}" : ''
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Check direct message type.
|
|
191
|
+
#
|
|
192
|
+
# @private
|
|
193
|
+
# @param [Docscribe::CLI::Formatters::change] change change info hash
|
|
194
|
+
# @return [Boolean]
|
|
195
|
+
def direct_message_change?(change)
|
|
196
|
+
%i[
|
|
197
|
+
missing_param
|
|
198
|
+
missing_return
|
|
199
|
+
missing_raise
|
|
200
|
+
missing_visibility
|
|
201
|
+
missing_module_function_note
|
|
202
|
+
insert_full_doc_block
|
|
203
|
+
].include?(change[:type])
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Docscribe
|
|
4
|
+
module CLI
|
|
5
|
+
# Factory for output formatters.
|
|
6
|
+
module Formatters
|
|
7
|
+
# Select formatter by format type.
|
|
8
|
+
#
|
|
9
|
+
# @param [Docscribe::CLI::Formatters::format] format output format symbol
|
|
10
|
+
# @raise [ArgumentError]
|
|
11
|
+
# @return [Docscribe::CLI::Formatters::Text, Docscribe::CLI::Formatters::Json, Docscribe::CLI::Formatters::Sarif]
|
|
12
|
+
def self.for(format)
|
|
13
|
+
case format
|
|
14
|
+
when :text then Text.new
|
|
15
|
+
when :json then Json.new
|
|
16
|
+
when :sarif then Sarif.new
|
|
17
|
+
else raise ArgumentError, "Unknown format: #{format}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
require_relative 'formatters/text'
|
|
25
|
+
require_relative 'formatters/json'
|
|
26
|
+
require_relative 'formatters/sarif'
|