reek 1.6.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +6 -9
  3. data/features/command_line_interface/options.feature +20 -16
  4. data/features/command_line_interface/stdin.feature +1 -1
  5. data/features/rake_task/rake_task.feature +0 -12
  6. data/features/reports/reports.feature +63 -23
  7. data/features/reports/yaml.feature +3 -3
  8. data/features/samples.feature +3 -3
  9. data/lib/reek/cli/application.rb +5 -5
  10. data/lib/reek/cli/input.rb +1 -1
  11. data/lib/reek/cli/option_interpreter.rb +77 -0
  12. data/lib/reek/cli/options.rb +89 -82
  13. data/lib/reek/cli/report/formatter.rb +33 -24
  14. data/lib/reek/cli/report/heading_formatter.rb +45 -0
  15. data/lib/reek/cli/report/location_formatter.rb +23 -0
  16. data/lib/reek/cli/report/report.rb +32 -17
  17. data/lib/reek/configuration/app_configuration.rb +2 -2
  18. data/lib/reek/configuration/configuration_file_finder.rb +10 -10
  19. data/lib/reek/core/smell_repository.rb +3 -28
  20. data/lib/reek/rake/task.rb +35 -76
  21. data/lib/reek/smell_warning.rb +31 -16
  22. data/lib/reek/smells/nested_iterators.rb +1 -1
  23. data/lib/reek/smells/smell_detector.rb +9 -0
  24. data/lib/reek/smells/utility_function.rb +2 -1
  25. data/lib/reek/spec/should_reek.rb +0 -3
  26. data/lib/reek/spec/should_reek_of.rb +61 -12
  27. data/lib/reek/spec/should_reek_only_of.rb +12 -10
  28. data/lib/reek/version.rb +1 -1
  29. data/reek.gemspec +2 -2
  30. data/spec/factories/factories.rb +2 -5
  31. data/spec/reek/cli/html_report_spec.rb +28 -0
  32. data/spec/reek/cli/option_interperter_spec.rb +14 -0
  33. data/spec/reek/cli/text_report_spec.rb +95 -0
  34. data/spec/reek/cli/yaml_report_spec.rb +23 -0
  35. data/spec/reek/configuration/configuration_file_finder_spec.rb +5 -6
  36. data/spec/reek/core/module_context_spec.rb +1 -1
  37. data/spec/reek/core/smell_repository_spec.rb +17 -0
  38. data/spec/reek/smell_warning_spec.rb +9 -11
  39. data/spec/reek/smells/boolean_parameter_spec.rb +11 -11
  40. data/spec/reek/smells/control_parameter_spec.rb +40 -40
  41. data/spec/reek/smells/data_clump_spec.rb +17 -17
  42. data/spec/reek/smells/duplicate_method_call_spec.rb +56 -33
  43. data/spec/reek/smells/feature_envy_spec.rb +44 -40
  44. data/spec/reek/smells/irresponsible_module_spec.rb +1 -1
  45. data/spec/reek/smells/long_parameter_list_spec.rb +12 -12
  46. data/spec/reek/smells/long_yield_list_spec.rb +4 -4
  47. data/spec/reek/smells/module_initialize_spec.rb +3 -3
  48. data/spec/reek/smells/nested_iterators_spec.rb +71 -52
  49. data/spec/reek/smells/nil_check_spec.rb +6 -6
  50. data/spec/reek/smells/prima_donna_method_spec.rb +2 -2
  51. data/spec/reek/smells/too_many_statements_spec.rb +34 -34
  52. data/spec/reek/smells/uncommunicative_method_name_spec.rb +1 -1
  53. data/spec/reek/smells/uncommunicative_module_name_spec.rb +7 -3
  54. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +12 -12
  55. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +28 -38
  56. data/spec/reek/smells/unused_parameters_spec.rb +16 -17
  57. data/spec/reek/smells/utility_function_spec.rb +21 -8
  58. data/spec/reek/spec/should_reek_of_spec.rb +18 -5
  59. data/spec/reek/spec/should_reek_only_of_spec.rb +7 -1
  60. data/spec/spec_helper.rb +22 -14
  61. metadata +15 -20
  62. data/lib/reek/cli/help_command.rb +0 -15
  63. data/lib/reek/cli/report/strategy.rb +0 -64
  64. data/lib/reek/cli/version_command.rb +0 -16
  65. data/spec/matchers/smell_of_matcher.rb +0 -95
  66. data/spec/reek/cli/help_command_spec.rb +0 -25
  67. data/spec/reek/cli/report_spec.rb +0 -132
  68. data/spec/reek/cli/version_command_spec.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6b56b69887082aa037332d0e26893f0124b5217
