reek 2.2.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.travis.yml +9 -4
  4. data/CHANGELOG +8 -0
  5. data/Gemfile +6 -4
  6. data/README.md +6 -0
  7. data/docs/API.md +51 -22
  8. data/docs/Configuration-Files.md +12 -1
  9. data/docs/Feature-Envy.md +30 -10
  10. data/docs/How-reek-works-internally.md +109 -39
  11. data/docs/RSpec-matchers.md +26 -22
  12. data/docs/Reek-Driven-Development.md +0 -8
  13. data/docs/Utility-Function.md +8 -10
  14. data/features/{ruby_api/api.feature → command_line_interface/basic_usage.feature} +2 -2
  15. data/features/programmatic_access.feature +21 -2
  16. data/features/samples.feature +3 -1
  17. data/lib/reek.rb +2 -2
  18. data/lib/reek/{core → ast}/ast_node_class_map.rb +8 -8
  19. data/lib/reek/{sexp/sexp_node.rb → ast/node.rb} +47 -6
  20. data/lib/reek/{core → ast}/object_refs.rb +2 -1
  21. data/lib/reek/{core → ast}/reference_collector.rb +2 -1
  22. data/lib/reek/{sexp → ast}/sexp_extensions.rb +10 -5
  23. data/lib/reek/{sexp → ast}/sexp_formatter.rb +7 -5
  24. data/lib/reek/cli/application.rb +1 -0
  25. data/lib/reek/cli/command.rb +1 -0
  26. data/lib/reek/cli/input.rb +4 -1
  27. data/lib/reek/cli/option_interpreter.rb +6 -4
  28. data/lib/reek/cli/options.rb +2 -1
  29. data/lib/reek/cli/reek_command.rb +3 -2
  30. data/lib/reek/cli/silencer.rb +1 -0
  31. data/lib/reek/{core → cli}/warning_collector.rb +2 -1
  32. data/lib/reek/code_comment.rb +36 -0
  33. data/lib/reek/configuration/app_configuration.rb +17 -2
  34. data/lib/reek/configuration/configuration_file_finder.rb +1 -0
  35. data/lib/reek/{core → context}/code_context.rb +7 -5
  36. data/lib/reek/{core → context}/method_context.rb +5 -3
  37. data/lib/reek/{core → context}/module_context.rb +8 -3
  38. data/lib/reek/{core/stop_context.rb → context/root_context.rb} +4 -2
  39. data/lib/reek/{core → context}/singleton_method_context.rb +2 -1
  40. data/lib/reek/examiner.rb +82 -0
  41. data/lib/reek/report/formatter.rb +70 -0
  42. data/lib/reek/report/heading_formatter.rb +45 -0
  43. data/lib/reek/report/location_formatter.rb +35 -0
  44. data/lib/reek/report/report.rb +198 -0
  45. data/lib/reek/smells.rb +24 -13
  46. data/lib/reek/smells/attribute.rb +6 -4
  47. data/lib/reek/smells/boolean_parameter.rb +3 -1
  48. data/lib/reek/smells/class_variable.rb +3 -1
  49. data/lib/reek/smells/control_parameter.rb +3 -1
  50. data/lib/reek/smells/data_clump.rb +3 -1
  51. data/lib/reek/smells/duplicate_method_call.rb +3 -1
  52. data/lib/reek/smells/feature_envy.rb +3 -1
  53. data/lib/reek/smells/irresponsible_module.rb +12 -7
  54. data/lib/reek/smells/long_parameter_list.rb +5 -3
  55. data/lib/reek/smells/long_yield_list.rb +3 -1
  56. data/lib/reek/smells/module_initialize.rb +3 -1
  57. data/lib/reek/smells/nested_iterators.rb +3 -1
  58. data/lib/reek/smells/nil_check.rb +3 -1
  59. data/lib/reek/smells/prima_donna_method.rb +3 -1
  60. data/lib/reek/smells/repeated_conditional.rb +5 -3
  61. data/lib/reek/{core → smells}/smell_configuration.rb +3 -1
  62. data/lib/reek/smells/smell_detector.rb +9 -7
  63. data/lib/reek/{core → smells}/smell_repository.rb +3 -2
  64. data/lib/reek/smells/smell_warning.rb +6 -4
  65. data/lib/reek/smells/too_many_instance_variables.rb +3 -1
  66. data/lib/reek/smells/too_many_methods.rb +3 -1
  67. data/lib/reek/smells/too_many_statements.rb +3 -1
  68. data/lib/reek/smells/uncommunicative_method_name.rb +3 -1
  69. data/lib/reek/smells/uncommunicative_module_name.rb +3 -1
  70. data/lib/reek/smells/uncommunicative_parameter_name.rb +3 -1
  71. data/lib/reek/smells/uncommunicative_variable_name.rb +3 -1
  72. data/lib/reek/smells/unused_parameters.rb +3 -1
  73. data/lib/reek/smells/utility_function.rb +5 -2
  74. data/lib/reek/source/source_code.rb +40 -9
  75. data/lib/reek/source/source_locator.rb +30 -12
  76. data/lib/reek/spec/should_reek.rb +5 -4
  77. data/lib/reek/spec/should_reek_of.rb +3 -2
  78. data/lib/reek/spec/should_reek_only_of.rb +5 -4
  79. data/lib/reek/tree_dresser.rb +32 -0
  80. data/lib/reek/tree_walker.rb +182 -0
  81. data/lib/reek/version.rb +1 -1
  82. data/reek.gemspec +3 -3
  83. data/spec/factories/factories.rb +2 -0
  84. data/spec/reek/{sexp/sexp_node_spec.rb → ast/node_spec.rb} +2 -2
  85. data/spec/reek/{core → ast}/object_refs_spec.rb +3 -3
  86. data/spec/reek/{core → ast}/reference_collector_spec.rb +2 -2
  87. data/spec/reek/{sexp → ast}/sexp_extensions_spec.rb +6 -16
  88. data/spec/reek/{sexp → ast}/sexp_formatter_spec.rb +2 -2
  89. data/spec/reek/cli/option_interpreter_spec.rb +2 -1
  90. data/spec/reek/{core → cli}/warning_collector_spec.rb +3 -3
  91. data/spec/reek/{core/code_comment_spec.rb → code_comment_spec.rb} +3 -3
  92. data/spec/reek/configuration/app_configuration_spec.rb +31 -18
  93. data/spec/reek/{core → context}/code_context_spec.rb +14 -15
  94. data/spec/reek/{core → context}/method_context_spec.rb +8 -8
  95. data/spec/reek/{core → context}/module_context_spec.rb +4 -4
  96. data/spec/reek/context/root_context_spec.rb +14 -0
  97. data/spec/reek/{core → context}/singleton_method_context_spec.rb +4 -4
  98. data/spec/reek/{core/examiner_spec.rb → examiner_spec.rb} +3 -42
  99. data/spec/reek/{cli → report}/html_report_spec.rb +5 -5
  100. data/spec/reek/report/json_report_spec.rb +20 -0
  101. data/spec/reek/{cli → report}/text_report_spec.rb +14 -14
  102. data/spec/reek/{cli → report}/xml_report_spec.rb +7 -7
  103. data/spec/reek/report/yaml_report_spec.rb +20 -0
  104. data/spec/reek/smells/attribute_spec.rb +2 -1
  105. data/spec/reek/smells/boolean_parameter_spec.rb +1 -1
  106. data/spec/reek/smells/class_variable_spec.rb +5 -5
  107. data/spec/reek/smells/control_parameter_spec.rb +1 -1
  108. data/spec/reek/smells/data_clump_spec.rb +1 -1
  109. data/spec/reek/smells/duplicate_method_call_spec.rb +3 -3
  110. data/spec/reek/smells/feature_envy_spec.rb +1 -1
  111. data/spec/reek/smells/irresponsible_module_spec.rb +24 -28
  112. data/spec/reek/smells/long_parameter_list_spec.rb +2 -2
  113. data/spec/reek/smells/long_yield_list_spec.rb +2 -2
  114. data/spec/reek/smells/nested_iterators_spec.rb +1 -1
  115. data/spec/reek/smells/nil_check_spec.rb +2 -2
  116. data/spec/reek/smells/prima_donna_method_spec.rb +3 -3
  117. data/spec/reek/smells/repeated_conditional_spec.rb +6 -6
  118. data/spec/reek/{core → smells}/smell_configuration_spec.rb +4 -4
  119. data/spec/reek/smells/smell_detector_shared.rb +2 -2
  120. data/spec/reek/{core → smells}/smell_repository_spec.rb +5 -4
  121. data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
  122. data/spec/reek/smells/too_many_methods_spec.rb +4 -4
  123. data/spec/reek/smells/too_many_statements_spec.rb +2 -2
  124. data/spec/reek/smells/uncommunicative_method_name_spec.rb +1 -1
  125. data/spec/reek/smells/uncommunicative_module_name_spec.rb +4 -4
  126. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +2 -2
  127. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +3 -3
  128. data/spec/reek/smells/utility_function_spec.rb +23 -1
  129. data/spec/reek/source/source_code_spec.rb +1 -1
  130. data/spec/reek/source/source_locator_spec.rb +30 -0
  131. data/spec/reek/spec/should_reek_of_spec.rb +0 -17
  132. data/spec/reek/spec/should_reek_spec.rb +0 -25
  133. data/spec/reek/tree_dresser_spec.rb +16 -0
  134. data/spec/reek/{core/tree_walker_spec.rb → tree_walker_spec.rb} +5 -5
  135. data/spec/samples/{simple_configuration.reek → configuration/simple_configuration.reek} +0 -0
  136. data/spec/samples/configuration/with_excluded_paths.reek +4 -0
  137. data/spec/samples/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb +5 -0
  138. data/spec/samples/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb +2 -0
  139. data/spec/samples/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb +6 -0
  140. data/spec/spec_helper.rb +6 -7
  141. data/tasks/develop.rake +2 -2
  142. metadata +71 -69
  143. data/lib/reek/cli/report/formatter.rb +0 -69
  144. data/lib/reek/cli/report/heading_formatter.rb +0 -45
  145. data/lib/reek/cli/report/location_formatter.rb +0 -34
  146. data/lib/reek/cli/report/report.rb +0 -191
  147. data/lib/reek/core/ast_node.rb +0 -38
  148. data/lib/reek/core/code_comment.rb +0 -37
  149. data/lib/reek/core/examiner.rb +0 -85
  150. data/lib/reek/core/tree_dresser.rb +0 -24
  151. data/lib/reek/core/tree_walker.rb +0 -180
  152. data/lib/reek/source/source_repository.rb +0 -43
  153. data/spec/reek/cli/json_report_spec.rb +0 -20
  154. data/spec/reek/cli/yaml_report_spec.rb +0 -20
  155. data/spec/reek/core/object_source_spec.rb +0 -18
  156. data/spec/reek/core/stop_context_spec.rb +0 -14
  157. data/spec/reek/core/tree_dresser_spec.rb +0 -16
