reviewer 0.1.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.alexignore +1 -0
  3. data/.flayignore +1 -0
  4. data/.github/workflows/main.yml +14 -4
  5. data/.gitignore +5 -0
  6. data/.inch.yml +4 -0
  7. data/.reviewer.example.yml +63 -0
  8. data/.reviewer.future.yml +221 -0
  9. data/.reviewer.yml +140 -0
  10. data/.reviewer_stdout +0 -0
  11. data/.rubocop.yml +20 -0
  12. data/CHANGELOG.md +38 -3
  13. data/Gemfile +2 -4
  14. data/Gemfile.lock +103 -20
  15. data/LICENSE.txt +4 -20
  16. data/README.md +23 -29
  17. data/Rakefile +5 -5
  18. data/bin/console +4 -4
  19. data/exe/fmt +7 -0
  20. data/exe/rvw +7 -0
  21. data/lib/reviewer/arguments/files.rb +94 -0
  22. data/lib/reviewer/arguments/keywords.rb +133 -0
  23. data/lib/reviewer/arguments/tags.rb +71 -0
  24. data/lib/reviewer/arguments.rb +54 -10
  25. data/lib/reviewer/batch.rb +91 -0
  26. data/lib/reviewer/command/string/env.rb +44 -0
  27. data/lib/reviewer/command/string/flags.rb +51 -0
  28. data/lib/reviewer/command/string.rb +66 -0
  29. data/lib/reviewer/command.rb +75 -0
  30. data/lib/reviewer/configuration.rb +32 -7
  31. data/lib/reviewer/conversions.rb +16 -0
  32. data/lib/reviewer/guidance.rb +77 -0
  33. data/lib/reviewer/history.rb +69 -0
  34. data/lib/reviewer/keywords/git/staged.rb +64 -0
  35. data/lib/reviewer/keywords/git.rb +14 -0
  36. data/lib/reviewer/keywords.rb +9 -0
  37. data/lib/reviewer/loader.rb +36 -9
  38. data/lib/reviewer/output/printer.rb +44 -0
  39. data/lib/reviewer/output/scrubber.rb +48 -0
  40. data/lib/reviewer/output/token.rb +85 -0
  41. data/lib/reviewer/output.rb +122 -0
  42. data/lib/reviewer/runner/strategies/captured.rb +157 -0
  43. data/lib/reviewer/runner/strategies/passthrough.rb +63 -0
  44. data/lib/reviewer/runner.rb +131 -0
  45. data/lib/reviewer/shell/result.rb +84 -0
  46. data/lib/reviewer/shell/timer.rb +72 -0
  47. data/lib/reviewer/shell.rb +54 -0
  48. data/lib/reviewer/tool/settings.rb +38 -19
  49. data/lib/reviewer/tool.rb +137 -23
  50. data/lib/reviewer/tools.rb +87 -8
  51. data/lib/reviewer/version.rb +1 -1
  52. data/lib/reviewer.rb +107 -28
  53. data/reviewer.gemspec +34 -19
  54. data/structure.svg +1 -0
  55. metadata +244 -12
  56. data/bin/review +0 -5
  57. data/lib/reviewer/tool/command.rb +0 -78
  58. data/lib/reviewer/tool/env.rb +0 -39
  59. data/lib/reviewer/tool/flags.rb +0 -39
  60. data/lib/reviewer/tool/verbosity.rb +0 -39
