reek 3.2 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/reek/ast/ast_node_class_map.rb +1 -5
  4. data/lib/reek/ast/node.rb +2 -4
  5. data/lib/reek/ast/object_refs.rb +5 -9
  6. data/lib/reek/ast/reference_collector.rb +2 -4
  7. data/lib/reek/cli/application.rb +9 -12
  8. data/lib/reek/cli/command.rb +0 -4
  9. data/lib/reek/cli/input.rb +4 -4
  10. data/lib/reek/cli/option_interpreter.rb +7 -11
  11. data/lib/reek/cli/options.rb +40 -42
  12. data/lib/reek/cli/reek_command.rb +3 -3
  13. data/lib/reek/cli/warning_collector.rb +3 -7
  14. data/lib/reek/code_comment.rb +1 -5
  15. data/lib/reek/context/code_context.rb +17 -19
  16. data/lib/reek/examiner.rb +6 -8
  17. data/lib/reek/rake/task.rb +22 -12
  18. data/lib/reek/report/formatter.rb +1 -5
  19. data/lib/reek/report/report.rb +13 -22
  20. data/lib/reek/smells/attribute.rb +6 -9
  21. data/lib/reek/smells/control_parameter.rb +13 -21
  22. data/lib/reek/smells/data_clump.rb +9 -17
  23. data/lib/reek/smells/duplicate_method_call.rb +6 -12
  24. data/lib/reek/smells/long_parameter_list.rb +2 -2
  25. data/lib/reek/smells/long_yield_list.rb +4 -4
  26. data/lib/reek/smells/nested_iterators.rb +2 -4
  27. data/lib/reek/smells/nil_check.rb +2 -6
  28. data/lib/reek/smells/repeated_conditional.rb +2 -2
  29. data/lib/reek/smells/smell_configuration.rb +7 -15
  30. data/lib/reek/smells/smell_detector.rb +10 -23
  31. data/lib/reek/smells/smell_warning.rb +6 -6
  32. data/lib/reek/smells/too_many_instance_variables.rb +2 -2
  33. data/lib/reek/smells/too_many_methods.rb +2 -2
  34. data/lib/reek/smells/too_many_statements.rb +4 -4
  35. data/lib/reek/smells/uncommunicative_method_name.rb +5 -5
  36. data/lib/reek/smells/uncommunicative_module_name.rb +5 -5
  37. data/lib/reek/smells/uncommunicative_parameter_name.rb +4 -8
  38. data/lib/reek/smells/uncommunicative_variable_name.rb +4 -8
  39. data/lib/reek/source/source_code.rb +1 -5
  40. data/lib/reek/spec/should_reek.rb +4 -9
  41. data/lib/reek/spec/should_reek_of.rb +5 -8
  42. data/lib/reek/spec/should_reek_only_of.rb +8 -12
  43. data/lib/reek/tree_dresser.rb +2 -6
  44. data/lib/reek/tree_walker.rb +22 -28
  45. data/lib/reek/version.rb +1 -1
  46. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51661975b3fe585a7de62a86ef3bdd470999cf9d
4
- data.tar.gz: d47b8fc50a340c0effa99b2d19f2bf6b460d8531
3
+ metadata.gz: fe2528f9142f9b45b13b25d3c5b05913ef16f190
4
+ data.tar.gz: b3d969d1feedbe459e2f073f86cbb4d2fb6774da
5
5
  SHA512:
6
- metadata.gz: 1ad047b74e7063afa1ecf570d94e9522bc3b4da8e671abd72c06a7e318b9dc47c5faac7570b67afbca9ffc1c8b766e973594b241c04c62b16914a26d80d57830
7
- data.tar.gz: 6801060d336d6ba4d605797cf32ad6f5df7be22fd44b41964c22b21c73d6a387e902dc63a6c119ec55f5bbf166179c93b471342fd91a33254179ad83567dc812
6
+ metadata.gz: d7a4a4ea2e5bf9cff1a99fa6ca67cc2709bc9cb806f0296acdc7b91ab3a8f7a59217b5d680cad008e33cf0f7887fd62299660f9efde81a978da6ea6b633eae41
7
+ data.tar.gz: 86b336f6aa1c9d9a4e3db2734ac01b35406bd389cef54fa1f67f1b7bbc707847ddabbbc318c257a0f16a8573a96ed08c12a2b9c06d9ee66a0ace9cfd9e03c5e3
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.2.1 (2015-08-17)
6
+
7
+ * Revert 864f0a9 to hotfix issues/642
8
+
5
9
  ## 3.2.0 (2015-08-17)