@@ -20,7 +20,7 @@ RSpec.describe Reek::Smells::TooManyMethods do
20
20
  end
21
21
  EOS
22
22
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
23
- ctx = Reek::Core::ModuleContext.new(nil, syntax_tree)
23
+ ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
24
24
  expect(@detector.examine_context(ctx)).to be_empty
25
25
  end
26
26
 
@@ -33,7 +33,7 @@ RSpec.describe Reek::Smells::TooManyMethods do
33
33
  end
34
34
  EOS
35
35
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
36
- ctx = Reek::Core::ModuleContext.new(nil, syntax_tree)
36
+ ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
37
37
  smells = @detector.examine_context(ctx)
38
38
  expect(smells.length).to eq(1)
39
39
  expect(smells[0].smell_type).to eq(described_class.smell_type)
@@ -56,7 +56,7 @@ RSpec.describe Reek::Smells::TooManyMethods do
56
56
  end
57
57
  EOS
58
58
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
59
- ctx = Reek::Core::ModuleContext.new(nil, syntax_tree)
59
+ ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
60
60
  expect(@detector.examine_context(ctx)).to be_empty
61
61
  end
62
62
  end
@@ -71,7 +71,7 @@ RSpec.describe Reek::Smells::TooManyMethods do
71
71
  EOS