data/Gemfile.lock CHANGED
@@ -1,36 +1,119 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- reviewer (0.1.1)
5
- activesupport
4
+ reviewer (0.1.5)
5
+ rainbow
6
6
  slop
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.1.3.1)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 1.6, < 2)
14
- minitest (>= 5.1)
15
- tzinfo (~> 2.0)
16
- zeitwerk (~> 2.3)
17
- concurrent-ruby (1.1.8)
18
- i18n (1.8.10)
19
- concurrent-ruby (~> 1.0)
20
- minitest (5.14.4)
21
- rake (13.0.3)
22
- slop (4.8.2)
23
- tzinfo (2.0.4)
24
- concurrent-ruby (~> 1.0)
25
- zeitwerk (2.4.2)
11
+ ast (2.4.2)
12
+ bundler-audit (0.9.0.1)
13
+ bundler (>= 1.2.0, < 3)
14
+ thor (~> 1.0)
15
+ codecov (0.6.0)
16
+ simplecov (>= 0.15, < 0.22)
17
+ coderay (1.1.3)
18
+ docile (1.4.0)
19
+ erubis (2.7.0)
20
+ flay (2.12.1)
21
+ erubis (~> 2.7.0)
22
+ path_expander (~> 1.0)
23
+ ruby_parser (~> 3.0)
24
+ sexp_processor (~> 4.0)
25
+ flog (4.6.4)
26
+ path_expander (~> 1.0)
27
+ ruby_parser (~> 3.1, > 3.1.0)
28
+ sexp_processor (~> 4.8)
29
+ inch (0.8.0)
30
+ pry
31
+ sparkr (>= 0.2.0)
32
+ term-ansicolor
33
+ yard (~> 0.9.12)
34
+ kwalify (0.7.2)
35
+ method_source (1.0.0)
36
+ minitest (5.15.0)
37
+ minitest-heat (1.1.0)
38
+ minitest
39
+ parallel (1.21.0)
40
+ parser (3.0.3.2)
41
+ ast (~> 2.4.1)
42
+ path_expander (1.1.0)
43
+ pry (0.14.1)
44
+ coderay (~> 1.1)
45
+ method_source (~> 1.0)
46
+ psych (4.0.3)
47
+ stringio
48
+ rainbow (3.0.0)
49
+ rake (13.0.6)
50
+ reek (6.0.6)
51
+ kwalify (~> 0.7.0)
52
+ parser (~> 3.0.0)
53
+ rainbow (>= 2.0, < 4.0)
54
+ regexp_parser (2.2.0)
55
+ rexml (3.2.5)
56
+ rubocop (1.23.0)
57
+ parallel (~> 1.10)
58
+ parser (>= 3.0.0.0)
59
+ rainbow (>= 2.2.2, < 4.0)
60
+ regexp_parser (>= 1.8, < 3.0)
61
+ rexml
62
+ rubocop-ast (>= 1.12.0, < 2.0)
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (>= 1.4.0, < 3.0)
65
+ rubocop-ast (1.15.0)
66
+ parser (>= 3.0.1.1)
67
+ rubocop-minitest (0.17.0)
68
+ rubocop (>= 0.90, < 2.0)
69
+ rubocop-rake (0.6.0)
70
+ rubocop (~> 1.0)
71
+ ruby-progressbar (1.11.0)
72
+ ruby_parser (3.18.1)
73
+ sexp_processor (~> 4.16)
74
+ sexp_processor (4.16.0)
75
+ simplecov (0.21.2)
76
+ docile (~> 1.1)
77
+ simplecov-html (~> 0.11)
78
+ simplecov_json_formatter (~> 0.1)
79
+ simplecov-html (0.12.3)
80
+ simplecov_json_formatter (0.1.3)
81
+ slop (4.9.1)
82
+ sparkr (0.4.1)
83
+ stringio (3.0.1)
84
+ sync (0.5.0)
85
+ term-ansicolor (1.7.1)
86
+ tins (~> 1.0)
87
+ thor (1.1.0)
88
+ tins (1.29.1)
89
+ sync
90
+ unicode-display_width (2.1.0)
91
+ webrick (1.7.0)
92
+ yard (0.9.27)
93
+ webrick (~> 1.7.0)
26
94
 
27
95
  PLATFORMS
28
- x86_64-darwin-19
96
+ ruby
97
+ x86_64-darwin-20
98
+ x86_64-linux
29
99
 
30
100
  DEPENDENCIES
31
- minitest (~> 5.0)
101
+ bundler-audit
102
+ codecov
103
+ flay
104
+ flog
105
+ inch
106
+ minitest
107
+ minitest-heat
108
+ psych
32
109
  rake (~> 13.0)
110
+ reek
33
111
  reviewer!
112
+ rubocop
113
+ rubocop-minitest
114
+ rubocop-rake
115
+ simplecov
116
+ yard
34
117
 
35
118
  BUNDLED WITH
36
- 2.2.16
119
+ 2.2.33
data/LICENSE.txt CHANGED
@@ -1,21 +1,5 @@
1
- The MIT License (MIT)
1
+ Copyright (c) Garrett Dimon
2
2
 