6
10
 
7
11
  * (mvz) Detect attribute writers created with `attr` in Attribute smell
@@ -13,7 +13,7 @@ module Reek
13
13
  end
14
14
 
15
15
  def klass_for(type)
16
- klass_map[type] ||= Class.new(Node).tap do |klass|
16
+ @klass_map[type] ||= Class.new(Node).tap do |klass|
17
17
  extension = extension_map[type]
18
18
  klass.send :include, extension if extension
19
19
  end
@@ -31,10 +31,6 @@ module Reek
31
31
  Hash[assoc]
32
32
  end
33
33
  end
34
-
35
- private
36
-
37
- private_attr_reader :klass_map
38
34
  end
39
35
  end
40
36
  end
@@ -17,12 +17,12 @@ module Reek
17
17
  end
18
18
 
19
19
  def full_comment
20
- comments.map(&:text).join("\n")
20
+ @comments.map(&:text).join("\n")
21
21
  end
22
22
 
23
23
  def leading_comment
24
24
  line = location.line
25
- comment_lines = comments.select do |comment|
25
+ comment_lines = @comments.select do |comment|
26
26
  comment.location.line < line
27
27
  end
28
28
  comment_lines.map(&:text).join("\n")
@@ -120,8 +120,6 @@ module Reek
120
120
 
121
121
  private
122
122
 
123
- private_attr_reader :comments
124
-
125
123
  def each_sexp
126
124
  children.each { |elem| yield elem if elem.is_a? ::Parser::AST::Node }
127
125
  end
@@ -11,25 +11,21 @@ module Reek
11
11
  end
12
12
 
13
13
  def most_popular
14
- max = refs.values.map(&:size).max
15
- refs.select { |_name, refs| refs.size == max }
14
+ max = @refs.values.map(&:size).max
15
+ @refs.select { |_name, refs| refs.size == max }
16
16
  end
17
17
 
18
18
  def record_reference_to(name, line: nil)
19
- refs[name] << ObjectRef.new(name, line)
19
+ @refs[name] << ObjectRef.new(name, line)
20
20
  end
21
21
 
22
22
  def references_to(name)
23
- refs[name]
23
+ @refs[name]
24
24
  end
25
25
 
26
26
  def self_is_max?
27
- refs.empty? || most_popular.keys.include?(:self)
27
+ @refs.empty? || most_popular.keys.include?(:self)
28
28
  end
29
-
30
- private
31
-
32
- private_attr_reader :refs
33
29
  end
34
30
  end
35
31
  end
@@ -18,16 +18,14 @@ module Reek
18
18
 
19
19
  private
20
20
 
21
- private_attr_reader :ast
22
-
23
21
  def explicit_self_calls
24
22
  [:self, :zsuper, :ivar, :ivasgn].flat_map do |node_type|
25
- ast.each_node(node_type, STOP_NODES)
23
+ @ast.each_node(node_type, STOP_NODES)
26
24
  end
27
25
  end
28
26
 
29
27
  def implicit_self_calls
30
- ast.each_node(:send, STOP_NODES).reject(&:receiver)
28
+ @ast.each_node(:send, STOP_NODES).reject(&:receiver)
31
29
  end
32
30
  end
33
31
  end
@@ -20,9 +20,9 @@ module Reek
20
20
  @status = STATUS_SUCCESS
21
21
  options_parser = Options.new(argv)
22
22
  begin