72
72
 
73
73
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
74
- ctx = Reek::Core::ModuleContext.new(nil, syntax_tree)
74
+ ctx = Reek::Context::ModuleContext.new(nil, syntax_tree)
75
75
  @warning = @detector.examine_context(ctx)[0]
76
76
  expect(@warning.source).to eq(@source_name)
77
77
  expect(@warning.smell_category).to eq(described_class.smell_category)
@@ -4,11 +4,11 @@ require_relative 'smell_detector_shared'
4
4
  require_relative '../../../lib/reek/source/source_code'
5
5
 
6
6
  def process_method(source)
7
- Reek::Core::TreeWalker.new.process_def(Reek::Source::SourceCode.from(source).syntax_tree)
7
+ Reek::TreeWalker.new.process_def(Reek::Source::SourceCode.from(source).syntax_tree)
8
8
  end
9
9
 
10
10
  def process_singleton_method(source)
11
- Reek::Core::TreeWalker.new.process_defs(Reek::Source::SourceCode.from(source).syntax_tree)
11
+ Reek::TreeWalker.new.process_defs(Reek::Source::SourceCode.from(source).syntax_tree)
12
12
  end
13
13
 
14
14
  RSpec.describe Reek::Smells::TooManyStatements do
@@ -21,7 +21,7 @@ RSpec.describe Reek::Smells::UncommunicativeMethodName do
21
21
  context 'with a bad name' do
22
22
  before do
23
23
  src = "def #{method_name}; end"
24
- ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
24
+ ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
25
25
  smells = @detector.examine_context(ctx)
26
26
  @warning = smells[0]
27
27
  end
@@ -1,7 +1,7 @@
1
1
  require_relative '../../spec_helper'
2
2
  require_relative '../../../lib/reek/smells/uncommunicative_module_name'
3
3
  require_relative 'smell_detector_shared'
4
- require_relative '../../../lib/reek/core/code_context'
4
+ require_relative '../../../lib/reek/context/code_context'
5
5
 
6
6
  RSpec.describe Reek::Smells::UncommunicativeModuleName do
7
7
  before do
@@ -30,7 +30,7 @@ RSpec.describe Reek::Smells::UncommunicativeModuleName do
30
30
 
31
31
  it 'reports a bad scoped name' do
32
32
  src = "#{type} Foo::X; end"
33
- ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
33
+ ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
34
34
  smells = @detector.examine_context(ctx)
35
35
  expect(smells.length).to eq(1)
36
36
  expect(smells[0].smell_category).to eq(Reek::Smells::UncommunicativeModuleName.smell_category)
@@ -43,7 +43,7 @@ RSpec.describe Reek::Smells::UncommunicativeModuleName do
43
43
  context 'accepting names' do
44
44
  it 'accepts Inline::C' do
45
45
  src = 'module Inline::C; end'
46
- ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
46
+ ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
47
47
  expect(@detector.examine_context(ctx)).to be_empty
48
48
  end
49
49
  end
@@ -51,7 +51,7 @@ RSpec.describe Reek::Smells::UncommunicativeModuleName do
51
51
  context 'looking at the YAML' do
52
52
  before :each do
53
53
  src = 'module Printer2; end'
54
- ctx = Reek::Core::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
54
+ ctx = Reek::Context::CodeContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
55
55
  smells = @detector.examine_context(ctx)