3
- Copyright (c) 2021 Garrett Dimon
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
3
+ Reviewer is an Open Source project licensed under the terms of
4
+ the LGPLv3 license. Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
5
+ for license text.
data/README.md CHANGED
@@ -1,43 +1,37 @@
1
- # Reviewer
1
+ # [Reviewer](https://github.com/garrettdimon/reviewer)
2
+ by [Garrett Dimon](https://garrettdimon.com)
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/reviewer`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ ---
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ **Note:** As of December 2021, Reviewer is a work in progress. While it's working great reviewing its own code, it's not quite ready for wider usage. Once, it's ready, it will provide more helpful installation and usage details.
6
7
 
7
- ## Installation
8
+ ---
8
9
 
9
- Add this line to your application's Gemfile:
10
+ *With Reviewer, you can seamlessly use multiple automated code review tools with orders of magnitude less friction so you can use them more frequently and consistently.*
10
11
 
11
- ```ruby
12
- gem 'reviewer'
12
+ So instead of remembering and typing...
13
+ ```bash
14
+ $ yarn audit --level moderate
15
+ $ bundle exec bundle-audit check --no-update
16
+ $ bundle exec rubocop --parallel
17
+ $ bundle exec erblint --lint-all --enable-all-linters
18
+ $ yarn stylelint .
19
+ $ yarn eslint .
20
+ ```
21
+ ...you could just type...
22
+ ```
23
+ $ rvw
13
24
  ```
14
25
 
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install reviewer
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
26
+ That's just the tip of the iceberg, though. For the full story on Reviewer's capabilities and benefits, the [Overview](https://github.com/garrettdimon/reviewer/wiki/Overview) is the best place to start. Or if you'd like to see how it's configured under the hood, the [Configuration Instructions](https://github.com/garrettdimon/reviewer/wiki/Configuration) go even deeper.
34
27
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/reviewer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/reviewer/blob/master/CODE_OF_CONDUCT.md).
28
+ [![build](https://github.com/garrettdimon/reviewer/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/garrettdimon/reviewer/actions/workflows/main.yml)
29
+ [![coverage](https://img.shields.io/codecov/c/github/garrettdimon/reviewer?token=UuXUlQAA2e)](https://codecov.io/gh/garrettdimon/reviewer)
30
+ [![last commit](https://img.shields.io/github/last-commit/garrettdimon/reviewer/main)](https://github.com/garrettdimon/reviewer/commits/main)
31
+ [![gem version](https://img.shields.io/gem/v/reviewer)](https://rubygems.org/gems/reviewer)
36
32
 
37
33
  ## License
38
-
39
34
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
35
 
41
36
  ## Code of Conduct
42
-
43
37
  Everyone interacting in the Reviewer project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/reviewer/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
5
 
6
6
  Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/*_test.rb"]
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
10
  end
11
11
 
12
12
  task default: :test
data/bin/console CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "reviewer"
4
+ require 'bundler/setup'
5
+ require 'reviewer'
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
9
9
 
10
10
  # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
11
+ # require 'pry'
12
12
  # Pry.start
13
13
 
14
- require "irb"
14
+ require 'irb'
15
15
  IRB.start(__FILE__)
data/exe/fmt ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require_relative '../lib/reviewer'
6
+
7
+ Reviewer.format(clear_screen: true)
data/exe/rvw ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require_relative '../lib/reviewer'
6
+
7
+ Reviewer.review(clear_screen: true)
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reviewer
4
+ class Arguments
5
+ # Generates a Ruby-friendly list (Array) of files to run the command against from the provided
6
+ # command line arguments
7
+ class Files
8
+ attr_reader :provided, :keywords
9
+
10
+ alias raw provided
11
+
12
+ # Generates an instance of files from the provided arguments
13
+ # @param provided: Reviewer.arguments.files.raw [Array, String] file arguments provided
14
+ # directly via the -f or --files flag on the command line.
15
+ # @param keywords: Reviewer.arguments.keywords [Array, String] keywords that can potentially
16
+ # be translated to a list of files (ex. 'staged')
17
+ #
18
+ # @example Using the `-f` flag: `rvw -f ./file.rb`
19
+ # reviewer = Reviewer::Arguments::Files.new(provided: ['./file.rb'], keywords: [])
20
+ # reviewer.to_a # => ['./file.rb']
21
+ # @example Using the `--files` flag: `rvw --files ./file.rb,./directory/file.rb
22
+ # reviewer = Reviewer::Arguments::Files.new(provided: ['./file.rb','./directory/file.rb'], keywords: [])
23
+ # reviewer.to_a # => ['./file.rb','./directory/file.rb']
24
+ #
25
+ # @return [self]
26
+ def initialize(provided: Reviewer.arguments.files.raw, keywords: Reviewer.arguments.keywords)
27
+ @provided = Array(provided)
28
+ @keywords = Array(keywords)
29
+ end
30
+
31
+ # Provides the full list of file/path values derived from the command-line arguments
32
+ #
33
+ # @return [Array<String>] full collection of the file arguments as a string
34
+ def to_a
35
+ file_list
36
+ end
37
+
38
+ # Provides the full list of file/path values derived from the command-line arguments
39
+ #
40
+ # @return [String] comma-separated string of the derived tag values
41
+ def to_s
42
+ to_a.join(',')
43
+ end
44
+
45
+ # Summary of the state of the file arguments
46
+ #
47
+ # @return [Hash<Symbol, Array<String>>] summarizes all of the resulting file values
48
+ def to_h
49
+ {
50
+ provided: provided.sort,
51
+ from_keywords: from_keywords
52
+ }
53
+ end
54
+ alias inspect to_h
55
+
56
+ private
57
+
58
+ # Combines the sorted list of unique files/paths by merging the explicitly-provided file
59
+ # arguments as well as those that were translated from any relevant keyword arguments.
60
+ #
61
+ # @return [Array] full list of files/paths passed via command-line including those extracted
62
+ # as a result of a keyword argument like `staged`
63
+ def file_list
64
+ @file_list ||= [
65
+ *provided,
66
+ *from_keywords
67
+ ].compact.sort.uniq
68
+ end
69
+
70
+ # Converts relevant keywords to the list of files they implicitly represent.
71
+ #
72
+ # @return [Array<String>] list of files/paths translated from any keyword arguments that
73
+ # represent a list of files
74
+ def from_keywords
75
+ return [] unless keywords.any?
76
+
77
+ keywords.map do |keyword|
78
+ next unless respond_to?(keyword.to_sym, true)
79
+
80
+ send(keyword.to_sym)
81
+ end.flatten.compact.uniq
82
+ end
83
+
84
+ # If `staged` is passed as a keyword via the command-line, this will get the list of staged
85
+ # files via Git
86
+ #
87
+ # @return [Array] list of the currently staged files
88
+ def staged
89
+ # Use git for list of staged fields
90
+ ::Reviewer::Keywords::Git::Staged.list
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reviewer
4
+ class Arguments
5
+ # Handles interpreting all 'leftover' arguments and translating them to file-related,
6
+ # tag-related, or tool-related arguments
7
+ #
8
+ # @!attribute provided
9
+ # @return [Array<String>] the keywords extracted from the command-line arguments
10
+ class Keywords
11
+ RESERVED = %w[staged].freeze
12
+
13
+ attr_accessor :provided
14
+
15
+ alias raw provided
16
+
17
+ # Generates an instance of parsed keywords from the provided arguments
18
+ # @param *provided [Array<String>] the leftover (non-flag) arguments from the command line
19
+ #
20
+ # @return [self]
21
+ def initialize(*provided)
22
+ @provided = Array(provided.flatten)
23
+ end
24
+
25
+ # Proves the full list of raw keyword arguments explicitly passed via command-line as an array
26
+ #
27
+ # @return [Array] full collection of the provided keyword arguments as a string
28
+ def to_a
29
+ provided
30
+ end
31
+
32
+ # Provides the full list of raw keyword arguments explicitly passed via command-line as a
33
+ # comma-separated string
34
+ #
35
+ # @return [String] comma-separated list of the file arguments as a string
36
+ def to_s
37
+ to_a.join(',')
38
+ end
39
+
40
+ # Summary of the state of keyword arguments based on how Reviewer parsed them
41
+ #
42
+ # @return [Hash] represents the summary of the keyword values parsed from the command-line and
43
+ # grouped based on how they were parsed
44
+ def to_h
45
+ {
46
+ provided: provided,
47
+ recognized: recognized,
48
+ unrecognized: unrecognized,
49
+ reserved: reserved,
50
+ for_tags: for_tags,
51
+ for_tool_names: for_tool_names
52
+ }
53
+ end
54
+ alias inspect to_h
55
+
56
+ # Extracts reserved keywords from the provided arguments
57
+ #
58
+ # @return [Array<String>] intersection of provided arguments and reserved keywords
59
+ def reserved
60
+ intersection_with RESERVED
61
+ end
62
+
63
+ # Extracts keywords that match configured tags for enabled tools
64
+ #
65
+ # @return [Array<String>] intersection of provided arguments and configured tags for tools
66
+ def for_tags
67
+ intersection_with configured_tags
68
+ end
69
+
70
+ # Extracts keywords that match configured tool keys
71
+ #
72
+ # @return [Array<String>] intersection of provided arguments and configured tool names
73
+ def for_tool_names
74
+ intersection_with configured_tool_names
75
+ end
76
+
77
+ # Extracts keywords that match any possible recognized keyword values
78
+ #
79
+ # @return [Array<String>] intersection of provided arguments and recognizable keywords
80
+ def recognized
81
+ intersection_with possible
82
+ end
83
+
84
+ # Extracts keywords that don't match any possible recognized keyword values
85
+ #
86
+ # @return [Array<String>] leftover keywords that weren't recognized
87
+ def unrecognized
88
+ (provided - recognized).uniq.sort
89
+ end
90
+
91
+ # Provides the complete list of all recognized keywords based on configuration
92
+ #
93
+ # @return [Array<String>] all keywords that Reviewer can recognized
94
+ def possible
95
+ (RESERVED + configured_tags + configured_tool_names).uniq.sort
96
+ end
97
+
98
+ # Provides the complete list of all configured tags for enabled tools
99
+ #
100
+ # @return [Array<String>] all unique configured tags
101
+ def configured_tags
102
+ tools.enabled.map(&:tags).flatten.uniq.sort
103
+ end
104
+
105
+ # Provides the complete list of all configured tool names for enabled tools
106
+ #
107
+ # @return [Array<String>] all unique configured tools
108
+ def configured_tool_names
109
+ # We explicitly don't sort the tool names list because Reviewer uses the configuration order
110
+ # to determine the execution order. So not sorting maintains the predicted order it will run
111
+ # in and leaves the option to sort to the consuming code if needed
112
+ tools.all.map { |tool| tool.key.to_s }
113
+ end
114
+
115
+ private
116
+
117
+ # Provides a collection of enabled Tools for convenient access
118
+ #
119
+ # @return [Array<Reviewer::Tool>] collection of all currently enabled tools
120
+ def tools
121
+ @tools ||= Reviewer.tools
122
+ end
123
+
124
+ # Syntactic sugar for finding intersections with valid keywords
125
+ # @param values [Array<String>] the collection to use for finding intersecting values
126
+ #
127
+ # @return [Array<String>] the list of intersecting values
128
+ def intersection_with(values)
129
+ (values & provided).uniq.sort
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reviewer
4
+ class Arguments
5
+ # Handles the logic of translating tag arguments
6
+ class Tags
7
+ attr_accessor :provided, :keywords
8
+
9
+ alias raw provided
10
+
11
+ # Generates an instace of parsed tags from the provided arguments by merging tag arguments
12
+ # that were provided via either flags or keywords
13
+ # @param provided: Reviewer.arguments.tags.raw [Array<String>] tag arguments provided
14
+ # directly via the -t or --tags flag on the command line.
15
+ # @param keywords: Reviewer.arguments.keywords [Array, String] keywords that can potentially
16
+ # be translated to a list of tags based on the tags used in the configuration file
17
+ #
18
+ # @example Using keywords: `rvw ruby` (assuming a 'ruby' tag is defined)
19
+ # Reviewer::Arguments::Tags.new.to_a # => ['ruby']
20
+ # @example Using the `-t` flag: `rvw -t ruby`
21
+ # Reviewer::Arguments::Tags.new.to_a # => ['ruby']
22
+ # @example Using the `--tags` flag: `rvw -t ruby,css`
23
+ # Reviewer::Arguments::Tags.new.to_a # => ['css', 'ruby']
24
+ #
25
+ # @return [self]
26
+ def initialize(provided: Reviewer.arguments.tags.raw, keywords: Reviewer.arguments.keywords.for_tags)
27
+ @provided = Array(provided)
28
+ @keywords = Array(keywords)
29
+ end
30
+
31
+ # Provides the full list of tags values derived from the command-line arguments
32
+ #
33
+ # @return [Array<String>] full collection of the tag arguments as a string
34
+ def to_a
35
+ tag_list
36
+ end
37
+
38
+ # Provides the full list of tag values derived from the command-line arguments
39
+ #
40
+ # @return [String] comma-separated string of the derived tag values
41
+ def to_s
42
+ to_a.join(',')
43
+ end
44
+
45
+ # Summary of the state of the tag arguments
46
+ #
47
+ # @return [Hash] represents the summary of the tag values parsed from the command-line
48
+ def to_h
49
+ {
50
+ provided: provided.sort,
51
+ from_keywords: keywords.sort
52
+ }
53
+ end
54
+ alias inspect to_h
55
+
56
+ private
57
+
58
+ # Combines the sorted list of unique tags by merging the explicitly-provided tag arguments
59
+ # as well as those that were recognized from any relevant keyword arguments.
60
+ #
61
+ # @return [Array] full list of tags passed via command-line including those matching keyword
62
+ # arguments
63
+ def tag_list
64
+ @tag_list ||= [
65
+ *provided,
66
+ *keywords
67
+ ].compact.sort.uniq
68
+ end
69
+ end
70
+ end
71
+ end