reek 1.6.6 → 2.0.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/CHANGELOG +6 -9
- data/features/command_line_interface/options.feature +20 -16
- data/features/command_line_interface/stdin.feature +1 -1
- data/features/rake_task/rake_task.feature +0 -12
- data/features/reports/reports.feature +63 -23
- data/features/reports/yaml.feature +3 -3
- data/features/samples.feature +3 -3
- data/lib/reek/cli/application.rb +5 -5
- data/lib/reek/cli/input.rb +1 -1
- data/lib/reek/cli/option_interpreter.rb +77 -0
- data/lib/reek/cli/options.rb +89 -82
- data/lib/reek/cli/report/formatter.rb +33 -24
- data/lib/reek/cli/report/heading_formatter.rb +45 -0
- data/lib/reek/cli/report/location_formatter.rb +23 -0
- data/lib/reek/cli/report/report.rb +32 -17
- data/lib/reek/configuration/app_configuration.rb +2 -2
- data/lib/reek/configuration/configuration_file_finder.rb +10 -10
- data/lib/reek/core/smell_repository.rb +3 -28
- data/lib/reek/rake/task.rb +35 -76
- data/lib/reek/smell_warning.rb +31 -16
- data/lib/reek/smells/nested_iterators.rb +1 -1
- data/lib/reek/smells/smell_detector.rb +9 -0
- data/lib/reek/smells/utility_function.rb +2 -1
- data/lib/reek/spec/should_reek.rb +0 -3
- data/lib/reek/spec/should_reek_of.rb +61 -12
- data/lib/reek/spec/should_reek_only_of.rb +12 -10
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +2 -2
- data/spec/factories/factories.rb +2 -5
- data/spec/reek/cli/html_report_spec.rb +28 -0
- data/spec/reek/cli/option_interperter_spec.rb +14 -0
- data/spec/reek/cli/text_report_spec.rb +95 -0
- data/spec/reek/cli/yaml_report_spec.rb +23 -0
- data/spec/reek/configuration/configuration_file_finder_spec.rb +5 -6
- data/spec/reek/core/module_context_spec.rb +1 -1
- data/spec/reek/core/smell_repository_spec.rb +17 -0
- data/spec/reek/smell_warning_spec.rb +9 -11
- data/spec/reek/smells/boolean_parameter_spec.rb +11 -11
- data/spec/reek/smells/control_parameter_spec.rb +40 -40
- data/spec/reek/smells/data_clump_spec.rb +17 -17
- data/spec/reek/smells/duplicate_method_call_spec.rb +56 -33
- data/spec/reek/smells/feature_envy_spec.rb +44 -40
- data/spec/reek/smells/irresponsible_module_spec.rb +1 -1
- data/spec/reek/smells/long_parameter_list_spec.rb +12 -12
- data/spec/reek/smells/long_yield_list_spec.rb +4 -4
- data/spec/reek/smells/module_initialize_spec.rb +3 -3
- data/spec/reek/smells/nested_iterators_spec.rb +71 -52
- data/spec/reek/smells/nil_check_spec.rb +6 -6
- data/spec/reek/smells/prima_donna_method_spec.rb +2 -2
- data/spec/reek/smells/too_many_statements_spec.rb +34 -34
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +1 -1
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +7 -3
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +12 -12
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +28 -38
- data/spec/reek/smells/unused_parameters_spec.rb +16 -17
- data/spec/reek/smells/utility_function_spec.rb +21 -8
- data/spec/reek/spec/should_reek_of_spec.rb +18 -5
- data/spec/reek/spec/should_reek_only_of_spec.rb +7 -1
- data/spec/spec_helper.rb +22 -14
- metadata +15 -20
- data/lib/reek/cli/help_command.rb +0 -15
- data/lib/reek/cli/report/strategy.rb +0 -64
- data/lib/reek/cli/version_command.rb +0 -16
- data/spec/matchers/smell_of_matcher.rb +0 -95
- data/spec/reek/cli/help_command_spec.rb +0 -25
- data/spec/reek/cli/report_spec.rb +0 -132
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e9938a6d72e1e64ab84f0cbfc67d43574a0d9b8
|
4
|
+
data.tar.gz: 102ac522a9e2df22fbbec630f09d97174e4e5bd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7b67443588cd094db2a47cd4fddf96190ea87c4c44e68fe6620f86638346e1dc38ad9e84941e6939360765762738b3fa5902289db52f2fa1ef1e78066b412ef
|
7
|
+
data.tar.gz: 16a5d7d2c2750e4a7d1324ca9bb6076fb3caad8eb929fb319dff712e895c6ffe73420e4f914317a5981f26300dc3fe5f1c926e36e69dd1ed7b1bbed0214ff2a8
|
data/CHANGELOG
CHANGED
@@ -1,14 +1,11 @@
|
|
1
|
-
==
|
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 -
|
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
|
42
|
-
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
-
|
50
|
-
-
|
51
|
-
-
|
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
|
"""
|
@@ -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:
|
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
|
-
| -
|
77
|
-
| --sort-by
|
81
|
+
| option |
|
82
|
+
| --sort-by smelliness |
|
83
|
+
| --sort-by s |
|
78
84
|
|
79
|
-
Scenario Outline: good files show no
|
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: --
|
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
|
-
| --
|
107
|
-
| -V
|
108
|
-
| --no-quiet |
|
111
|
+
| option |
|
112
|
+
| --empty-headings |
|
113
|
+
| -V |
|
109
114
|
|
110
|
-
Scenario Outline: --
|
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
|
-
| -
|
122
|
-
| -V --
|
125
|
+
| option |
|
126
|
+
| --no-empty-headings |
|
127
|
+
| -V --no-empty-headings |
|
123
128
|
|
124
|
-
Scenario Outline: --line-
|
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
|
-
| -
|
141
|
-
| --no-line-numbers |
|
142
|
-
| -
|
143
|
-
|
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 --
|
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
|
-
| --
|
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
|
"""
|
data/features/samples.feature
CHANGED
@@ -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 -
|
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 -
|
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 -
|
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
|
"""
|
data/lib/reek/cli/application.rb
CHANGED
@@ -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
|
-
|
19
|
+
options_parser = Options.new(argv)
|
21
20
|
begin
|
22
|
-
@
|
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
|
37
|
+
Configuration::AppConfiguration.initialize_with @options
|
38
38
|
end
|
39
39
|
|
40
40
|
def output(text)
|
data/lib/reek/cli/input.rb
CHANGED
@@ -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
|
data/lib/reek/cli/options.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require 'ostruct'
|
2
3
|
require 'rainbow'
|
3
|
-
require 'reek/cli/
|
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
|
-
|
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
|
-
|
26
|
+
private
|
20
27
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
36
|
-
|
37
|
-
<<-EOB.gsub(/^[ ]+/, '')
|
38
|
-
Usage: #{
|
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
|
-
#{
|
43
|
-
#{
|
44
|
-
cat my_class.rb | #{
|
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
|
52
|
-
@parser.
|
53
|
-
@parser.
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@
|
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
|
-
|
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
|
-
|
70
|
-
@parser.
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
103
|
-
@parser.
|
104
|
-
|
105
|
-
|
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
|
109
|
-
@
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
116
|
-
@parser.
|
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
|
120
|
-
@parser.
|
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
|