56
56
  @warning = smells[0]
57
57
  end
@@ -1,7 +1,7 @@
1
1
  require_relative '../../spec_helper'
2
2
  require_relative '../../../lib/reek/smells/uncommunicative_parameter_name'
3
3
  require_relative 'smell_detector_shared'
4
- require_relative '../../../lib/reek/core/method_context'
4
+ require_relative '../../../lib/reek/context/method_context'
5
5
 
6
6
  RSpec.describe Reek::Smells::UncommunicativeParameterName do
7
7
  before :each do
@@ -81,7 +81,7 @@ RSpec.describe Reek::Smells::UncommunicativeParameterName do
81
81
  context 'looking at the smell result fields' do
82
82
  before :each do
83
83
  src = 'def bad(good, bad2, good_again); basics(good, bad2, good_again); end'
84
- ctx = Reek::Core::MethodContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
84
+ ctx = Reek::Context::MethodContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
85
85
  @smells = @detector.examine_context(ctx)
86
86
  @warning = @smells[0]
87
87
  end
@@ -53,7 +53,7 @@ RSpec.describe Reek::Smells::UncommunicativeVariableName do
53
53
  it 'reports variable name only once' do
54
54
  src = 'def simple(fred) x = jim(45); x = y end'
55
55
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
56
- ctx = Reek::Core::CodeContext.new(nil, syntax_tree)
56
+ ctx = Reek::Context::CodeContext.new(nil, syntax_tree)
57
57
  smells = @detector.examine_context(ctx)
58
58
  expect(smells.length).to eq(1)
59
59
  expect(smells[0].smell_type).to eq(described_class.smell_type)
@@ -165,7 +165,7 @@ RSpec.describe Reek::Smells::UncommunicativeVariableName do
165
165
  end
166
166
  EOS
167
167
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
168
- ctx = Reek::Core::CodeContext.new(nil, syntax_tree)
168
+ ctx = Reek::Context::CodeContext.new(nil, syntax_tree)
169
169
  @smells = @detector.examine_context(ctx)
170
170
  @warning = @smells[0]
171
171
  end
@@ -182,7 +182,7 @@ RSpec.describe Reek::Smells::UncommunicativeVariableName do
182
182
  before :each do
183
183
  src = 'def self.bad() x2 = 4; end'
184
184
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
185
- ctx = Reek::Core::CodeContext.new(nil, syntax_tree)
185
+ ctx = Reek::Context::CodeContext.new(nil, syntax_tree)
186
186
  @smells = @detector.examine_context(ctx)
187
187
  @warning = @smells[0]
188
188
  end
@@ -21,7 +21,7 @@ RSpec.describe Reek::Smells::UtilityFunction do
21
21
  end
22
22
  EOS
23
23
  source = Reek::Source::SourceCode.from(src)
24
- mctx = Reek::Core::TreeWalker.new.process_def(source.syntax_tree)
24
+ mctx = Reek::TreeWalker.new.process_def(source.syntax_tree)
25
25
  @warning = @detector.examine_context(mctx)[0] # SMELL: too cumbersome!
26
26
  end
27
27
 
@@ -42,6 +42,28 @@ RSpec.describe Reek::Smells::UtilityFunction do
42
42
  end
43
43
  end
44
44
 
45
+ context 'Singleton methods' do
46
+ it 'for classes with `class << self` notation should not report UtilityFunction' do
47
+ src = 'class C; class << self; def m(a) a.to_s; end; end; end'
48
+ expect(src).not_to reek_of(:UtilityFunction)
49
+ end
50
+
51
+ it 'for classes with `self.` notation should not report UtilityFunction' do
52
+ src = 'class C; def self.m(a) a.to_s; end; end'
53
+ expect(src).not_to reek_of(:UtilityFunction)
54
+ end
55
+
56
+ it 'for modules with `class << self` notation should not report UtilityFunction' do
57
+ src = 'module M; class << self; def self.m(a) a.to_s; end; end; end'
58
+ expect(src).not_to reek_of(:UtilityFunction)
59
+ end
60
+
61
+ it 'for modules with `self.` notation should not report UtilityFunction' do
62
+ src = 'module M; def self.simple(a) a.to_s; end; end'
63
+ expect(src).not_to reek_of(:UtilityFunction)
64
+ end
65
+ end
66
+
45
67
  context 'with no calls' do
46
68
  it 'does not report empty method' do
47
69
  expect('def simple(arga) end').not_to reek_of(:UtilityFunction)
@@ -8,7 +8,7 @@ RSpec.describe Reek::Source::SourceCode do
8
8
  source = "# this is\n# a comment\ndef foo; end"
9
9
  source_code = Reek::Source::SourceCode.new(source, '(string)')
10
10
  result = source_code.syntax_tree
11
- expect(result.comments).to eq "# this is\n# a comment"
11
+ expect(result.leading_comment).to eq "# this is\n# a comment"
12
12
  end
13
13
 
14
14
  it 'cleanly processes empty source' do
