yard-junk 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2e9b802aa1bb3391b0962165574b75f10e05cad
4
- data.tar.gz: 6b279f93f06feb8ea1c10595d10cc8661f7bcc8d
3
+ metadata.gz: fcf20dc05e2b7b8cccc8928add0ccfb1a3645534
4
+ data.tar.gz: a1f0da93aeebcc2b82eb9bb303649cbd4ffc0928
5
5
  SHA512:
6
- metadata.gz: 381f8c03346812eef369dabc6548c675aef0c309f7cd08b767c0e3603ef1267f08b589acb994789f410039601108aa7cd3de46b42f3e8fc539d683a28b50975b
7
- data.tar.gz: d9c65f218d51d23bb573671f9e89c62497bbed28063487a06ede45a1e1d97abd54dd5311e095d2944936d665ef86471dd0f1b385279906a17e5d7be9316a874a
6
+ metadata.gz: 96e3d2ca3814151e8ea7cfc68aeb32edd0a2ab13b7ed4008eb0b50091a6dcedd14668fbd5d05a56f7a1e151399551a33c442dc7d3921f9b95543ffd256d09412
7
+ data.tar.gz: 0e599b6a5101aec233c921443a5a9778cb6b7037513075517e134d0b946be52de9bbd0b31682ad6cef48b18b1509d4a7d5459b1f8c09c4ec0272e2212dd1b5fe
data/Changelog.md ADDED
@@ -0,0 +1,12 @@
1
+ # Yard-Junk changelog
2
+
3
+ ## 0.0.2 -- 2017-09-03
4
+
5
+ * Lots of small cleanups and enchancement of README, Gemfile and directory structure ([@olleolleolle]);
6
+ * Colorized text output ([@olleolleolle]);
7
+ * HTML reporter;
8
+ * Options for command line and Rake task.
9
+
10
+ ## 0.0.1 -- 2017-08-27
11
+
12
+ Yard-Junk was born (Even RubyWeekly [#364](http://rubyweekly.com/issues/364) noticed!)
data/README.md CHANGED
@@ -12,7 +12,205 @@ Yard-Junk is [yard](https://github.com/lsegal/yard) plugin/patch, that provides:
12
12
 
13
13
  Let's generate the docs for the [rom](https://github.com/rom-rb/rom) library.
14
14
 
15
- Output of `yard doc` without JunkYard: [too huge to embed in README](https://gist.github.com/zverok/6dcf946d674e63545cee9f8a74e08728).
15
+ <details><summary>Output of `yard doc` without JunkYard</summary>
16
+
17
+ ```
18
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Types
19
+ in file 'core/lib/rom/types.rb':9:
20
+
21
+ 9: include Dry::Types.module
22
+
23
+ [warn]: Invalid tag format for @example in file `core/lib/rom/global.rb` near line 41
24
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Schema
25
+ in file 'core/lib/rom/schema.rb':66:
26
+
27
+ 66: include Dry::Equalizer(:name, :attributes, :associations)
28
+
29
+ [warn]: @param tag has unknown parameter name:
30
+ in file `core/lib/rom/schema.rb' near line 149
31
+ [warn]: @param tag has unknown parameter name:
32
+ in file `core/lib/rom/schema.rb' near line 305
33
+ [warn]: @param tag has unknown parameter name:
34
+ in file `core/lib/rom/schema.rb' near line 316
35
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Command
36
+ in file 'core/lib/rom/command.rb':30:
37
+
38
+ 30: include Dry::Equalizer(:relation, :options)
39
+
40
+ [warn]: @param tag has unknown parameter name: Transaction
41
+ in file `core/lib/rom/gateway.rb' near line 176
42
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Pipeline::Composite
43
+ in file 'core/lib/rom/pipeline.rb':82:
44
+
45
+ 82: include Dry::Equalizer(:left, :right)
46
+
47
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Registry
48
+ in file 'core/lib/rom/registry.rb':13:
49
+
50
+ 13: include Dry::Equalizer(:elements)
51
+
52
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Relation
53
+ in file 'core/lib/rom/relation.rb':129:
54
+
55
+ 129: include Dry::Equalizer(:name, :dataset)
56
+
57
+ [warn]: @param tag has unknown parameter name: options
58
+ in file `core/lib/rom/relation.rb' near line 302
59
+ [warn]: @param tag has unknown parameter name: new_options
60
+ in file `core/lib/rom/relation.rb' near line 411
61
+ [warn]: @param tag has unknown parameter name: klass
62
+ in file `core/lib/rom/relation.rb' near line 529
63
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Attribute
64
+ in file 'core/lib/rom/attribute.rb':17:
65
+
66
+ 17: include Dry::Equalizer(:type, :options)
67
+
68
+ [warn]: @param tag has unknown parameter name:
69
+ in file `core/lib/rom/attribute.rb' near line 344
70
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Container
71
+ in file 'core/lib/rom/container.rb':101:
72
+
73
+ 101: include Dry::Equalizer(:gateways, :relations, :mappers, :commands)
74
+
75
+ [warn]: @param tag has unknown parameter name: base
76
+ in file `core/lib/rom/plugin_base.rb' near line 41
77
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Commands::Lazy
78
+ in file 'core/lib/rom/commands/lazy.rb':10:
79
+
80
+ 10: include Dry::Equalizer(:command, :evaluator)
81
+
82
+ [warn]: @param tag has unknown parameter name: The
83
+ in file `core/lib/rom/configuration.rb' near line 50
84
+ [warn]: @param tag has unknown parameter name: Plugin
85
+ in file `core/lib/rom/configuration.rb' near line 50
86
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Relation::Name
87
+ in file 'core/lib/rom/relation/name.rb':17:
88
+
89
+ 17: include Dry::Equalizer(:relation, :dataset)
90
+
91
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Commands::Graph
92
+ in file 'core/lib/rom/commands/graph.rb':12:
93
+
94
+ 12: include Dry::Equalizer(:root, :nodes)
95
+
96
+ [warn]: @param tag has unknown parameter name: names
97
+ in file `core/lib/rom/memory/dataset.rb' near line 61
98
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Relation::Graph
99
+ in file 'core/lib/rom/relation/graph.rb':29:
100
+
101
+ 29: include Dry::Equalizer(:root, :nodes)
102
+
103
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::PluginRegistryBase
104
+ in file 'core/lib/rom/plugin_registry.rb':88:
105
+
106
+ 88: include Dry::Equalizer(:elements, :plugin_type)
107
+
108
+ [warn]: Unknown tag @raises in file `core/lib/rom/plugin_registry.rb` near line 143
109
+ [warn]: Unknown tag @raises in file `core/lib/rom/plugin_registry.rb` near line 190
110
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Relation::Loaded
111
+ in file 'core/lib/rom/relation/loaded.rb':12:
112
+
113
+ 12: include Dry::Equalizer(:source, :collection)
114
+
115
+ [warn]: Unknown tag @raises in file `core/lib/rom/relation/loaded.rb` near line 94
116
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Schema::Inferrer
117
+ in file 'core/lib/rom/schema/inferrer.rb':27:
118
+
119
+ 27: include Dry::Equalizer(:options)
120
+
121
+ [warn]: @param tag has unknown parameter name: name
122
+ in file `core/lib/rom/command_registry.rb' near line 57
123
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Relation::Curried
124
+ in file 'core/lib/rom/relation/curried.rb':22:
125
+
126
+ 22: include Dry::Equalizer(:relation, :options)
127
+
128
+ [warn]: Unknown tag @raises in file `core/lib/rom/relation/curried.rb` near line 72
129
+ [warn]: @param tag has unknown parameter name: adapter
130
+ in file `core/lib/rom/global/plugin_dsl.rb' near line 42
131
+ [warn]: @param tag has unknown parameter name:
132
+ in file `core/lib/rom/relation/combined.rb' near line 33
133
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Associations::Abstract
134
+ in file 'core/lib/rom/associations/abstract.rb':17:
135
+
136
+ 17: include Dry::Equalizer(:definition, :source, :target)
137
+
138
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Notifications::Event
139
+ in file 'core/lib/rom/support/notifications.rb':75:
140
+
141
+ 75: include Dry::Equalizer(:id, :payload)
142
+
143
+ [warn]: @param tag has unknown parameter name: command
144
+ in file `core/lib/rom/commands/class_interface.rb' near line 86
145
+ [warn]: @param tag has unknown parameter name: parent
146
+ in file `core/lib/rom/commands/class_interface.rb' near line 86
147
+ [warn]: @param tag has unknown parameter name: options
148
+ in file `core/lib/rom/commands/class_interface.rb' near line 112
149
+ [warn]: @param tag has unknown parameter name:
150
+ in file `core/lib/rom/commands/class_interface.rb' near line 123
151
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Commands::Graph::InputEvaluator
152
+ in file 'core/lib/rom/commands/graph/input_evaluator.rb':5:
153
+
154
+ 5: include Dry::Equalizer(:tuple_path, :excluded_keys)
155
+
156
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Associations::Definitions::Abstract
157
+ in file 'core/lib/rom/associations/definitions/abstract.rb':16:
158
+
159
+ 16: include Dry::Equalizer(:source, :target, :result)
160
+
161
+ [warn]: @param tag has unknown parameter name: options
162
+ in file `core/lib/rom/associations/definitions/abstract.rb' near line 74
163
+ [warn]: @param tag has unknown parameter name: options
164
+ in file `changeset/lib/rom/changeset.rb' near line 84
165
+ [warn]: in YARD::Handlers::Ruby::ClassHandler: Undocumentable superclass (class was added without superclass)
166
+ in file 'changeset/lib/rom/changeset/pipe.rb':28:
167
+
168
+ 28: class Pipe < Transproc::Transformer[PipeRegistry]
169
+
170
+ [warn]: @param tag has unknown parameter name: assoc
171
+ in file `changeset/lib/rom/changeset/stateful.rb' near line 222
172
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Header
173
+ in file 'mapper/lib/rom/header.rb':12:
174
+
175
+ 12: include Dry::Equalizer(:attributes, :model)
176
+
177
+ [warn]: @param tag has unknown parameter name: model
178
+ in file `mapper/lib/rom/header.rb' near line 52
179
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Mapper
180
+ in file 'mapper/lib/rom/mapper.rb':11:
181
+
182
+ 11: include Dry::Equalizer(:transformers, :header)
183
+
184
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Header::Attribute
185
+ in file 'mapper/lib/rom/header/attribute.rb':14:
186
+
187
+ 14: include Dry::Equalizer(:name, :key, :type)
188
+
189
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Header::Embedded
190
+ in file 'mapper/lib/rom/header/attribute.rb':110:
191
+
192
+ 110: include Dry::Equalizer(:name, :key, :type, :header)
193
+
194
+ [warn]: @param tag has unknown parameter name:
195
+ in file `mapper/lib/rom/processor/transproc.rb' near line 215
196
+ [warn]: in YARD::Handlers::Ruby::MixinHandler: Undocumentable mixin: YARD::Parser::UndocumentableError for class ROM::Session
197
+ in file 'repository/lib/rom/repository/session.rb':8:
198
+
199
+ 8: include Dry::Equalizer(:queue, :status)
200
+
201
+ [warn]: The proxy Coercible has not yet been recognized.
202
+ If this class/method is part of your source tree, this will affect your documentation results.
203
+ You can correct this issue by loading the source file for this object before `core/lib/rom/types.rb'
204
+
205
+ [warn]: The proxy Coercible has not yet been recognized.
206
+ If this class/method is part of your source tree, this will affect your documentation results.
207
+ You can correct this issue by loading the source file for this object before `core/lib/rom/types.rb'
208
+
209
+ [warn]: The proxy Coercible has not yet been recognized.
210
+ If this class/method is part of your source tree, this will affect your documentation results.
211
+ You can correct this issue by loading the source file for this object before `core/lib/rom/types.rb'
212
+ ```
213
+ </details>
16
214
 
17
215
  Things to notice:
18
216
 
@@ -24,7 +222,7 @@ Things to notice:
24
222
  * verbose and not very informative errors (look at that "Undocumentable mixin" -- and then grep
25
223
  for "The proxy Coercible has not yet been recognized." and compare).
26
224
 
27
- Output of `yard doc` with Yard-Junk:
225
+ <details><summary>Output of `yard doc` with Yard-Junk</summary>
28
226
 
29
227
  ```
30
228
  core/lib/rom/global.rb:40: [InvalidTagFormat] Invalid tag format for @example
@@ -60,6 +258,7 @@ core/lib/rom/types.rb:1: [UnknownNamespace] namespace Coercible is not recognize
60
258
  core/lib/rom/types.rb:1: [UnknownNamespace] namespace Coercible is not recognized
61
259
  core/lib/rom/types.rb:1: [UnknownNamespace] namespace Coercible is not recognized
62
260
  ```
261
+ </details>
63
262
 
64
263
  Things to notice:
65
264
 
@@ -74,7 +273,7 @@ Unknown tag @raises. Did you mean @raise?
74
273
  ```
75
274
  * Rephrased and cleaned up messages.
76
275
 
77
- `yard-junk` tool output:
276
+ <details><summary>`yard-junk` tool output</summary>
78
277
 
79
278
  ```
80
279
  Problems
@@ -116,6 +315,7 @@ mapper/lib/rom/processor/transproc.rb:212: [MissingParamName] @param tag has emp
116
315
 
117
316
  0 failures, 32 problems (2 seconds to run)
118
317
  ```
318
+ </details>
119
319
 
120
320
  It is basically the same as above, and:
121
321
 
@@ -168,7 +368,18 @@ include Rails.routes
168
368
 
169
369
  ### Standalone docs check
170
370
 
171
- Just run `yard-junk` command after gem is installed. It should work :)
371
+ Just run `yard-junk` command after gem is installed. Optionally, you can setup "formatters" to use:
372
+
373
+ * text formatter: suitable for console, sparse colorized output;
374
+ * HTML formatter: suitable as CI artifact, readable in browser.
375
+
376
+ Examples:
377
+
378
+ * `yard-junk` (default run, outputs text to STDOUT);
379
+ * `yard-junk --text` (same as above);
380
+ * `yard-junk --text logs/yard.log` (set the output path);
381
+ * `yard-junk --text --html build-artifacts/junk-yard.html` (several formatters at once: text to console,
382
+ HTML to file).
172
383
 
173
384
  ### Rake task (integrating in CI)
174
385
 
@@ -184,13 +395,21 @@ and then run it (or add to your `.travis.yml`) as
184
395
  rake yard:junk
185
396
  ```
186
397
 
398
+ Rake task also allows to pass formatters (at task definition time), this way:
399
+
400
+ ```ruby
401
+ YardJunk::Rake.task(:text) # default
402
+ YardJunk::Rake.task(text: 'logs/yard.log') # text to file
403
+ YardJunk::Rake.task(:text, html: 'build-artifacts/junk-yard.html') # text to STDOUT, html to file
404
+ ```
405
+
187
406
  ## Reasons
188
407
 
189
- Small problems in docs lead to decrease of readability and usability. But it is hard to check for
408
+ Small problems in docs lead to a decrease in readability and usability. But it is hard to check for
190
409
  all those problems manually due to YARD's cumbersome output, and lack of CI-ready doc checking tools.
191
410
 
192
- Idea of regularly structured logger was initially [proposed](https://github.com/lsegal/yard/issues/1007)
193
- as an enchancement for YARD itself, and even some steps were maid by YARD's author in that direction,
411
+ The idea of a regularly structured logger was initially [proposed](https://github.com/lsegal/yard/issues/1007)
412
+ as an enhancement for YARD itself, and even some steps were made by YARD's author in that direction,
194
413
  but the idea was abandoned since.
195
414
 
196
415
  Therefore, this independent tool was made.
@@ -198,31 +417,32 @@ Therefore, this independent tool was made.
198
417
  ## Caveats
199
418
 
200
419
  * Sometimes YARD doesn't provide enough information to guess in which line of code the problem is;
201
- in those cases `junk-yard` just writes something like `file.rb:1` (to stay consistent and not break
420
+ in those cases `yard-junk` just writes something like `file.rb:1` (to stay consistent and not break
202
421
  go-to-file tools);
203
- * Checking of links to files and URLs proven to be incomplete.
422
+ * Checking of links to files and URLs proven to be incomplete ([#12](https://github.com/zverok/yard-junk/issues/12)).
204
423
 
205
424
  ## Roadmap
206
425
 
207
426
  * Docs for usage as a system-wide YARD plugin;
208
427
  * Docs for internals;
209
- * Colorized output for text reporter;
210
- * HTML reporter for CIs allowing to store build artifacts;
211
- * Documentation quality checks as a next level of YARD checker;
212
- * Option to check new/updated code only (integration with git history)?
428
+ * Documentation quality checks as a next level of YARD checker ([#14](https://github.com/zverok/yard-junk/issues/14));
429
+ * Option to check only selected parts of code ([#13](https://github.com/zverok/yard-junk/issues/13)).
213
430
 
214
431
  ## Some examples of problems found in popular gems:
215
432
 
216
433
  **NB: All of those are excellent libs! The showcase is of "how hard it is to maintain docs quality",
217
434
  not of "how ignorant other programmers are".**
218
435
 
219
- httparty:
436
+ <details><summary>httparty: 2</summary>
437
+
220
438
  ```
221
439
  lib/httparty/exceptions.rb:2: [UnknownTag] Unknown tag @abstact. Did you mean @abstract?
222
440
  lib/httparty/exceptions.rb:20: [MissingParamName] @param tag has empty parameter name
223
441
  ```
442
+ </details>
443
+
444
+ <details><summary>vcr: 7</summary>
224
445
 
225
- vcr:
226
446
  ```
227
447
  lib/vcr/deprecations.rb:71: [UnknownParam] @param tag has unknown parameter name: name
228
448
  lib/vcr/deprecations.rb:73: [UnknownParam] @param tag has unknown parameter name: options
@@ -232,8 +452,10 @@ lib/vcr/linked_cassette.rb:55: [UnknownParam] @param tag has unknown parameter n
232
452
  lib/vcr/linked_cassette.rb:56: [UnknownParam] @param tag has unknown parameter name: context-unowned
233
453
  lib/vcr/test_frameworks/cucumber.rb:27: [UnknownParam] @param tag has unknown parameter name: options
234
454
  ```
455
+ </details>
456
+
457
+ <details><summary>eventmachine: 19</summary>
235
458
 
236
- eventmachine:
237
459
  ```
238
460
  lib/em/channel.rb:39: [UnknownParam] @param tag has unknown parameter name: Subscriber
239
461
  lib/em/connection.rb:603: [InvalidLink] Cannot resolve link to Socket.unpack_sockaddr_in from text: {Socket.unpack_sockaddr_in}
@@ -255,8 +477,10 @@ lib/eventmachine.rb:231: [InvalidLink] Cannot resolve link to EventMachine::Call
255
477
  lib/eventmachine.rb:319: [UnknownParam] @param tag has unknown parameter name: delay
256
478
  lib/eventmachine.rb:345: [UnknownParam] @param tag has unknown parameter name: delay
257
479
  ```
480
+ </details>
481
+
482
+ <details><summary>addressable: 8</summary>
258
483
 
259
- addressable:
260
484
  ```
261
485
  lib/addressable/template.rb:197: [UnknownParam] @param tag has unknown parameter name: *indexes. Did you mean `indexes`?
262
486
  lib/addressable/uri.rb:296: [UnknownParam] @param tag has unknown parameter name: *uris. Did you mean `uris`?
@@ -267,8 +491,10 @@ lib/addressable/uri.rb:2023: [UnknownParam] @param tag has unknown parameter nam
267
491
  lib/addressable/uri.rb:2244: [UnknownParam] @param tag has unknown parameter name: *components. Did you mean `components`?
268
492
  lib/addressable/uri.rb:2275: [UnknownParam] @param tag has unknown parameter name: *components. Did you mean `components`?
269
493
  ```
494
+ </details>
495
+
496
+ <details><summary>hashie: 16 (mostly not escaped code in docs)</summary>
270
497
 
271
- hashie:
272
498
  ```
273
499
  lib/hashie/extensions/coercion.rb:68: [UnknownParam] @param tag has unknown parameter name: key
274
500
  lib/hashie/extensions/coercion.rb:69: [UnknownParam] @param tag has unknown parameter name: into
@@ -287,10 +513,12 @@ lib/hashie/extensions/deep_find.rb:36: [InvalidLink] Cannot resolve link to loca
287
513
  lib/hashie/mash.rb:32: [InvalidLink] Cannot resolve link to :a from text: {:a => {:b => 23, :d => {:e => "abc"}
288
514
  lib/hashie/mash.rb:32: [InvalidLink] Cannot resolve link to :g from text: {:g => 44, :h => 29}
289
515
  ```
516
+ </details>
290
517
 
291
518
  ## Authors
292
519
 
293
- [Victor Shepelev](https://github.com/zverok)
520
+ * [Victor Shepelev](https://github.com/zverok)
521
+ * [Olle Jonsson](https://github.com/olleolleolle)
294
522
 
295
523
  ## License
296
524
 
data/exe/yard-junk ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(File.expand_path(__FILE__)), '..', 'lib'))
5
+
6
+ require 'yard'
7
+ require 'yard-junk'
8
+ require 'optparse'
9
+
10
+ formatters = {}
11
+
12
+ OptionParser.new do |opts|
13
+ opts.banner = 'Usage: yard-junk [formatters]'
14
+ opts.separator ''
15
+ opts.separator 'Formatters'
16
+ opts.separator '(you can use several at once, for example --text to print in console and --html to save HTML report somewhere)'
17
+ opts.separator 'Default is: text formatter, printing to STDOUT.'
18
+ opts.separator ''
19
+
20
+ opts.on('--text [PATH]', 'Plaintext formatter (prints to STDOUT by default)') do |path|
21
+ formatters[:text] = path
22
+ end
23
+
24
+ opts.on('--html [PATH]', 'HTML formatter, useful as CI artifact (prints to STDOUT by default)') do |path|
25
+ formatters[:html] = path
26
+ end
27
+
28
+ opts.separator ''
29
+ opts.separator 'Other options'
30
+
31
+ opts.on_tail('-h', '--help', 'Show this message') do
32
+ puts opts
33
+ exit
34
+ end
35
+ end.parse!
36
+
37
+ formatters = {text: nil} if formatters.empty?
38
+
39
+ janitor = YardJunk::Janitor.new
40
+ janitor.run
41
+ exit janitor.report(**formatters)
@@ -27,8 +27,8 @@ module YardJunk
27
27
  }
28
28
  end
29
29
 
30
- def report(*reporters)
31
- reporters.each do |reporter|
30
+ def report(*args, **opts)
31
+ guess_reporters(*args, **opts).each do |reporter|
32
32
  reporter.section('Errors', 'severe code or formatting problems', errors)
33
33
  reporter.section('Problems', 'mistyped tags or other typos in documentation', problems)
34
34
 
@@ -58,9 +58,19 @@ module YardJunk
58
58
  def problems
59
59
  messages.select(&:warn?)
60
60
  end
61
+
62
+ # TODO: specs for the logic
63
+ def guess_reporters(*symbols, **symbols_with_args)
64
+ symbols
65
+ .map { |sym| [sym, nil] }.to_h.merge(symbols_with_args)
66
+ .map { |sym, args| ["#{sym.to_s.capitalize}Reporter", args] }
67
+ .each { |name, _| Janitor.const_defined?(name) or fail(ArgumentError, "Reporter #{name} not found") }
68
+ .map { |name, args| Janitor.const_get(name).new(*args) }
69
+ end
61
70
  end
62
71
  end
63
72
 
64
73
  require_relative 'janitor/base_reporter'
65
74
  require_relative 'janitor/text_reporter'
75
+ require_relative 'janitor/html_reporter'
66
76
  require_relative 'janitor/resolver'
@@ -19,7 +19,7 @@ module YardJunk
19
19
  #
20
20
  # @overload initialize(filename)
21
21
  # @param filename [String] Name of file to save the output.
22
- def initialize(io_or_filename)
22
+ def initialize(io_or_filename = STDOUT)
23
23
  @io =
24
24
  case io_or_filename
25
25
  when ->(i) { i.respond_to?(:puts) } # quacks!
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ module YardJunk
6
+ class Janitor
7
+ # Reporter that just outputs everything in HTML format. Useful
8
+ # for usage with Jenkins. See {BaseReporter} for details about reporters.
9
+ #
10
+ class HtmlReporter < BaseReporter
11
+ HEADER = <<~HTML
12
+ <!DOCTYPE html>
13
+ <html lang="en">
14
+ <header>
15
+ <meta charset='UTF-8' />
16
+ <title>YARD-Junk Report</title>
17
+ <style>
18
+ body, html {
19
+ }
20
+ body {
21
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
22
+ margin: 0;
23
+ padding: 20px;
24
+ }
25
+ h2 {
26
+ font-size: 1.6rem;
27
+ }
28
+ h2 small {
29
+ color: gray;
30
+ font-weight: normal;
31
+ }
32
+ span.path {
33
+ font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
34
+ font-size: 85%;
35
+ }
36
+ .problem { color: red; }
37
+ .notice { color: gray; }
38
+ p.stats {
39
+ padding: 10px;
40
+ font-size: 1.2em;
41
+ border: 1px dotted silver;
42
+ }
43
+ </style>
44
+ </header>
45
+ <body>
46
+ <h1>YARD Validation Report</h1>
47
+ HTML
48
+
49
+ FOOTER = <<~HTML
50
+ </body>
51
+ </html>
52
+ HTML
53
+
54
+ SECTION = <<-HTML
55
+ <h2 class="<%= title == 'Notices' ? 'notice' : 'problem' %>">
56
+ <%= title %>
57
+ <small>(<%= explanation %>)</small>
58
+ </h2>
59
+ HTML
60
+
61
+ ROW = <<-HTML
62
+ <li><span class="path"><%= file %>:<%= line %></span>: <%= message %></li>
63
+ HTML
64
+
65
+ STATS = <<-HTML
66
+ <p class="stats">
67
+ <span class="<%= 'problem' unless errors.zero? %>"><%= errors %> failures</span>,
68
+ <span class="<%= 'problem' unless problems.zero? %>"><%= problems %> problems</span>
69
+ (ready in <%= duration %>)
70
+ </p>
71
+ HTML
72
+
73
+ Helper = Class.new(OpenStruct) do
74
+ def the_binding
75
+ binding
76
+ end
77
+ end
78
+
79
+ attr_reader :html
80
+
81
+ def initialize(*)
82
+ super
83
+ @html = HEADER.dup
84
+ end
85
+
86
+ def finalize
87
+ @html << FOOTER
88
+ @io.puts(@html)
89
+ end
90
+
91
+ private
92
+
93
+ def _stats(**stat)
94
+ render(STATS, **stat)
95
+ end
96
+
97
+ def header(title, explanation)
98
+ render(SECTION, title: title, explanation: explanation)
99
+ end
100
+
101
+ def row(message)
102
+ render(ROW, **message.to_h)
103
+ end
104
+
105
+ def render(template, values)
106
+ html <<
107
+ ERB.new(template)
108
+ .result(Helper.new(values).the_binding)
109
+ end
110
+ end
111
+ end
112
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rainbow'
4
+
3
5
  module YardJunk
4
6
  class Janitor
5
7
  # Reporter that just outputs everything in plaintext format. Useful
@@ -9,9 +11,27 @@ module YardJunk
9
11
  private
10
12
 
11
13
  def _stats(**stat)
12
- line =
13
- '%<errors>i failures, %<problems>i problems (%<duration>s to run)' % stat
14
- @io.puts "\n#{line}"
14
+ @io.puts "\n#{template_for(stat) % stat}"
15
+ end
16
+
17
+ NO_ISSUES_TEMPLATE = [
18
+ Rainbow('%<errors>i failures, %<problems>i problems').green,
19
+ Rainbow(', (%<duration>s to run)').gray
20
+ ].join('').freeze
21
+
22
+ ERROR_COUNT_TEMPLATE = [
23
+ Rainbow('%<errors>i failures').red,
24
+ Rainbow(',').gray,
25
+ Rainbow(' %<problems>i problems').yellow,
26
+ Rainbow(', (%<duration>s to run)').gray
27
+ ].join('').freeze
28
+
29
+ def template_for(stat)
30
+ if stat[:errors].zero? && stat[:problems].zero?
31
+ NO_ISSUES_TEMPLATE
32
+ else
33
+ ERROR_COUNT_TEMPLATE
34
+ end
15
35
  end
16
36
 
17
37
  def header(title, explanation)
@@ -4,12 +4,13 @@ module YardJunk
4
4
  module Rake
5
5
  extend ::Rake::DSL
6
6
 
7
- def self.define_task
8
- desc 'Check th junk in your YARD Documentation'
7
+ def self.define_task(*args)
8
+ desc 'Check the junk in your YARD Documentation'
9
9
  task('yard:junk') do
10
10
  require 'yard'
11
11
  require_relative '../yard-junk'
12
- exit Janitor.new.run.report(Janitor::TextReporter.new(STDOUT))
12
+ args = :text if args.empty?
13
+ exit Janitor.new.run.report(*args)
13
14
  end
14
15
  end
15
16
  end
data/yard-junk.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'yard-junk'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.authors = ['Victor Shepelev']
5
5
  s.email = 'zverok.offline@gmail.com'
6
6
  s.homepage = 'https://github.com/zverok/junk_yard'
@@ -18,16 +18,20 @@ Gem::Specification.new do |s|
18
18
  spec\/.*
19
19
  |Gemfile
20
20
  |Rakefile
21
+ |\.codeclimate.yml
21
22
  |\.rspec
22
23
  |\.gitignore
23
24
  |\.rubocop.yml
25
+ |\.rubocop_todo.yml
24
26
  |\.travis.yml
27
+ |\.yardopts
25
28
  )$/x
26
29
  end
27
30
  s.require_paths = ["lib"]
28
- s.bindir = 'bin'
31
+ s.bindir = 'exe'
29
32
  s.executables << 'yard-junk'
30
33
 
34
+ s.add_dependency 'rainbow'
31
35
  s.add_dependency 'yard'
32
36
  if RUBY_VERSION < '2.4'
33
37
  s.add_dependency 'did_you_mean', '~> 1.0'
@@ -35,11 +39,11 @@ Gem::Specification.new do |s|
35
39
  s.add_dependency 'did_you_mean', '~> 1.1'
36
40
  end
37
41
 
38
- s.add_development_dependency 'rubocop', '>= 0.30'
42
+ s.add_development_dependency 'rubocop', '>= 0.49'
39
43
  s.add_development_dependency 'rspec', '>= 3'
40
44
  s.add_development_dependency 'rubocop-rspec'
41
45
  s.add_development_dependency 'rspec-its', '~> 1'
42
- #s.add_development_dependency 'saharspec'
46
+ #s.add_development_dependency 'saharspec' # saharspec is moving target!
43
47
  s.add_development_dependency 'fakefs'
44
48
  s.add_development_dependency 'simplecov', '~> 0.9'
45
49
  s.add_development_dependency 'rake'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-junk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Shepelev
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-27 00:00:00.000000000 Z
11
+ date: 2017-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rainbow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: yard
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +58,14 @@ dependencies:
44
58
  requirements:
45
59
  - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '0.30'
61
+ version: '0.49'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '0.30'
68
+ version: '0.49'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -172,19 +186,19 @@ executables:
172
186
  extensions: []
173
187
  extra_rdoc_files: []
174
188
  files:
175
- - ".rubocop_todo.yml"
176
- - ".yardopts"
189
+ - Changelog.md
177
190
  - README.md
178
- - bin/yard-junk
179
191
  - examples/bare_log.rb
180
192
  - examples/formatted_log.rb
181
193
  - examples/input/circular_ref.rb
182
194
  - examples/input/lot_of_errors.rb
183
195
  - examples/input/unparseable.rb
196
+ - exe/yard-junk
184
197
  - lib/yard-junk.rb
185
198
  - lib/yard-junk/command_line.rb
186
199
  - lib/yard-junk/janitor.rb
187
200
  - lib/yard-junk/janitor/base_reporter.rb
201
+ - lib/yard-junk/janitor/html_reporter.rb
188
202
  - lib/yard-junk/janitor/resolver.rb
189
203
  - lib/yard-junk/janitor/text_reporter.rb
190
204
  - lib/yard-junk/logger.rb
data/.rubocop_todo.yml DELETED
@@ -1 +0,0 @@
1
-
data/.yardopts DELETED
@@ -1,2 +0,0 @@
1
- --markup markdown
2
- -e ./lib/yard-junk.rb
data/bin/yard-junk DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH.unshift(File.join(File.dirname(File.expand_path(__FILE__)), '..', 'lib'))
5
-
6
- require 'yard'
7
- require 'yard-junk'
8
-
9
- janitor = YardJunk::Janitor.new
10
- janitor.run
11
- exit janitor.report(YardJunk::Janitor::TextReporter.new(STDOUT))