23
- options = options_parser.parse
24
- @command = ReekCommand.new(OptionInterpreter.new(options))
25
- @configuration = Configuration::AppConfiguration.new(options)
23
+ @options = options_parser.parse
24
+ @command = ReekCommand.new(OptionInterpreter.new(@options))
25
+ @configuration = Configuration::AppConfiguration.new @options
26
26
  rescue OptionParser::InvalidOption, Reek::Configuration::ConfigFileException => error
27
27
  $stderr.puts "Error: #{error}"
28
28
  @status = STATUS_ERROR
@@ -30,9 +30,9 @@ module Reek
30
30
  end
31
31
 
32
32
  def execute
33
- return status if error_occured?
34
- command.execute self
35
- status
33
+ return @status if error_occured?
34
+ @command.execute self
35
+ @status
36
36
  end
37
37
 
38
38
  def output(text)
@@ -40,20 +40,17 @@ module Reek
40
40
  end
41
41
 
42
42
  def report_success
43
- self.status = STATUS_SUCCESS
43
+ @status = STATUS_SUCCESS
44
44
  end
45
45
 
46
46
  def report_smells
47
- self.status = STATUS_SMELLS
47
+ @status = STATUS_SMELLS
48
48
  end
49
49
 
50
50
  private
51
51
 
52
- private_attr_accessor :status
53
- private_attr_reader :command
54
-
55
52
  def error_occured?
56
- status == STATUS_ERROR
53
+ @status == STATUS_ERROR
57
54
  end
58
55
  end
59
56
  end
@@ -10,10 +10,6 @@ module Reek
10
10
  def initialize(options)
11
11
  @options = options
12
12
  end
13
-
14
- private
15
-
16
- private_attr_reader :options
17
13
  end
18
14
  end
19
15
  end
@@ -26,9 +26,9 @@ module Reek
26
26
  end
27
27
 
28
28
  def no_source_files_given?
29
- # At this point we have deleted all options from argv. The only remaining entries
30
- # are paths to the source files. If argv is empty, this means that no files were given.
31
- argv.empty?
29
+ # At this point we have deleted all options from @argv. The only remaining entries
30
+ # are paths to the source files. If @argv is empty, this means that no files were given.
31
+ @argv.empty?
32
32
  end
33
33
 
34
34
  def working_directory_as_source
@@ -36,7 +36,7 @@ module Reek
36
36
  end
37
37
 
38
38
  def sources_from_argv
39
- Source::SourceLocator.new(argv).sources
39
+ Source::SourceLocator.new(@argv).sources
40
40
  end
41
41
 
42
42
  def source_from_pipe
@@ -13,11 +13,11 @@ module Reek
13
13
 
14
14
  extend Forwardable
15
15
 
16
- def_delegators :options, :smells_to_detect
16
+ def_delegators :@options, :smells_to_detect
17
17
 
18
18
  def initialize(options)
19
19
  @options = options
20
- @argv = options.argv
20
+ @argv = @options.argv
21
21
  end
22
22
 
23
23
  def reporter
@@ -30,7 +30,7 @@ module Reek
30
30
  end
31
31
 
32
32
  def report_class
33
- Report.report_class(options.report_format)
33
+ Report.report_class(@options.report_format)
34
34
  end
35
35
 
36
36
  def warning_formatter
@@ -38,24 +38,20 @@ module Reek
38
38
  end
39
39
 
40
40
  def warning_formatter_class
41
- Report.warning_formatter_class(options.show_links ? :wiki_links : :simple)
41
+ Report.warning_formatter_class(@options.show_links ? :wiki_links : :simple)
42
42
  end
43
43
 
44
44
  def location_formatter
45
- Report.location_formatter(options.location_format)
45
+ Report.location_formatter(@options.location_format)
46
46
  end
47
47
 
48
48
  def heading_formatter
49
- Report.heading_formatter(options.show_empty ? :verbose : :quiet)
49
+ Report.heading_formatter(@options.show_empty ? :verbose : :quiet)
50
50
  end
51
51
 