@@ -0,0 +1,30 @@
1
+ require_relative '../../spec_helper'
2
+ require_relative '../../../lib/reek/source/source_locator'
3
+
4
+ RSpec.describe Reek::Source::SourceLocator do
5
+ describe '#sources' do
6
+ context 'exclude paths' do
7
+ let(:config) { 'spec/samples/configuration/with_excluded_paths.reek' }
8
+ let(:path) { 'spec/samples/source_with_exclude_paths' }
9
+ let(:files_that_are_expected_to_be_ignored) do
10
+ [
11
+ 'spec/samples/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb',
12
+ 'spec/samples/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb'
13
+ ]
14
+ end
15
+
16
+ it 'does not use excluded paths' do
17
+ with_test_config(config) do
18
+ sources = described_class.new([path]).sources
19
+
20
+ expect(sources.map(&:path).sort).
21
+ not_to include(files_that_are_expected_to_be_ignored)
22
+
23
+ expect(sources.map(&:path).sort).to eq [
24
+ 'spec/samples/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb'
25
+ ]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -54,23 +54,6 @@ RSpec.describe Reek::Spec::ShouldReekOf do
54
54
  end
55
55
  end
56
56
 
57
- context 'checking code in a Dir' do
58
- before :each do
59
- @clean_dir = Dir['spec/samples/three_clean_files/*.rb']
60
- @smelly_dir = Dir['spec/samples/two_smelly_files/*.rb']
61
- @matcher = Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName,
62
- name: '@s')
63
- end
64
-
65
- it 'matches a smelly String' do
66
- expect(@matcher.matches?(@smelly_dir)).to be_truthy
67
- end
68
-
69
- it 'doesnt match a fragrant String' do
70
- expect(@matcher.matches?(@clean_dir)).to be_falsey
71
- end
72
- end
73
-
74
57
  context 'checking code in a File' do
75
58
  before :each do
76
59
  @clean_file = File.new(Dir['spec/samples/three_clean_files/*.rb'][0])
@@ -22,31 +22,6 @@ RSpec.describe Reek::Spec::ShouldReek do
22
22
  end
23
23
  end
24
24
 
25
- describe 'checking code in a Dir' do
26
- let(:clean_dir) { Dir['spec/samples/three_clean_files/*.rb'] }
27
- let(:smelly_dir) { Dir['spec/samples/two_smelly_files/*.rb'] }
28
- let(:masked_dir) { Dir['spec/samples/clean_due_to_masking/*.rb'] }
29
-
30
- it 'matches a smelly Dir' do
31
- expect(matcher.matches?(smelly_dir)).to be_truthy
32
- end
33
-
34
- it 'doesnt match a fragrant Dir' do
35
- expect(matcher.matches?(clean_dir)).to be_falsey
36
- end
37
-
38
- it 'masks smells using the relevant configuration' do
39
- with_test_config('spec/samples/clean_due_to_masking/masked.reek') do
40
- expect(matcher.matches?(masked_dir)).to be_falsey
41
- end
42
- end
43
-
44
- it 'reports the smells when should_not fails' do
45
- matcher.matches?(smelly_dir)
46
- expect(matcher.failure_message_when_negated).to match('UncommunicativeVariableName')
47
- end
48
- end
49
-
50
25
  describe 'checking code in a File' do
51
26
  let(:clean_file) { File.new('spec/samples/three_clean_files/clean_one.rb') }
52
27
  let(:smelly_file) { File.new('spec/samples/two_smelly_files/dirty_one.rb') }
@@ -0,0 +1,16 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/reek/tree_dresser'
3
+
4
+ RSpec.describe Reek::TreeDresser do
5
+ let(:ifnode) { ::Parser::AST::Node.new(:if) }
6
+ let(:sendnode) { ::Parser::AST::Node.new(:send) }
7
+ let(:dresser) { described_class.new }
8
+
9
+ it 'dresses :if sexp with IfNode' do
10
+ expect(dresser.dress(ifnode, {})).to be_a Reek::AST::SexpExtensions::IfNode
11
+ end
12
+
13
+ it 'dresses :send sexp with SendNode' do
14
+ expect(dresser.dress(sendnode, {})).to be_a Reek::AST::SexpExtensions::SendNode
15
+ end
16
+ end
@@ -1,7 +1,7 @@
1
- require_relative '../../spec_helper'
2
- require_relative '../../../lib/reek/core/tree_walker'
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/reek/tree_walker'
3
3
 
4
- RSpec.describe Reek::Core::TreeWalker, 'with no method definitions' do
4
+ RSpec.describe Reek::TreeWalker, 'with no method definitions' do
5
5
  it 'reports no problems for empty source code' do
6
6
  expect('').not_to reek
7
7
  end
@@ -11,14 +11,14 @@ class Fred; end').not_to reek
11
11
  end
12
12
  end
13
13
 
14
- RSpec.describe Reek::Core::TreeWalker, 'with a global method definition' do
14
+ RSpec.describe Reek::TreeWalker, 'with a global method definition' do
15
15
  it 'reports no problems for simple method' do
16
16
  src = 'def Outermost::fred() true; end'
17
17
  expect(src).not_to reek
18
18
  end
19
19
  end
20
20
 
21
- RSpec.describe Reek::Core::TreeWalker, 'when a yield is the receiver' do
21
+ RSpec.describe Reek::TreeWalker, 'when a yield is the receiver' do
22
22
  it 'reports no problems' do
23
23
  src = <<EOS
