reek 3.2.1 → 3.3.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.md +5 -0
- data/Rakefile +0 -1
- data/config/defaults.reek +1 -1
- data/features/samples.feature +17 -16
- data/lib/reek.rb +0 -1
- data/lib/reek/ast/ast_node_class_map.rb +5 -1
- data/lib/reek/ast/node.rb +10 -3
- data/lib/reek/ast/object_refs.rb +11 -5
- data/lib/reek/ast/reference_collector.rb +6 -2
- data/lib/reek/ast/sexp_extensions.rb +42 -1
- data/lib/reek/ast/sexp_formatter.rb +2 -1
- data/lib/reek/cli/application.rb +12 -9
- data/lib/reek/cli/command.rb +6 -0
- data/lib/reek/cli/input.rb +4 -4
- data/lib/reek/cli/option_interpreter.rb +11 -7
- data/lib/reek/cli/options.rb +42 -40
- data/lib/reek/cli/reek_command.rb +3 -3
- data/lib/reek/cli/silencer.rb +12 -3
- data/lib/reek/cli/warning_collector.rb +8 -3
- data/lib/reek/code_comment.rb +6 -1
- data/lib/reek/configuration/app_configuration.rb +65 -100
- data/lib/reek/configuration/configuration_file_finder.rb +4 -13
- data/lib/reek/configuration/configuration_validator.rb +35 -0
- data/lib/reek/configuration/default_directive.rb +12 -0
- data/lib/reek/configuration/directory_directives.rb +54 -0
- data/lib/reek/configuration/excluded_paths.rb +18 -0
- data/lib/reek/context/code_context.rb +19 -17
- data/lib/reek/examiner.rb +9 -7
- data/lib/reek/rake/task.rb +12 -22
- data/lib/reek/report/formatter.rb +6 -1
- data/lib/reek/report/report.rb +22 -13
- data/lib/reek/smells/attribute.rb +6 -53
- data/lib/reek/smells/control_parameter.rb +21 -13
- data/lib/reek/smells/data_clump.rb +17 -9
- data/lib/reek/smells/duplicate_method_call.rb +12 -6
- data/lib/reek/smells/long_parameter_list.rb +2 -2
- data/lib/reek/smells/long_yield_list.rb +4 -4
- data/lib/reek/smells/nested_iterators.rb +4 -2
- data/lib/reek/smells/nil_check.rb +6 -2
- data/lib/reek/smells/repeated_conditional.rb +3 -3
- data/lib/reek/smells/smell_configuration.rb +17 -7
- data/lib/reek/smells/smell_detector.rb +24 -11
- data/lib/reek/smells/smell_repository.rb +1 -1
- data/lib/reek/smells/smell_warning.rb +6 -6
- data/lib/reek/smells/too_many_instance_variables.rb +2 -2
- data/lib/reek/smells/too_many_methods.rb +4 -4
- data/lib/reek/smells/too_many_statements.rb +4 -4
- data/lib/reek/smells/uncommunicative_method_name.rb +5 -5
- data/lib/reek/smells/uncommunicative_module_name.rb +6 -6
- data/lib/reek/smells/uncommunicative_parameter_name.rb +8 -4
- data/lib/reek/smells/uncommunicative_variable_name.rb +9 -5
- data/lib/reek/smells/utility_function.rb +1 -1
- data/lib/reek/source/source_code.rb +5 -1
- data/lib/reek/source/source_locator.rb +3 -2
- data/lib/reek/spec.rb +3 -3
- data/lib/reek/spec/should_reek.rb +10 -5
- data/lib/reek/spec/should_reek_of.rb +9 -6
- data/lib/reek/spec/should_reek_only_of.rb +13 -8
- data/lib/reek/tree_dresser.rb +6 -2
- data/lib/reek/tree_walker.rb +40 -32
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +1 -1
- data/spec/reek/ast/node_spec.rb +1 -2
- data/spec/reek/ast/object_refs_spec.rb +40 -42
- data/spec/reek/ast/sexp_extensions_spec.rb +98 -104
- data/spec/reek/cli/warning_collector_spec.rb +8 -12
- data/spec/reek/code_comment_spec.rb +3 -5
- data/spec/reek/configuration/app_configuration_spec.rb +43 -57
- data/spec/reek/configuration/configuration_file_finder_spec.rb +5 -7
- data/spec/reek/configuration/default_directive_spec.rb +13 -0
- data/spec/reek/configuration/directory_directives_spec.rb +89 -0
- data/spec/reek/configuration/excluded_paths_spec.rb +30 -0
- data/spec/reek/context/code_context_spec.rb +63 -62
- data/spec/reek/context/method_context_spec.rb +8 -12
- data/spec/reek/context/module_context_spec.rb +1 -1
- data/spec/reek/context/root_context_spec.rb +3 -7
- data/spec/reek/examiner_spec.rb +14 -25
- data/spec/reek/smells/attribute_spec.rb +2 -4
- data/spec/reek/smells/boolean_parameter_spec.rb +5 -7
- data/spec/reek/smells/class_variable_spec.rb +29 -44
- data/spec/reek/smells/control_parameter_spec.rb +7 -9
- data/spec/reek/smells/data_clump_spec.rb +25 -32
- data/spec/reek/smells/duplicate_method_call_spec.rb +8 -7
- data/spec/reek/smells/feature_envy_spec.rb +16 -17
- data/spec/reek/smells/irresponsible_module_spec.rb +2 -4
- data/spec/reek/smells/long_parameter_list_spec.rb +6 -9
- data/spec/reek/smells/long_yield_list_spec.rb +6 -9
- data/spec/reek/smells/nested_iterators_spec.rb +14 -16
- data/spec/reek/smells/repeated_conditional_spec.rb +25 -25
- data/spec/reek/smells/smell_configuration_spec.rb +32 -27
- data/spec/reek/smells/smell_detector_shared.rb +12 -13
- data/spec/reek/smells/smell_warning_spec.rb +54 -58
- data/spec/reek/smells/too_many_instance_variables_spec.rb +9 -9
- data/spec/reek/smells/too_many_methods_spec.rb +13 -14
- data/spec/reek/smells/too_many_statements_spec.rb +8 -10
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +8 -9
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -13
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +7 -10
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +16 -20
- data/spec/reek/smells/utility_function_spec.rb +11 -15
- data/spec/reek/source/source_code_spec.rb +6 -11
- data/spec/reek/spec/should_reek_of_spec.rb +19 -30
- data/spec/reek/spec/should_reek_only_of_spec.rb +28 -34
- data/spec/reek/tree_walker_spec.rb +14 -2
- data/spec/spec_helper.rb +2 -3
- data/tasks/test.rake +0 -5
- metadata +10 -6
- data/docs/Configuration-Files.md +0 -49
- data/spec/gem/updates_spec.rb +0 -25
- data/spec/gem/yard_spec.rb +0 -11
- data/spec/reek/smells/behaves_like_variable_detector.rb +0 -39
@@ -18,21 +18,12 @@ module Reek
|
|
18
18
|
module ConfigurationFileFinder
|
19
19
|
module_function
|
20
20
|
|
21
|
-
def find_and_load(
|
22
|
-
load_from_file(find(
|
21
|
+
def find_and_load(path: nil)
|
22
|
+
load_from_file(find(path: path))
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
def find(params = {})
|
28
|
-
options = params.fetch(:options) { nil }
|
29
|
-
current = params.fetch(:current) { Pathname.pwd }
|
30
|
-
home = params.fetch(:home) { Pathname.new(Dir.home) }
|
31
|
-
find_by_cli(options) || find_by_dir(current) || find_by_dir(home)
|
32
|
-
end
|
33
|
-
|
34
|
-
def find_by_cli(options)
|
35
|
-
options && options.config_file
|
25
|
+
def find(path: nil, current: Pathname.pwd, home: Pathname.new(Dir.home))
|
26
|
+
path || find_by_dir(current) || find_by_dir(home)
|
36
27
|
end
|
37
28
|
|
38
29
|
def find_by_dir(start)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Reek
|
2
|
+
module Configuration
|
3
|
+
#
|
4
|
+
# Configuration validator module.
|
5
|
+
#
|
6
|
+
module ConfigurationValidator
|
7
|
+
private
|
8
|
+
|
9
|
+
def smell_type?(key)
|
10
|
+
Reek::Smells.const_get key
|
11
|
+
rescue NameError
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
def error_message_for_missing_directory(pathname)
|
16
|
+
"Configuration error: Directory `#{pathname}` does not exist"
|
17
|
+
end
|
18
|
+
|
19
|
+
def error_message_for_file_given(pathname)
|
20
|
+
"Configuration error: `#{pathname}` is supposed to be a directory but is a file"
|
21
|
+
end
|
22
|
+
|
23
|
+
def validate_directory(pathname)
|
24
|
+
abort(error_message_for_missing_directory(pathname)) unless pathname.exist?
|
25
|
+
abort(error_message_for_file_given(pathname)) if pathname.file?
|
26
|
+
end
|
27
|
+
|
28
|
+
def with_valid_directory(path)
|
29
|
+
directory = Pathname.new path.to_s.chomp('/')
|
30
|
+
validate_directory directory
|
31
|
+
yield directory if block_given?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative './configuration_validator'
|
2
|
+
|
3
|
+
module Reek
|
4
|
+
module Configuration
|
5
|
+
#
|
6
|
+
# Hash extension for directory directives.
|
7
|
+
#
|
8
|
+
module DirectoryDirectives
|
9
|
+
include ConfigurationValidator
|
10
|
+
|
11
|
+
# Returns the directive for a given source.
|
12
|
+
#
|
13
|
+
# @param source_via [String] the source of the code inspected
|
14
|
+
#
|
15
|
+
# @return [Hash | nil] the configuration for the source or nil
|
16
|
+
def directive_for(source_via)
|
17
|
+
return unless source_via
|
18
|
+
source_base_dir = Pathname.new(source_via).dirname
|
19
|
+
hit = best_match_for source_base_dir
|
20
|
+
self[hit]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Adds a directive and returns self.
|
24
|
+
#
|
25
|
+
# @param path [Pathname] the path
|
26
|
+
# @param config [Hash] the configuration
|
27
|
+
#
|
28
|
+
# @return [self]
|
29
|
+
def add(path, config)
|
30
|
+
with_valid_directory(path) do |directory|
|
31
|
+
self[directory] = config.each_with_object({}) do |(key, value), hash|
|
32
|
+
abort(error_message_for_invalid_smell_type(key)) unless smell_type?(key)
|
33
|
+
hash[Reek::Smells.const_get(key)] = value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def best_match_for(source_base_dir)
|
42
|
+
keys.
|
43
|
+
select { |pathname| source_base_dir.to_s.match(/#{Regexp.escape(pathname.to_s)}/) }.
|
44
|
+
max_by { |pathname| pathname.to_s.length }
|
45
|
+
end
|
46
|
+
|
47
|
+
def error_message_for_invalid_smell_type(klass)
|
48
|
+
"You are trying to configure smell type #{klass} but we can't find one with that name.\n" \
|
49
|
+
"Please make sure you spelled it right (see 'config/defaults.reek' in the reek\n" \
|
50
|
+
'repository for a list of all available smell types.'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative './configuration_validator'
|
2
|
+
|
3
|
+
module Reek
|
4
|
+
module Configuration
|
5
|
+
#
|
6
|
+
# Hash extension for excluded paths.
|
7
|
+
#
|
8
|
+
module ExcludedPaths
|
9
|
+
include ConfigurationValidator
|
10
|
+
|
11
|
+
def add(paths)
|
12
|
+
paths.each do |path|
|
13
|
+
with_valid_directory(path) { |directory| self << directory }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -70,11 +70,11 @@ module Reek
|
|
70
70
|
# @param child [CodeContext] the child context to register
|
71
71
|
def append_child_context(child)
|
72
72
|
child.visibility = tracked_visibility
|
73
|
-
|
73
|
+
children << child
|
74
74
|
end
|
75
75
|
|
76
76
|
def count_statements(num)
|
77
|
-
|
77
|
+
self.num_statements += num
|
78
78
|
end
|
79
79
|
|
80
80
|
def record_call_to(exp)
|
@@ -83,19 +83,19 @@ module Reek
|
|
83
83
|
case type
|
84
84
|
when :lvar, :lvasgn
|
85
85
|
unless exp.object_creation_call?
|
86
|
-
|
86
|
+
refs.record_reference_to(receiver.name, line: exp.line)
|
87
87
|
end
|
88
88
|
when :self
|
89
|
-
|
89
|
+
refs.record_reference_to(:self, line: exp.line)
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
93
|
def record_use_of_self
|
94
|
-
|
94
|
+
refs.record_reference_to(:self)
|
95
95
|
end
|
96
96
|
|
97
97
|
def name
|
98
|
-
|
98
|
+
exp.name
|
99
99
|
end
|
100
100
|
|
101
101
|
def local_nodes(type, &blk)
|
@@ -103,7 +103,7 @@ module Reek
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def each_node(type, ignoring, &blk)
|
106
|
-
|
106
|
+
exp.each_node(type, ignoring, &blk)
|
107
107
|
end
|
108
108
|
|
109
109
|
def matches?(candidates)
|
@@ -119,8 +119,7 @@ module Reek
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def full_name
|
122
|
-
context
|
123
|
-
exp.full_name(context)
|
122
|
+
exp.full_name(context ? context.full_name : '')
|
124
123
|
end
|
125
124
|
|
126
125
|
def config_for(detector_class)
|
@@ -140,46 +139,49 @@ module Reek
|
|
140
139
|
# @param names [Array<Symbol>]
|
141
140
|
def track_visibility(visibility, names = [])
|
142
141
|
if names.any?
|
143
|
-
|
142
|
+
children.each do |child|
|
144
143
|
child.visibility = visibility if names.include? child.name
|
145
144
|
end
|
146
145
|
else
|
147
|
-
|
146
|
+
self.tracked_visibility = visibility
|
148
147
|
end
|
149
148
|
end
|
150
149
|
|
151
150
|
def type
|
152
|
-
|
151
|
+
exp.type
|
153
152
|
end
|
154
153
|
|
155
154
|
# Iterate over +self+ and child contexts.
|
156
155
|
def each(&block)
|
157
156
|
yield self
|
158
|
-
|
157
|
+
children.each do |child|
|
159
158
|
child.each(&block)
|
160
159
|
end
|
161
160
|
end
|
162
161
|
|
163
162
|
protected
|
164
163
|
|
165
|
-
attr_writer :visibility
|
164
|
+
attr_writer :num_statements, :visibility
|
166
165
|
|
167
166
|
private
|
168
167
|
|
168
|
+
private_attr_writer :tracked_visibility
|
169
|
+
private_attr_reader :context, :refs
|
170
|
+
|
169
171
|
def tracked_visibility
|
170
172
|
@tracked_visibility ||= :public
|
171
173
|
end
|
172
174
|
|
173
175
|
def config
|
174
|
-
@config ||= if
|
175
|
-
CodeComment.new(
|
176
|
+
@config ||= if exp
|
177
|
+
CodeComment.new(exp.full_comment || '').config
|
176
178
|
else
|
177
179
|
{}
|
178
180
|
end
|
179
181
|
end
|
180
182
|
|
181
183
|
def context_config_for(detector_class)
|
182
|
-
|
184
|
+
context ? context.config_for(detector_class) : {}
|
183
185
|
end
|
184
186
|
end
|
185
187
|
end
|
data/lib/reek/examiner.rb
CHANGED
@@ -26,7 +26,7 @@ module Reek
|
|
26
26
|
#
|
27
27
|
def initialize(source,
|
28
28
|
filter_by_smells = [],
|
29
|
-
configuration: Configuration::AppConfiguration.
|
29
|
+
configuration: Configuration::AppConfiguration.default)
|
30
30
|
@source = Source::SourceCode.from(source)
|
31
31
|
@configuration = configuration
|
32
32
|
@collector = CLI::WarningCollector.new
|
@@ -39,14 +39,14 @@ module Reek
|
|
39
39
|
# @return [String] description of the source being analysed
|
40
40
|
#
|
41
41
|
def description
|
42
|
-
@description ||=
|
42
|
+
@description ||= source.description
|
43
43
|
end
|
44
44
|
|
45
45
|
#
|
46
46
|
# @return [Array<SmellWarning>] the smells found in the source
|
47
47
|
#
|
48
48
|
def smells
|
49
|
-
@smells ||=
|
49
|
+
@smells ||= collector.warnings
|
50
50
|
end
|
51
51
|
|
52
52
|
#
|
@@ -65,13 +65,15 @@ module Reek
|
|
65
65
|
|
66
66
|
private
|
67
67
|
|
68
|
+
private_attr_reader :configuration, :collector, :smell_types, :source
|
69
|
+
|
68
70
|
def run
|
69
71
|
smell_repository = Smells::SmellRepository.new(source_description: description,
|
70
|
-
smell_types:
|
71
|
-
configuration:
|
72
|
-
syntax_tree =
|
72
|
+
smell_types: smell_types,
|
73
|
+
configuration: configuration)
|
74
|
+
syntax_tree = source.syntax_tree
|
73
75
|
TreeWalker.new(smell_repository, syntax_tree).walk if syntax_tree
|
74
|
-
smell_repository.report_on(
|
76
|
+
smell_repository.report_on(collector)
|
75
77
|
end
|
76
78
|
|
77
79
|
def eligible_smell_types(filter_by_smells = [])
|
data/lib/reek/rake/task.rb
CHANGED
@@ -39,17 +39,17 @@ module Reek
|
|
39
39
|
|
40
40
|
# Path to reek's config file.
|
41
41
|
# Setting the REEK_CFG environment variable overrides this.
|
42
|
-
|
42
|
+
attr_accessor :config_file
|
43
43
|
|
44
44
|
# Glob pattern to match source files.
|
45
45
|
# Setting the REEK_SRC environment variable overrides this.
|
46
46
|
# Defaults to 'lib/**/*.rb'.
|
47
|
-
|
47
|
+
attr_accessor :source_files
|
48
48
|
|
49
49
|
# String containing commandline options to be passed to Reek.
|
50
50
|
# Setting the REEK_OPTS environment variable overrides this value.
|
51
51
|
# Defaults to ''.
|
52
|
-
|
52
|
+
attr_accessor :reek_opts
|
53
53
|
|
54
54
|
# Whether or not to fail Rake when an error occurs (typically when smells are found).
|
55
55
|
# Defaults to true.
|
@@ -60,10 +60,11 @@ module Reek
|
|
60
60
|
attr_writer :verbose
|
61
61
|
|
62
62
|
def initialize(name = :reek)
|
63
|
+
@config_file = ENV['REEK_CFG']
|
63
64
|
@name = name
|
64
|
-
@reek_opts = ''
|
65
|
+
@reek_opts = ENV['REEK_OPTS'] || ''
|
65
66
|
@fail_on_error = true
|
66
|
-
@source_files = 'lib/**/*.rb'
|
67
|
+
@source_files = FileList[ENV['REEK_SRC'] || 'lib/**/*.rb']
|
67
68
|
@verbose = false
|
68
69
|
|
69
70
|
yield self if block_given?
|
@@ -72,15 +73,17 @@ module Reek
|
|
72
73
|
|
73
74
|
private
|
74
75
|
|
76
|
+
private_attr_reader :fail_on_error, :name, :verbose
|
77
|
+
|
75
78
|
def define_task
|
76
79
|
desc 'Check for code smells'
|
77
|
-
task(
|
80
|
+
task(name) { run_task }
|
78
81
|
end
|
79
82
|
|
80
83
|
def run_task
|
81
|
-
puts "\n\n!!! Running 'reek' rake command: #{command}\n\n" if
|
84
|
+
puts "\n\n!!! Running 'reek' rake command: #{command}\n\n" if verbose
|
82
85
|
system(*command)
|
83
|
-
abort("\n\n!!! `reek` has found smells - exiting!") if sys_call_failed? &&
|
86
|
+
abort("\n\n!!! `reek` has found smells - exiting!") if sys_call_failed? && fail_on_error
|
84
87
|
end
|
85
88
|
|
86
89
|
def command
|
@@ -89,25 +92,12 @@ module Reek
|
|
89
92
|
reject(&:empty?)
|
90
93
|
end
|
91
94
|
|
92
|
-
def source_files
|
93
|
-
FileList[ENV['REEK_SRC'] || @source_files]
|
94
|
-
end
|
95
|
-
|
96
|
-
def reek_opts
|
97
|
-
ENV['REEK_OPTS'] || @reek_opts
|
98
|
-
end
|
99
|
-
|
100
|
-
def config_file
|
101
|
-
ENV['REEK_CFG'] || @config_file
|
102
|
-
end
|
103
|
-
|
104
95
|
def sys_call_failed?
|
105
96
|
!$CHILD_STATUS.success?
|
106
97
|
end
|
107
98
|
|
108
99
|
def config_file_as_argument
|
109
|
-
|
110
|
-
['-c', @config_file]
|
100
|
+
config_file ? ['-c', config_file] : []
|
111
101
|
end
|
112
102
|
|
113
103
|
def reek_opts_as_arguments
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'private_attr/everywhere'
|
1
2
|
require_relative 'location_formatter'
|
2
3
|
|
3
4
|
module Reek
|
@@ -35,7 +36,7 @@ module Reek
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def format(warning)
|
38
|
-
"#{
|
39
|
+
"#{location_formatter.format(warning)}#{base_format(warning)}"
|
39
40
|
end
|
40
41
|
|
41
42
|
private
|
@@ -43,6 +44,10 @@ module Reek
|
|
43
44
|
def base_format(warning)
|
44
45
|
"#{warning.context} #{warning.message} (#{warning.smell_type})"
|
45
46
|
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
private_attr_reader :location_formatter
|
46
51
|
end
|
47
52
|
|
48
53
|
#
|
data/lib/reek/report/report.rb
CHANGED
@@ -30,8 +30,8 @@ module Reek
|
|
30
30
|
#
|
31
31
|
# @param [Reek::Examiner] examiner object to report on
|
32
32
|
def add_examiner(examiner)
|
33
|
-
|
34
|
-
|
33
|
+
self.total_smell_count += examiner.smells_count
|
34
|
+
examiners << examiner
|
35
35
|
self
|
36
36
|
end
|
37
37
|
|
@@ -42,13 +42,22 @@ module Reek
|
|
42
42
|
|
43
43
|
# @api private
|
44
44
|
def smells?
|
45
|
-
|
45
|
+
total_smell_count > 0
|
46
46
|
end
|
47
47
|
|
48
48
|
# @api private
|
49
49
|
def smells
|
50
|
-
|
50
|
+
examiners.map(&:smells).flatten
|
51
51
|
end
|
52
|
+
|
53
|
+
protected
|
54
|
+
|
55
|
+
attr_accessor :total_smell_count
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
private_attr_reader :examiners, :options, :report_formatter,
|
60
|
+
:sort_by_issue_count, :warning_formatter
|
52
61
|
end
|
53
62
|
|
54
63
|
#
|
@@ -64,7 +73,7 @@ module Reek
|
|
64
73
|
private
|
65
74
|
|
66
75
|
def smell_summaries
|
67
|
-
|
76
|
+
examiners.map { |ex| summarize_single_examiner(ex) }.reject(&:empty?)
|
68
77
|
end
|
69
78
|
|
70
79
|
def display_summary
|
@@ -72,33 +81,33 @@ module Reek
|
|
72
81
|
end
|
73
82
|
|
74
83
|
def display_total_smell_count
|
75
|
-
return unless
|
84
|
+
return unless examiners.size > 1
|
76
85
|
print total_smell_count_message
|
77
86
|
end
|
78
87
|
|
79
88
|
def summarize_single_examiner(examiner)
|
80
89
|
result = heading_formatter.header(examiner)
|
81
90
|
if examiner.smelly?
|
82
|
-
formatted_list =
|
83
|
-
|
91
|
+
formatted_list = report_formatter.format_list(examiner.smells,
|
92
|
+
warning_formatter)
|
84
93
|
result += ":\n#{formatted_list}"
|
85
94
|
end
|
86
95
|
result
|
87
96
|
end
|
88
97
|
|
89
98
|
def sort_examiners
|
90
|
-
|
99
|
+
examiners.sort_by!(&:smells_count).reverse! if sort_by_issue_count
|
91
100
|
end
|
92
101
|
|
93
102
|
def total_smell_count_message
|
94
103
|
colour = smells? ? WARNINGS_COLOR : NO_WARNINGS_COLOR
|
95
|
-
s =
|
96
|
-
Rainbow("#{
|
104
|
+
s = total_smell_count == 1 ? '' : 's'
|
105
|
+
Rainbow("#{total_smell_count} total warning#{s}\n").color(colour)
|
97
106
|
end
|
98
107
|
|
99
108
|
def heading_formatter
|
100
109
|
@heading_formatter ||=
|
101
|
-
|
110
|
+
options.fetch(:heading_formatter, HeadingFormatter::Quiet).new(report_formatter)
|
102
111
|
end
|
103
112
|
end
|
104
113
|
|
@@ -118,7 +127,7 @@ module Reek
|
|
118
127
|
def show
|
119
128
|
print ::JSON.generate(
|
120
129
|
smells.map do |smell|
|
121
|
-
smell.yaml_hash(
|
130
|
+
smell.yaml_hash(warning_formatter)
|
122
131
|
end
|
123
132
|
)
|
124
133
|
end
|