52
52
  def sort_by_issue_count
53
- options.sorting == :smelliness
53
+ @options.sorting == :smelliness
54
54
  end
55
-
56
- private
57
-
58
- private_attr_reader :argv, :options
59
55
  end
60
56
  end
61
57
  end
@@ -23,16 +23,14 @@ module Reek
23
23
  end
24
24
 
25
25
  def parse
26
- parser.parse!(argv)
27
- options.argv = argv
28
- Rainbow.enabled = options.colored
29
- options
26
+ @parser.parse!(@argv)
27
+ @options.argv = @argv
28
+ Rainbow.enabled = @options.colored
29
+ @options
30
30
  end
31
31
 
32
32
  private
33
33
 
34
- private_attr_reader :argv, :options, :parser
35
-
36
34
  def color_support?
37
35
  $stdout.tty?
38
36
  end
@@ -46,8 +44,8 @@ module Reek
46
44
  end
47
45
 
48
46
  def set_banner
49
- program_name = parser.program_name
50
- parser.banner = <<-EOB.gsub(/^[ ]+/, '')
47
+ program_name = @parser.program_name
48
+ @parser.banner = <<-EOB.gsub(/^[ ]+/, '')
51
49
  Usage: #{program_name} [options] [files]
52
50
 
53
51
  Examples:
@@ -62,29 +60,29 @@ module Reek
62
60
  end
63
61
 
64
62
  def set_alternative_formatter_options