24
24
  def values(*args)
@@ -0,0 +1,4 @@
1
+ ---
2
+ exclude_paths:
3
+ - spec/samples/source_with_exclude_paths/ignore_me/
4
+ - spec/samples/source_with_exclude_paths/nested/ignore_me_as_well
@@ -0,0 +1,5 @@
1
+ # Klass comment.
2
+ class Klass
3
+ def m
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ # Klass comment
2
+ class Klass
3
+ def method(a)
4
+ a + @x
5
+ end
6
+ end
@@ -1,20 +1,19 @@
1
1
  require_relative '../lib/reek/spec'
2
- require_relative '../lib/reek/core/ast_node_class_map'
2
+ require_relative '../lib/reek/ast/ast_node_class_map'
3
3
  require_relative '../lib/reek/configuration/app_configuration'
4
4
 
5
5
  Reek::CLI::Silencer.silently do
6
6
  require 'factory_girl'
7
+ begin
8
+ require 'pry-byebug'
9
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
10
+ end
7
11
  end
8
12
  if Gem.loaded_specs['factory_girl'].version > Gem::Version.create('4.5.0')
9
13
  raise 'Remove the above silencer as well as this check now that ' \
10
14
  '`factory_girl` gem is updated to version greater than 4.5.0!'
11
15
  end
12
16
 
13
- begin
14
- require 'pry-byebug'
15
- rescue LoadError # rubocop:disable Lint/HandleExceptions
16
- end
17
-
18
17
  FactoryGirl.find_definitions
19
18
 
20
19
  SAMPLES_DIR = 'spec/samples'
@@ -37,7 +36,7 @@ module Helpers
37
36
 
38
37
  # :reek:UncommunicativeMethodName
39
38
  def s(type, *children)
40
- @klass_map ||= Reek::Core::ASTNodeClassMap.new
39
+ @klass_map ||= Reek::AST::ASTNodeClassMap.new
41
40
  @klass_map.klass_for(type).new(type, children)
42
41
  end
43
42
 
@@ -1,11 +1,11 @@
1
1
  require 'rake/clean'
2
- require_relative '../lib/reek/core/smell_repository'
2
+ require_relative '../lib/reek/smells/smell_repository'
3
3
 
4
4
  CONFIG_FILE = 'config/defaults.reek'
5
5
 
6
6
  file CONFIG_FILE do
7
7
  config = {}
8
- Reek::Core::SmellRepository.smell_types.each do |klass|
8
+ Reek::Smells::SmellRepository.smell_types.each do |klass|
9
9
  config[klass.name.split(/::/)[-1]] = klass.default_config
10
10
  end
11
11
  $stderr.puts "Creating #{CONFIG_FILE}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reek
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Rutherford
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-05-11 00:00:00.000000000 Z
13
+ date: 2015-06-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parser
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '2.2'
21
+ version: 2.2.2.5
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '2.2'
28
+ version: 2.2.2.5
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rainbow
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -82,6 +82,20 @@ dependencies:
82
82
  - - "~>"
83
83
  - !ruby/object:Gem::Version
84
84
  version: 0.6.2
85
+ - !ruby/object:Gem::Dependency
86
+ name: ataru
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: 0.2.0
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: 0.2.0
85
99
  - !ruby/object:Gem::Dependency
86
100
  name: bundler
87
101
  requirement: !ruby/object:Gem::Requirement
@@ -166,20 +180,6 @@ dependencies:
166
180
  - - "~>"
167
181
  - !ruby/object:Gem::Version
168
182
  version: 0.30.0
169
- - !ruby/object:Gem::Dependency
170
- name: yard
171
- requirement: !ruby/object:Gem::Requirement
172
- requirements:
173
- - - "~>"
174
- - !ruby/object:Gem::Version
175
- version: 0.8.7
176
- type: :development
177
- prerelease: false
178
- version_requirements: !ruby/object:Gem::Requirement
179
- requirements:
180
- - - "~>"
181
- - !ruby/object:Gem::Version
182
- version: 0.8.7
183
183
  description: |2
184
184
  Reek is a tool that examines Ruby classes, modules and methods and reports
185
185
  any code smells it finds.
@@ -247,6 +247,7 @@ files:
247
247
  - docs/Versioning-Policy.md
248
248
  - docs/YAML-Reports.md
249
249
  - docs/yard_plugin.rb
250
+ - features/command_line_interface/basic_usage.feature
250
251
  - features/command_line_interface/options.feature
251
252
  - features/command_line_interface/smell_selection.feature
252
253
  - features/command_line_interface/smells_count.feature
@@ -259,46 +260,40 @@ files:
259
260
  - features/reports/json.feature
260
261
  - features/reports/reports.feature
261
262
  - features/reports/yaml.feature
262
- - features/ruby_api/api.feature
263
263
  - features/samples.feature
264
264
  - features/step_definitions/.rubocop.yml
265
265
  - features/step_definitions/reek_steps.rb
266
266
  - features/step_definitions/sample_file_steps.rb
267
267
  - features/support/env.rb
268
268
  - lib/reek.rb