4
- data.tar.gz: 86dfd512f568cbdaca34fbdca28c05f97d9578d8
3
+ metadata.gz: 6e9938a6d72e1e64ab84f0cbfc67d43574a0d9b8
4
+ data.tar.gz: 102ac522a9e2df22fbbec630f09d97174e4e5bd0
5
5
  SHA512:
6
- metadata.gz: c78a54feac15972836de8e6cc89172649db95bd3c1d113ba7e089a8558f1f8143fe520a2ada4185646586a90a146e9ca05a4687707799a1f13cf2cda088b2dc5
7
- data.tar.gz: 55d5f7cfde48194423d1b685da1eb560bed74fc43f81df44d2166989ce58e7fab3ce720e30c9d02194901a75733ff10887f015573a8fc91a87c5f0f840d8bedb
6
+ metadata.gz: c7b67443588cd094db2a47cd4fddf96190ea87c4c44e68fe6620f86638346e1dc38ad9e84941e6939360765762738b3fa5902289db52f2fa1ef1e78066b412ef
7
+ data.tar.gz: 16a5d7d2c2750e4a7d1324ca9bb6076fb3caad8eb929fb319dff712e895c6ffe73420e4f914317a5981f26300dc3fe5f1c926e36e69dd1ed7b1bbed0214ff2a8
data/CHANGELOG CHANGED
@@ -1,14 +1,11 @@
1
- == 1.6.6
2
-
3
- * (guilhermesimoes) Fix HTML report generation.
4
-
5
- == 1.6.5
6
-
7
- * (mvz) Make NestedIterator not break when iterator is called on super.
8
-
9
- == 1.6.4
1
+ == 2.0.0
10
2
 
3
+ * (troessner) Revise, improve & refactor our Rspec matcher and remove smell_of
4
+ * (guilhermesimoes) Fix generating HTML report
5
+ * (mvz) Re-organize CLI options
11
6
  * (maser) Fix file arguments without TTY
7
+ * (marcofognog) Make NestedIterator not break if iterator is called on super
8
+ * (troessner) Revamp & refactor our rake task
12
9
 
13
10
  == 1.6.3
14
11
 
@@ -25,29 +25,33 @@ Feature: Reek can be controlled using command-line options
25
25
  Examples:
26
26
 