65
- parser.separator "\nReport format:"
66
- parser.on(
63
+ @parser.separator "\nReport format:"
64
+ @parser.on(
67
65
  '-f', '--format FORMAT', [:html, :text, :yaml, :json, :xml],
68
66
  'Report smells in the given format:',
69
67
  ' html', ' text (default)', ' yaml', ' json', ' xml'
70
68
  ) do |opt|
71
- options.report_format = opt
69
+ @options.report_format = opt
72
70
  end
73
71
  end
74
72
 
75
73
  def set_configuration_options
76
- parser.separator 'Configuration:'
77
- parser.on('-c', '--config FILE', 'Read configuration options from FILE') do |file|
74
+ @parser.separator 'Configuration:'
75
+ @parser.on('-c', '--config FILE', 'Read configuration options from FILE') do |file|
78
76
  raise ArgumentError, "Config file #{file} doesn't exist" unless File.exist?(file)
79
- options.config_file = Pathname.new(file)
77
+ @options.config_file = Pathname.new(file)
80
78
  end
81
- parser.on('--smell SMELL', 'Detect smell SMELL (default: all enabled smells)') do |smell|
82
- options.smells_to_detect << smell
79
+ @parser.on('--smell SMELL', 'Detect smell SMELL (default: all enabled smells)') do |smell|
80
+ @options.smells_to_detect << smell
83
81
  end
84
82
  end
85
83
 
86
84
  def set_report_formatting_options
87
- parser.separator "\nText format options:"
85
+ @parser.separator "\nText format options:"
88
86
  set_up_color_option
89
87
  set_up_verbosity_options
90
88
  set_up_location_formatting_options
@@ -92,50 +90,50 @@ module Reek
92
90
  end
93
91
 
94
92
  def set_up_color_option
95
- parser.on('--[no-]color', 'Use colors for the output (default: true)') do |opt|
96
- options.colored = opt
93
+ @parser.on('--[no-]color', 'Use colors for the output (default: true)') do |opt|
94
+ @options.colored = opt
97
95
  end
98
96
  end
99
97
 
100
98
  def set_up_verbosity_options
101
- parser.on('-V', '--[no-]empty-headings',
102
- 'Show headings for smell-free source files (default: false)') do |show_empty|
103
- options.show_empty = show_empty
99
+ @parser.on('-V', '--[no-]empty-headings',
100
+ 'Show headings for smell-free source files (default: false)') do |show_empty|
101
+ @options.show_empty = show_empty
104
102
  end
105
- parser.on('-U', '--[no-]wiki-links',
106
- 'Show link to related wiki page for each smell (default: false)') do |show_links|
107
- options.show_links = show_links
103
+ @parser.on('-U', '--[no-]wiki-links',
104
+ 'Show link to related wiki page for each smell (default: false)') do |show_links|
105
+ @options.show_links = show_links
108
106
  end
109
107
  end
110
108
 
111
109
  def set_up_location_formatting_options
112
- parser.on('-n', '--[no-]line-numbers',
113
- 'Show line numbers in the output (default: true)') do |show_numbers|
114
- options.location_format = show_numbers ? :numbers : :plain
110
+ @parser.on('-n', '--[no-]line-numbers',
111
+ 'Show line numbers in the output (default: true)') do |show_numbers|
112
+ @options.location_format = show_numbers ? :numbers : :plain
115
113
  end
116
- parser.on('-s', '--single-line',
117
- 'Show location in editor-compatible single-line-per-smell format') do
118
- options.location_format = :single_line
114
+ @parser.on('-s', '--single-line',
115
+ 'Show location in editor-compatible single-line-per-smell format') do
116
+ @options.location_format = :single_line
119
117
  end
120
118
  end
121
119
 
122
120
  def set_up_sorting_option
123
- parser.on('--sort-by SORTING', [:smelliness, :none],
124
- 'Sort reported files by the given criterium:',
125
- ' smelliness ("smelliest" files first)',
126
- ' none (default - output in processing order)') do |sorting|
127
- options.sorting = sorting
128
- end
121
+ @parser.on('--sort-by SORTING', [:smelliness, :none],
122
+ 'Sort reported files by the given criterium:',
123
+ ' smelliness ("smelliest" files first)',
124
+ ' none (default - output in processing order)') do |sorting|
125
+ @options.sorting = sorting
126
+ end
129
127
  end
130
128
 
131
129
  def set_utility_options
132
- parser.separator "\nUtility options:"
133
- parser.on_tail('-h', '--help', 'Show this message') do
134
- puts parser
130
+ @parser.separator "\nUtility options:"
131
+ @parser.on_tail('-h', '--help', 'Show this message') do
132
+ puts @parser
135
133
  exit
136
134
  end
137
- parser.on_tail('-v', '--version', 'Show version') do
138
- puts "#{parser.program_name} #{Reek::Version::STRING}\n"
135
+ @parser.on_tail('-v', '--version', 'Show version') do
136
+ puts "#{@parser.program_name} #{Reek::Version::STRING}\n"
139
137
  exit
140
138
  end
141
139
  end
@@ -10,7 +10,7 @@ module Reek
10
10
  # @api private
11
11
  class ReekCommand < Command
12
12
  def execute(app)
13
- options.sources.each do |source|
13
+ @options.sources.each do |source|
14
14
  reporter.add_examiner Examiner.new(source, smell_names, configuration: app.configuration)
15
15
  end
16
16
  reporter.smells? ? app.report_smells : app.report_success
@@ -20,11 +20,11 @@ module Reek
20
20
  private
21
21
 
22
22
  def reporter
23
- @reporter ||= options.reporter
23
+ @reporter ||= @options.reporter
24
24
  end
25
25
 
26
26
  def smell_names
27
- @smell_names ||= options.smells_to_detect
27
+ @smell_names ||= @options.smells_to_detect
28
28
  end
29
29
  end
30
30
  end
@@ -8,20 +8,16 @@ module Reek
8
8
  # @api private
9
9
  class WarningCollector
10
10
  def initialize
11
- @warnings_set = Set.new
11
+ @warnings = Set.new
12
12
  end
13
13
 
14
14
  def found_smell(warning)
15
- warnings_set.add(warning)
15
+ @warnings.add(warning)
16
16
  end
17
17
 
18
18
  def warnings
19
- warnings_set.to_a.sort
19
+ @warnings.to_a.sort
20
20
  end
21
-
22
- private
23
-
24
- private_attr_reader :warnings_set
25
21
  end
26
22
  end
27
23
  end