269
+ - lib/reek/ast/ast_node_class_map.rb
270
+ - lib/reek/ast/node.rb
271
+ - lib/reek/ast/object_refs.rb
272
+ - lib/reek/ast/reference_collector.rb
273
+ - lib/reek/ast/sexp_extensions.rb
274
+ - lib/reek/ast/sexp_formatter.rb
269
275
  - lib/reek/cli/application.rb
270
276
  - lib/reek/cli/command.rb
271
277
  - lib/reek/cli/input.rb
272
278
  - lib/reek/cli/option_interpreter.rb
273
279
  - lib/reek/cli/options.rb
274
280
  - lib/reek/cli/reek_command.rb
275
- - lib/reek/cli/report/formatter.rb
276
- - lib/reek/cli/report/heading_formatter.rb
277
- - lib/reek/cli/report/location_formatter.rb
278
- - lib/reek/cli/report/report.rb
279
281
  - lib/reek/cli/silencer.rb
282
+ - lib/reek/cli/warning_collector.rb
283
+ - lib/reek/code_comment.rb
280
284
  - lib/reek/configuration/app_configuration.rb
281
285
  - lib/reek/configuration/configuration_file_finder.rb
282
- - lib/reek/core/ast_node.rb
283
- - lib/reek/core/ast_node_class_map.rb
284
- - lib/reek/core/code_comment.rb
285
- - lib/reek/core/code_context.rb
286
- - lib/reek/core/examiner.rb
287
- - lib/reek/core/method_context.rb
288
- - lib/reek/core/module_context.rb
289
- - lib/reek/core/object_refs.rb
290
- - lib/reek/core/reference_collector.rb
291
- - lib/reek/core/singleton_method_context.rb
292
- - lib/reek/core/smell_configuration.rb
293
- - lib/reek/core/smell_repository.rb
294
- - lib/reek/core/stop_context.rb
295
- - lib/reek/core/tree_dresser.rb
296
- - lib/reek/core/tree_walker.rb
297
- - lib/reek/core/warning_collector.rb
286
+ - lib/reek/context/code_context.rb
287
+ - lib/reek/context/method_context.rb
288
+ - lib/reek/context/module_context.rb
289
+ - lib/reek/context/root_context.rb
290
+ - lib/reek/context/singleton_method_context.rb
291
+ - lib/reek/examiner.rb
298
292
  - lib/reek/rake/task.rb
299
- - lib/reek/sexp/sexp_extensions.rb
300
- - lib/reek/sexp/sexp_formatter.rb
301
- - lib/reek/sexp/sexp_node.rb
293
+ - lib/reek/report/formatter.rb
294
+ - lib/reek/report/heading_formatter.rb
295
+ - lib/reek/report/location_formatter.rb
296
+ - lib/reek/report/report.rb
302
297
  - lib/reek/smells.rb
303
298
  - lib/reek/smells/attribute.rb
304
299
  - lib/reek/smells/boolean_parameter.rb
@@ -315,7 +310,9 @@ files:
315
310
  - lib/reek/smells/nil_check.rb
316
311
  - lib/reek/smells/prima_donna_method.rb
317
312
  - lib/reek/smells/repeated_conditional.rb
313
+ - lib/reek/smells/smell_configuration.rb
318
314
  - lib/reek/smells/smell_detector.rb
315
+ - lib/reek/smells/smell_repository.rb
319
316
  - lib/reek/smells/smell_warning.rb
320
317
  - lib/reek/smells/too_many_instance_variables.rb
321
318
  - lib/reek/smells/too_many_methods.rb
@@ -328,44 +325,40 @@ files:
328
325
  - lib/reek/smells/utility_function.rb
329
326
  - lib/reek/source/source_code.rb
330
327
  - lib/reek/source/source_locator.rb
331
- - lib/reek/source/source_repository.rb
332
328
  - lib/reek/spec.rb
333
329
  - lib/reek/spec/should_reek.rb
334
330
  - lib/reek/spec/should_reek_of.rb
335
331
  - lib/reek/spec/should_reek_only_of.rb
332
+ - lib/reek/tree_dresser.rb
333
+ - lib/reek/tree_walker.rb
336
334
  - lib/reek/version.rb
337
335
  - reek.gemspec
338
336
  - spec/factories/factories.rb
339
337
  - spec/gem/updates_spec.rb
340
338
  - spec/gem/yard_spec.rb
341
339
  - spec/quality/reek_source_spec.rb
342
- - spec/reek/cli/html_report_spec.rb
343
- - spec/reek/cli/json_report_spec.rb
340
+ - spec/reek/ast/node_spec.rb
341
+ - spec/reek/ast/object_refs_spec.rb
342
+ - spec/reek/ast/reference_collector_spec.rb
343
+ - spec/reek/ast/sexp_extensions_spec.rb
344
+ - spec/reek/ast/sexp_formatter_spec.rb
344
345
  - spec/reek/cli/option_interpreter_spec.rb
345
346
  - spec/reek/cli/options_spec.rb
346
- - spec/reek/cli/text_report_spec.rb
347
- - spec/reek/cli/xml_report_spec.rb
348
- - spec/reek/cli/yaml_report_spec.rb
347
+ - spec/reek/cli/warning_collector_spec.rb
348
+ - spec/reek/code_comment_spec.rb
349
349
  - spec/reek/configuration/app_configuration_spec.rb
350
350
  - spec/reek/configuration/configuration_file_finder_spec.rb