27
27
  reek lib/*.rb
28
- reek -q lib
28
+ reek -s lib
29
29
  cat my_class.rb | reek
30
30
 
31
31
  See http://wiki.github.com/troessner/reek for detailed help.
32
32
 
33
- Common options:
34
- -h, --help Show this message
35
- -v, --version Show version
36
-
37
33
  Configuration:
38
34
  -c, --config FILE Read configuration options from FILE
39
35
  --smell SMELL Detect smell SMELL (default is all enabled smells)
40
36
 
41
- Report formatting:
42
- -o, --[no-]color Use colors for the output (this is the default)
43
- -q, --quiet Suppress headings for smell-free source files (this is the default)
44
- -V, --no-quiet, --verbose Show headings for smell-free source files
45
- -U, --ultra-verbose Be as explanatory as possible
46
- -n, --no-line-numbers Suppress line numbers from the output
47
- --line-numbers Show line numbers in the output (this is the default)
48
- -s, --single-line Show IDE-compatible single-line-per-warning
49
- -S, --sort-by-issue-count Sort by "issue-count", listing the "smelliest" files first
50
- -y, --yaml Report smells in YAML format
51
- -H, --html Report smells in HTML format
37
+ Report format:
38
+ -f, --format FORMAT Report smells in the given format:
39
+ html
40
+ text (default)
41
+ yaml
42
+
43
+ Text format options:
44
+ --[no-]color Use colors for the output (this is the default)
45
+ -V, --[no-]empty-headings Show headings for smell-free source files
46
+ -U, --[no-]wiki-links Show link to related Reek wiki page for each smell
47
+ -n, --[no-]line-numbers Show line numbers in the output (this is the default)
48
+ -s, --single-line Show location in editor-compatible single-line-per-smell format
49
+ --sort-by SORTING Sort reported files by the given criterium:
50
+ smelliness ("smelliest" files first)
51
+ none (default - output in processing order)
52
+
53
+ Utility options:
54
+ -h, --help Show this message
55
+ -v, --version Show version
52
56
 
53
57
  """
@@ -12,7 +12,7 @@ Feature: Reek reads from $stdin when no files are given
12
12
  """
13
13
 
14
14
  Scenario: outputs nothing on empty stdin
15
- When I pass "" to reek --quiet
15
+ When I pass "" to reek
16
16
  Then it succeeds
17
17
  And stdout equals ""
18
18
 
@@ -82,15 +82,3 @@ Feature: Reek can be driven through its Task
82
82
  And it reports:
83
83
  """
84
84
  """
85
- Scenario: can be configured with config_files
86
- When I run rake reek with:
87
- """
88
- Reek::Rake::Task.new do |t|
89
- t.config_files = 'spec/samples/minimal_smelly_and_masked/config.reek'
90
- t.source_files = 'spec/samples/minimal_smelly_and_masked/minimal_dirty.rb'
91
- end
92
- """
93
- Then it succeeds
94
- And it reports:
95
- """
96
- """
@@ -31,8 +31,8 @@ Feature: Correctly formatted reports
31
31
  | spec/samples/two_smelly_files/*.rb |
32
32
  | spec/samples/two_smelly_files |
33
33
 
34
- Scenario: Do not sort by default (which means report each file as it is read in)
35
- When I run reek spec/samples/three_smelly_files/*.rb
34
+ Scenario Outline: No sorting (which means report each file as it is read in)
35
+ When I run reek <option> spec/samples/three_smelly_files/*.rb
36
36
  Then the exit status indicates smells
37
37
  And it reports:
38
38
  """
@@ -51,6 +51,12 @@ Feature: Correctly formatted reports
51
51
  9 total warnings
52
52
  """
53
53
 
54
+ Examples:
55
+ | option |
56
+ | |
57
+ | --sort-by none |
58
+ | --sort-by n |
59
+
54
60
  Scenario Outline: Sort by issue count
55
61
  When I run reek <option> spec/samples/three_smelly_files/*.rb
56
62
  Then the exit status indicates smells
@@ -72,11 +78,11 @@ Feature: Correctly formatted reports
72
78
  """
73
79
 
74
80
  Examples:
75
- | option |
76
- | -S |
77
- | --sort-by-issue-count |
81
+ | option |
82
+ | --sort-by smelliness |
83
+ | --sort-by s |
78
84
 
79
- Scenario Outline: good files show no headers by default
85
+ Scenario Outline: good files show no headings by default
80
86
  When I run reek <args>
81
87
  Then it succeeds
82
88
  And it reports:
@@ -90,7 +96,7 @@ Feature: Correctly formatted reports
90
96
  | spec/samples/three_clean_files/*.rb |
91
97
  | spec/samples/three_clean_files |
92
98
 
93
- Scenario Outline: --verbose and --no-quiet turn on headers for fragrant files
99
+ Scenario Outline: --empty-headings turns on headings for fragrant files
94
100
  When I run reek <option> spec/samples/three_clean_files/*.rb
95
101
  Then it succeeds
96
102
  And it reports:
@@ -102,12 +108,11 @@ Feature: Correctly formatted reports
102
108
  """
103
109
 
104
110
  Examples:
105
- | option |
106
- | --verbose |
107
- | -V |
108
- | --no-quiet |
111
+ | option |
112
+ | --empty-headings |
113
+ | -V |
109
114
 
110
- Scenario Outline: --quiet turns off headers for fragrant files
115
+ Scenario Outline: --no-empty-headings turns off headings for fragrant files
111
116
  When I run reek <option> spec/samples/three_clean_files/*.rb
112
117
  Then it succeeds
113
118
  And it reports:
@@ -117,11 +122,11 @@ Feature: Correctly formatted reports
117
122
  """
118
123
 
119
124
  Examples:
120
- | option |
121
- | -V -q |
122
- | -V --quiet |
125
+ | option |
126
+ | --no-empty-headings |
127
+ | -V --no-empty-headings |
123
128
 
124
- Scenario Outline: --line-number turns off line numbers
129
+ Scenario Outline: --no-line-numbers turns off line numbers
125
130
  When I run reek <option> spec/samples/standard_smelly/dirty.rb
126
131
  Then the exit status indicates smells
127
132
  And it reports:
@@ -136,11 +141,30 @@ Feature: Correctly formatted reports
136
141
  """
137
142
 
138
143
  Examples:
139
- | option |
140
- | -n |
141
- | --no-line-numbers |
142
- | -n -V |
143
- | -V -n |
144
+ | option |
145
+ | --no-line-numbers |
146
+ | --no-line-numbers -V |
147
+ | -V --no-line-numbers |
148
+
149
+ Scenario Outline: --line-numbers turns on line numbers
150
+ When I run reek <option> spec/samples/standard_smelly/dirty.rb
151
+ Then the exit status indicates smells
152
+ And it reports:
153
+ """
154
+ spec/samples/standard_smelly/dirty.rb -- 6 warnings:
155
+ [5]:Dirty has the variable name '@s' (UncommunicativeVariableName)
156
+ [4, 6]:Dirty#a calls @s.title 2 times (DuplicateMethodCall)
157
+ [4, 6]:Dirty#a calls puts(@s.title) 2 times (DuplicateMethodCall)
158
+ [5]:Dirty#a contains iterators nested 2 deep (NestedIterators)
159
+ [3]:Dirty#a has the name 'a' (UncommunicativeMethodName)
160
+ [5]:Dirty#a has the variable name 'x' (UncommunicativeVariableName)
161
+ """
162
+
163
+ Examples:
164
+ | option |
165
+ | --line-numbers |
166
+ | --no-line-numbers --line-numbers |
167
+ | --no-line-numbers -n |
144
168
 
145
169
  Scenario Outline: --single-line shows filename and one line number
146
170
  When I run reek <option> spec/samples/standard_smelly/dirty.rb
@@ -190,7 +214,7 @@ Feature: Correctly formatted reports
190
214
  | spec/samples/two_smelly_files/ |
191
215
  | spec/samples/two_smelly_files |
192
216
 
193
- Scenario Outline: -U or --ultra-verbose adds helpful links to smell warnings
217
+ Scenario Outline: -U or --wiki-links adds helpful links to smell warnings
194
218
  When I run reek <option> spec/samples/one_smelly_file/dirty.rb
195
219
  Then the exit status indicates smells
196
220
  And it reports:
@@ -204,4 +228,20 @@ Feature: Correctly formatted reports
204
228
  Examples:
205
229
  | option |
206
230
  | -U |
207
- | --ultra-verbose |
231
+ | --wiki-links |
232
+
233
+ Scenario Outline: --wiki-links is independent of --line-numbers
234
+ When I run reek <option> spec/samples/one_smelly_file/dirty.rb
235
+ Then the exit status indicates smells
236
+ And it reports:
237
+ """
238
+ spec/samples/one_smelly_file/dirty.rb -- 3 warnings:
239
+ D has no descriptive comment (IrresponsibleModule) [https://github.com/troessner/reek/wiki/Irresponsible-Module]
240
+ D has the name 'D' (UncommunicativeModuleName) [https://github.com/troessner/reek/wiki/Uncommunicative-Module-Name]
241
+ D#a has the name 'a' (UncommunicativeMethodName) [https://github.com/troessner/reek/wiki/Uncommunicative-Method-Name]
242
+ """
243
+
244
+ Examples:
245
+ | option |
246
+ | --no-line-numbers -U |
247
+ | --no-line-numbers --wiki-links |
@@ -4,7 +4,7 @@ Feature: Report smells using simple YAML layout
4
4
  output a list of smells in Yaml.
5
5
 
6
6
  Scenario: output is empty when there are no smells
7
- When I run reek --yaml spec/samples/three_clean_files
7
+ When I run reek --format yaml spec/samples/three_clean_files
8
8
  Then it succeeds
9
9
  And it reports this yaml:
10
10
  """
@@ -12,7 +12,7 @@ Feature: Report smells using simple YAML layout
12
12
  """
13
13
 
14
14
  Scenario: Indicate smells and print them as yaml when using files
15
- When I run reek --yaml spec/samples/standard_smelly/minimal_dirty.rb
15
+ When I run reek --format yaml spec/samples/standard_smelly/minimal_dirty.rb
16
16
  Then the exit status indicates smells
17
17
  And it reports this yaml:
18
18
  """
@@ -44,7 +44,7 @@ Feature: Report smells using simple YAML layout
44
44
  """
45
45
 
46
46
  Scenario: Indicate smells and print them as yaml when using STDIN
47
- When I pass "class Turn; end" to reek --yaml
47
+ When I pass "class Turn; end" to reek --format yaml
48
48
  Then the exit status indicates smells
49
49
  And it reports this yaml:
50
50
  """
@@ -6,7 +6,7 @@ Feature: Basic smell detection
6
6
 
7
7
  @inline
8
8
  Scenario: Correct smells from inline.rb
9
- When I run reek -n spec/samples/inline.rb
9
+ When I run reek --no-line-numbers spec/samples/inline.rb
10
10
  Then the exit status indicates smells
11
11
  And it reports:
12
12
  """
@@ -58,7 +58,7 @@ Feature: Basic smell detection
58
58
  """
59
59
 
60
60
  Scenario: Correct smells from optparse.rb
61
- When I run reek -n spec/samples/optparse.rb
61
+ When I run reek --no-line-numbers spec/samples/optparse.rb
62
62
  Then the exit status indicates smells
63
63
  And it reports:
64
64
  """
@@ -177,7 +177,7 @@ Feature: Basic smell detection
177
177
  """
178
178
 
179
179
  Scenario: Correct smells from redcloth.rb
180
- When I run reek -n spec/samples/redcloth.rb
180
+ When I run reek --no-line-numbers spec/samples/redcloth.rb
181
181
  Then the exit status indicates smells
182
182
  And it reports:
183
183
  """
@@ -1,4 +1,5 @@
1
1
  require 'reek/cli/options'
2
+ require 'reek/cli/reek_command'
2
3
  require 'reek/configuration/app_configuration'
3
4
 
4
5
  module Reek
@@ -9,17 +10,16 @@ module Reek
9
10
  # command line.
10
11
  #
11
12
  class Application
12
- attr_reader :options
13
-
14
13
  STATUS_SUCCESS = 0
15
14
  STATUS_ERROR = 1
16
15
  STATUS_SMELLS = 2
17
16
 
18
17
  def initialize(argv)
19
18
  @status = STATUS_SUCCESS
20
- @options = Options.new(argv)
19
+ options_parser = Options.new(argv)
21
20
  begin
22
- @command = @options.parse
21
+ @options = options_parser.parse
22
+ @command = ReekCommand.new(OptionInterpreter.new(@options))
23
23
  initialize_configuration
24
24
  rescue OptionParser::InvalidOption, Reek::Configuration::ConfigFileException => error
25
25
  $stderr.puts "Error: #{error}"
@@ -34,7 +34,7 @@ module Reek
34
34
  end
35
35
 
36
36
  def initialize_configuration
37
- Configuration::AppConfiguration.initialize_with self
37
+ Configuration::AppConfiguration.initialize_with @options
38
38
  end
39
39
 
40
40
  def output(text)
@@ -1,7 +1,7 @@
1
1
  require 'reek/source'
2
2
 
3
3
  module Reek
4
- module CLI
4
+ module Cli
5
5
  #
6
6
  # CLI Input utility
7
7
  #
@@ -0,0 +1,77 @@
1
+ require 'forwardable'
2
+ require 'reek/cli/input'
3
+ require 'reek/cli/report/report'
4
+ require 'reek/cli/report/formatter'
5
+ require 'reek/cli/report/heading_formatter'
6
+
7
+ module Reek
8
+ module Cli
9
+ #
10
+ # Interprets the options set from the command line
11
+ #
12
+ class OptionInterpreter
13
+ include Cli::Input
14
+
15
+ extend Forwardable
16
+
17
+ def_delegators :@options, :smells_to_detect
18
+
19
+ def initialize(options)
20
+ @options = options
21
+ @argv = @options.argv
22
+ end
23
+
24
+ def reporter
25
+ @reporter ||=
26
+ report_class.new(
27
+ warning_formatter: warning_formatter,
28
+ report_formatter: Report::Formatter,
29
+ sort_by_issue_count: sort_by_issue_count,
30
+ heading_formatter: heading_formatter)
31
+ end
32
+
33
+ def report_class
34
+ case @options.report_format
35
+ when :yaml
36
+ Report::YamlReport
37
+ when :html
38
+ Report::HtmlReport
39
+ else # :text
40
+ Report::TextReport
41
+ end
42
+ end
43
+
44
+ def warning_formatter
45
+ klass = if @options.show_links
46
+ Report::WikiLinkWarningFormatter
47
+ else
48
+ Report::SimpleWarningFormatter
49
+ end
50
+ klass.new(location_formatter)
51
+ end
52
+
53
+ def location_formatter
54
+ case @options.location_format
55
+ when :single_line
56
+ Report::SingleLineLocationFormatter
57
+ when :plain
58
+ Report::BlankLocationFormatter
59
+ else # :numbers
60
+ Report::DefaultLocationFormatter
61
+ end
62
+ end
63
+
64
+ def heading_formatter
65
+ if @options.show_empty
66
+ Report::HeadingFormatter::Verbose
67
+ else
68
+ Report::HeadingFormatter::Quiet
69
+ end
70
+ end
71
+
72
+ def sort_by_issue_count
73
+ @options.sorting == :smelliness
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,12 +1,7 @@
1
1
  require 'optparse'
2
+ require 'ostruct'
2
3
  require 'rainbow'
3
- require 'reek/cli/report/report'
4
- require 'reek/cli/report/formatter'
5
- require 'reek/cli/report/strategy'
6
- require 'reek/cli/reek_command'
7
- require 'reek/cli/help_command'
8
- require 'reek/cli/version_command'
9
- require 'reek/cli/input'
4
+ require 'reek/cli/option_interpreter'
10
5
 
11
6
  module Reek
12
7
  module Cli
@@ -14,110 +9,122 @@ module Reek
14
9
  # Parses the command line
15
10
  #
16
11
  class Options
17
- include CLI::Input
12
+ def initialize(argv)
13
+ @argv = argv
14
+ @parser = OptionParser.new
15
+ @options = OpenStruct.new(colored: true, smells_to_detect: [])
16
+ set_up_parser
17
+ end
18
+
19
+ def parse
20
+ @parser.parse!(@argv)
21
+ @options.argv = @argv
22
+ Rainbow.enabled = @options.colored
23
+ @options
24
+ end
18
25
 
19
- attr_reader :config_file, :smells_to_detect
26
+ private
20
27
 
21
- def initialize(argv)
22
- @argv = argv
23
- @parser = OptionParser.new
24
- @colored = true
25
- @report_class = Report::TextReport
26
- @strategy = Report::Strategy::Quiet
27
- @warning_formatter = Report::WarningFormatterWithLineNumbers
28
- @command_class = ReekCommand
29
- @config_file = nil
30
- @sort_by_issue_count = false
31
- @smells_to_detect = []
32
- set_options
28
+ def set_up_parser
29
+ set_banner
30
+ set_configuration_options
31
+ set_alternative_formatter_options
32
+ set_report_formatting_options
33
+ set_utility_options
33
34
  end
34
35
 
35
- def banner
36
- progname = @parser.program_name
37
- <<-EOB.gsub(/^[ ]+/, '')
38
- Usage: #{progname} [options] [files]
36
+ def set_banner
37
+ program_name = @parser.program_name
38
+ @parser.banner = <<-EOB.gsub(/^[ ]+/, '')
39
+ Usage: #{program_name} [options] [files]
39
40
 
40
41
  Examples:
41
42
 
42
- #{progname} lib/*.rb
43
- #{progname} -q lib
44
- cat my_class.rb | #{progname}
43
+ #{program_name} lib/*.rb
44
+ #{program_name} -s lib
45
+ cat my_class.rb | #{program_name}
45
46
 
46
47
  See http://wiki.github.com/troessner/reek for detailed help.
47
48
 
48
49
  EOB
49
50
  end
50
51
 
51
- def set_options
52
- @parser.banner = banner
53
- @parser.separator 'Common options:'
54
- @parser.on('-h', '--help', 'Show this message') do
55
- @command_class = HelpCommand
56
- end
57
- @parser.on('-v', '--version', 'Show version') do
58
- @command_class = VersionCommand
52
+ def set_alternative_formatter_options
53
+ @parser.separator "\nReport format:"
54
+ @parser.on(
55
+ '-f', '--format FORMAT', [:html, :text, :yaml],
56
+ 'Report smells in the given format:',
57
+ ' html', ' text (default)', ' yaml'
58
+ ) do |opt|
59
+ @options.report_format = opt
59
60
  end
61
+ end
60
62
 
61
- @parser.separator "\nConfiguration:"
63
+ def set_configuration_options
64
+ @parser.separator 'Configuration:'
62
65
  @parser.on('-c', '--config FILE', 'Read configuration options from FILE') do |file|
63
- @config_file = file
66
+ @options.config_file = file
64
67
  end
65
68
  @parser.on('--smell SMELL', 'Detect smell SMELL (default is all enabled smells)') do |smell|
66
- @smells_to_detect << smell
69
+ @options.smells_to_detect << smell
67
70
  end
71
+ end
68
72
 
69
- @parser.separator "\nReport formatting:"
70
- @parser.on('-o', '--[no-]color', 'Use colors for the output (this is the default)') do |opt|
71
- @colored = opt
72
- end
73
- @parser.on('-q', '--quiet', 'Suppress headings for smell-free source files (this is the default)') do |_opt|
74
- @strategy = Report::Strategy::Quiet
75
- end
76
- @parser.on('-V', '--no-quiet', '--verbose', 'Show headings for smell-free source files') do |_opt|
77
- @strategy = Report::Strategy::Verbose
78
- end
79
- @parser.on('-U', '--ultra-verbose', 'Be as explanatory as possible') do |_opt|
80
- @warning_formatter = Report::UltraVerboseWarningFormattter
81
- end
82
- @parser.on('-n', '--no-line-numbers', 'Suppress line numbers from the output') do
83
- @warning_formatter = Report::SimpleWarningFormatter
84
- end
85
- @parser.on('--line-numbers', 'Show line numbers in the output (this is the default)') do
86
- @warning_formatter = Report::WarningFormatterWithLineNumbers
87
- end
88
- @parser.on('-s', '--single-line', 'Show IDE-compatible single-line-per-warning') do
89
- @warning_formatter = Report::SingleLineWarningFormatter
90
- end
91
- @parser.on('-S', '--sort-by-issue-count', 'Sort by "issue-count", listing the "smelliest" files first') do
92
- @sort_by_issue_count = true
93
- end
94
- @parser.on('-y', '--yaml', 'Report smells in YAML format') do
95
- @report_class = Report::YamlReport
96
- end
97
- @parser.on('-H', '--html', 'Report smells in HTML format') do
98
- @report_class = Report::HtmlReport
73
+ def set_report_formatting_options
74
+ @parser.separator "\nText format options:"
75
+ set_up_color_option
76
+ set_up_verbosity_options
77
+ set_up_location_formatting_options
78
+ set_up_sorting_option
79
+ end
80
+
81
+ def set_up_color_option
82
+ @parser.on('--[no-]color', 'Use colors for the output (this is the default)') do |opt|
83
+ @options.colored = opt
99
84
  end
100
85
  end
101
86
 
102
- def parse
103
- @parser.parse!(@argv)
104
- Rainbow.enabled = @colored
105
- @command_class.new(self)
87
+ def set_up_verbosity_options
88
+ @parser.on('-V', '--[no-]empty-headings',
89
+ 'Show headings for smell-free source files') do |show_empty|
90
+ @options.show_empty = show_empty
91
+ end
92
+ @parser.on('-U', '--[no-]wiki-links',
93
+ 'Show link to related Reek wiki page for each smell') do |show_links|
94
+ @options.show_links = show_links
95
+ end
106
96
  end
107
97
 
108
- def reporter
109
- @reporter ||= @report_class.new(warning_formatter: @warning_formatter,
110
- report_formatter: Report::Formatter,
111
- sort_by_issue_count: @sort_by_issue_count,
112
- strategy: @strategy)
98
+ def set_up_location_formatting_options
99
+ @parser.on('-n', '--[no-]line-numbers',
100
+ 'Show line numbers in the output (this is the default)') do |show_numbers|
101
+ @options.location_format = show_numbers ? :numbers : :plain
102
+ end
103
+ @parser.on('-s', '--single-line',
104
+ 'Show location in editor-compatible single-line-per-smell format') do
105
+ @options.location_format = :single_line
106
+ end
113
107
  end
114
108
 
115
- def program_name
116
- @parser.program_name
109
+ def set_up_sorting_option
110
+ @parser.on('--sort-by SORTING', [:smelliness, :none],
111
+ 'Sort reported files by the given criterium:',
112
+ ' smelliness ("smelliest" files first)',
113
+ ' none (default - output in processing order)') do |sorting|
114
+ @options.sorting = sorting
115
+ end
117
116
  end
118
117
 
119
- def help_text
120
- @parser.to_s
118
+ def set_utility_options
119
+ @parser.separator "\nUtility options:"
120
+ @parser.on_tail('-h', '--help', 'Show this message') do
121
+ puts @parser
122
+ exit
123
+ end
124
+ @parser.on_tail('-v', '--version', 'Show version') do
125
+ puts "#{@parser.program_name} #{Reek::VERSION}\n"
126
+ exit
127
+ end
121
128
  end
122
129
  end
123
130
  end