351
- - spec/reek/core/code_comment_spec.rb
352
- - spec/reek/core/code_context_spec.rb
353
- - spec/reek/core/examiner_spec.rb
354
- - spec/reek/core/method_context_spec.rb
355
- - spec/reek/core/module_context_spec.rb
356
- - spec/reek/core/object_refs_spec.rb
357
- - spec/reek/core/object_source_spec.rb
358
- - spec/reek/core/reference_collector_spec.rb
359
- - spec/reek/core/singleton_method_context_spec.rb
360
- - spec/reek/core/smell_configuration_spec.rb
361
- - spec/reek/core/smell_repository_spec.rb
362
- - spec/reek/core/stop_context_spec.rb
363
- - spec/reek/core/tree_dresser_spec.rb
364
- - spec/reek/core/tree_walker_spec.rb
365
- - spec/reek/core/warning_collector_spec.rb
366
- - spec/reek/sexp/sexp_extensions_spec.rb
367
- - spec/reek/sexp/sexp_formatter_spec.rb
368
- - spec/reek/sexp/sexp_node_spec.rb
351
+ - spec/reek/context/code_context_spec.rb
352
+ - spec/reek/context/method_context_spec.rb
353
+ - spec/reek/context/module_context_spec.rb
354
+ - spec/reek/context/root_context_spec.rb
355
+ - spec/reek/context/singleton_method_context_spec.rb
356
+ - spec/reek/examiner_spec.rb
357
+ - spec/reek/report/html_report_spec.rb
358
+ - spec/reek/report/json_report_spec.rb
359
+ - spec/reek/report/text_report_spec.rb
360
+ - spec/reek/report/xml_report_spec.rb
361
+ - spec/reek/report/yaml_report_spec.rb
369
362
  - spec/reek/smells/attribute_spec.rb
370
363
  - spec/reek/smells/behaves_like_variable_detector.rb
371
364
  - spec/reek/smells/boolean_parameter_spec.rb
@@ -382,7 +375,9 @@ files:
382
375
  - spec/reek/smells/nil_check_spec.rb
383
376
  - spec/reek/smells/prima_donna_method_spec.rb
384
377
  - spec/reek/smells/repeated_conditional_spec.rb
378
+ - spec/reek/smells/smell_configuration_spec.rb
385
379
  - spec/reek/smells/smell_detector_shared.rb
380
+ - spec/reek/smells/smell_repository_spec.rb
386
381
  - spec/reek/smells/smell_warning_spec.rb
387
382
  - spec/reek/smells/too_many_instance_variables_spec.rb
388
383
  - spec/reek/smells/too_many_methods_spec.rb
@@ -394,9 +389,12 @@ files:
394
389
  - spec/reek/smells/unused_parameters_spec.rb
395
390
  - spec/reek/smells/utility_function_spec.rb
396
391
  - spec/reek/source/source_code_spec.rb
392
+ - spec/reek/source/source_locator_spec.rb
397
393
  - spec/reek/spec/should_reek_of_spec.rb
398
394
  - spec/reek/spec/should_reek_only_of_spec.rb
399
395
  - spec/reek/spec/should_reek_spec.rb
396
+ - spec/reek/tree_dresser_spec.rb
397
+ - spec/reek/tree_walker_spec.rb
400
398
  - spec/samples/all_but_one_masked/clean_one.rb
401
399
  - spec/samples/all_but_one_masked/dirty.rb
402
400
  - spec/samples/all_but_one_masked/masked.reek
@@ -407,6 +405,8 @@ files:
407
405
  - spec/samples/clean_due_to_masking/dirty_one.rb
408
406
  - spec/samples/clean_due_to_masking/dirty_two.rb
409
407
  - spec/samples/clean_due_to_masking/masked.reek
408
+ - spec/samples/configuration/simple_configuration.reek
409
+ - spec/samples/configuration/with_excluded_paths.reek
410
410
  - spec/samples/exceptions.reek
411
411
  - spec/samples/inline.rb
412
412
  - spec/samples/masked_by_dotfile/.reek
@@ -414,7 +414,9 @@ files:
414
414
  - spec/samples/no_config_file/dirty.rb
415
415
  - spec/samples/optparse.rb
416
416
  - spec/samples/redcloth.rb
417
- - spec/samples/simple_configuration.reek
417
+ - spec/samples/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb
418
+ - spec/samples/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb
419
+ - spec/samples/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb
418
420
  - spec/samples/three_clean_files/clean_one.rb
419
421
  - spec/samples/three_clean_files/clean_three.rb
420
422
  - spec/samples/three_clean_files/clean_two.rb
@@ -442,7 +444,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
442
444
  requirements:
443
445
  - - ">="
444
446
  - !ruby/object:Gem::Version
445
- version: 1.9.3
447
+ version: 2.0.0
446
448
  required_rubygems_version: !ruby/object:Gem::Requirement
447
449
  requirements:
448
450
  - - ">="
@@ -450,7 +452,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
450
452
  version: '0'
451
453
  requirements: []
452
454
  rubyforge_project:
453
- rubygems_version: 2.4.6
455
+ rubygems_version: 2.4.5
454
456
  signing_key:
455
457
  specification_version: 4
456
458
  summary: Code smell detector for Ruby