reek 5.0.2 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +9 -70
  3. data/.rubocop_todo.yml +63 -0
  4. data/.simplecov +4 -1
  5. data/CHANGELOG.md +5 -0
  6. data/Gemfile +12 -17
  7. data/README.md +21 -29
  8. data/Rakefile +2 -2
  9. data/docs/templates/default/docstring/setup.rb +3 -0
  10. data/features/command_line_interface/options.feature +5 -3
  11. data/features/configuration_files/schema_validation.feature +3 -3
  12. data/features/configuration_files/show_configuration_file.feature +44 -0
  13. data/features/rake_task/rake_task.feature +1 -1
  14. data/features/reports/json.feature +3 -3
  15. data/features/reports/reports.feature +4 -4
  16. data/features/reports/yaml.feature +3 -3
  17. data/features/rspec_matcher.feature +1 -0
  18. data/features/step_definitions/sample_file_steps.rb +6 -8
  19. data/features/todo_list.feature +39 -26
  20. data/lib/reek.rb +7 -0
  21. data/lib/reek/ast/node.rb +4 -0
  22. data/lib/reek/ast/sexp_extensions/if.rb +20 -0
  23. data/lib/reek/ast/sexp_extensions/methods.rb +1 -0
  24. data/lib/reek/cli/application.rb +25 -0
  25. data/lib/reek/cli/command/todo_list_command.rb +17 -7
  26. data/lib/reek/cli/options.rb +21 -14
  27. data/lib/reek/code_comment.rb +2 -0
  28. data/lib/reek/configuration/app_configuration.rb +0 -3
  29. data/lib/reek/configuration/configuration_converter.rb +4 -4
  30. data/lib/reek/configuration/directory_directives.rb +1 -0
  31. data/lib/reek/configuration/schema_validator.rb +1 -0
  32. data/lib/reek/context/method_context.rb +1 -0
  33. data/lib/reek/context/module_context.rb +5 -4
  34. data/lib/reek/context/visibility_tracker.rb +7 -4
  35. data/lib/reek/context_builder.rb +1 -0
  36. data/lib/reek/detector_repository.rb +1 -0
  37. data/lib/reek/errors/incomprehensible_source_error.rb +2 -2
  38. data/lib/reek/errors/syntax_error.rb +4 -0
  39. data/lib/reek/examiner.rb +1 -0
  40. data/lib/reek/report/text_report.rb +1 -0
  41. data/lib/reek/smell_detectors/control_parameter.rb +13 -107
  42. data/lib/reek/smell_detectors/control_parameter_helpers/call_in_condition_finder.rb +91 -0
  43. data/lib/reek/smell_detectors/control_parameter_helpers/candidate.rb +38 -0
  44. data/lib/reek/smell_detectors/control_parameter_helpers/control_parameter_finder.rb +94 -0
  45. data/lib/reek/smell_detectors/duplicate_method_call.rb +1 -0
  46. data/lib/reek/smell_detectors/feature_envy.rb +2 -0
  47. data/lib/reek/smell_detectors/irresponsible_module.rb +1 -0
  48. data/lib/reek/smell_detectors/long_parameter_list.rb +1 -0
  49. data/lib/reek/smell_detectors/manual_dispatch.rb +1 -0
  50. data/lib/reek/smell_detectors/missing_safe_method.rb +1 -0
  51. data/lib/reek/smell_detectors/nested_iterators.rb +1 -0
  52. data/lib/reek/smell_detectors/repeated_conditional.rb +1 -0
  53. data/lib/reek/smell_detectors/too_many_instance_variables.rb +1 -0
  54. data/lib/reek/smell_detectors/too_many_methods.rb +1 -0
  55. data/lib/reek/smell_detectors/too_many_statements.rb +1 -0
  56. data/lib/reek/smell_detectors/uncommunicative_variable_name.rb +2 -0
  57. data/lib/reek/smell_detectors/unused_parameters.rb +1 -0
  58. data/lib/reek/source/source_locator.rb +1 -0
  59. data/lib/reek/spec/should_reek_of.rb +2 -2
  60. data/lib/reek/spec/should_reek_only_of.rb +1 -0
  61. data/lib/reek/spec/smell_matcher.rb +1 -0
  62. data/lib/reek/tree_dresser.rb +1 -0
  63. data/lib/reek/version.rb +1 -1
  64. data/samples/smelly_source/ruby.rb +368 -0
  65. data/spec/factories/factories.rb +10 -9
  66. data/spec/performance/reek/smell_detectors/runtime_speed_spec.rb +17 -0
  67. data/spec/quality/documentation_spec.rb +40 -0
  68. data/spec/reek/ast/sexp_extensions_spec.rb +20 -20
  69. data/spec/reek/cli/application_spec.rb +29 -0
  70. data/spec/reek/cli/command/todo_list_command_spec.rb +64 -46
  71. data/spec/reek/configuration/app_configuration_spec.rb +8 -8
  72. data/spec/reek/configuration/configuration_file_finder_spec.rb +3 -3
  73. data/spec/reek/configuration/schema_validator_spec.rb +10 -10
  74. data/spec/reek/detector_repository_spec.rb +2 -2
  75. data/spec/reek/smell_detectors/control_parameter_spec.rb +17 -0
  76. data/spec/reek/source/source_locator_spec.rb +0 -2
  77. data/spec/spec_helper.rb +2 -0
  78. data/tasks/configuration.rake +2 -1
  79. data/tasks/test.rake +4 -0
  80. metadata +11 -5
  81. data/ataru_setup.rb +0 -13
  82. data/tasks/ataru.rake +0 -5
@@ -9,7 +9,7 @@ RSpec.describe Reek::Configuration::SchemaValidator do
9
9
  context 'when configuration is valid' do
10
10
  let(:configuration) do
11
11
  {
12
- Reek::Configuration::AppConfiguration::DETECTORS_KEY => {
12
+ Reek::DETECTORS_KEY => {
13
13
  'UncommunicativeVariableName' => { 'enabled' => false },
14
14
  'UncommunicativeMethodName' => { 'enabled' => false }
15
15
  }
@@ -24,7 +24,7 @@ RSpec.describe Reek::Configuration::SchemaValidator do
24
24
  context 'when detector is invalid' do
25
25
  let(:configuration) do
26
26
  {
27
- Reek::Configuration::AppConfiguration::DETECTORS_KEY => {
27
+ Reek::DETECTORS_KEY => {
28
28
  'DoesNotExist' => { 'enabled' => false }
29
29
  }
30
30
  }
@@ -39,7 +39,7 @@ RSpec.describe Reek::Configuration::SchemaValidator do
39
39
  context 'when `enabled` has a non-boolean value' do
40
40
  let(:configuration) do
41
41
  {
42
- Reek::Configuration::AppConfiguration::DETECTORS_KEY => {
42
+ Reek::DETECTORS_KEY => {
43
43
  'FeatureEnvy' => { 'enabled' => 'foo' }
44
44
  }
45
45
  }
@@ -54,7 +54,7 @@ RSpec.describe Reek::Configuration::SchemaValidator do
54
54
  context 'when detector has an unknown option' do
55
55
  let(:configuration) do
56
56
  {
57
- Reek::Configuration::AppConfiguration::DETECTORS_KEY => {
57
+ Reek::DETECTORS_KEY => {
58
58
  'DataClump' => { 'does_not_exist' => 42 }
59
59
  }
60
60
  }
@@ -71,7 +71,7 @@ RSpec.describe Reek::Configuration::SchemaValidator do
71
71
  context 'when a scalar' do
72
72
  let(:configuration) do
73
73
  {
74
- Reek::Configuration::AppConfiguration::DETECTORS_KEY => {
74
+ Reek::DETECTORS_KEY => {
75
75
  'UncommunicativeMethodName' => { attribute => 42 }
76
76
  }
77
77
  }
@@ -86,7 +86,7 @@ RSpec.describe Reek::Configuration::SchemaValidator do
86
86
  context 'when types are mixed' do
87
87
  let(:configuration) do
88
88
  {
89
- Reek::Configuration::AppConfiguration::DETECTORS_KEY => {
89
+ Reek::DETECTORS_KEY => {
90
90
  'UncommunicativeMethodName' => { attribute => [42, 'foo'] }
91
91
  }
92
92
  }
@@ -103,7 +103,7 @@ RSpec.describe Reek::Configuration::SchemaValidator do
103
103
  context 'when `exclude_paths` is a scalar' do
104
104
  let(:configuration) do
105
105
  {
106
- Reek::Configuration::AppConfiguration::EXCLUDE_PATHS_KEY => 42
106
+ Reek::EXCLUDE_PATHS_KEY => 42
107
107
  }
108
108
  end
109
109
 
@@ -116,7 +116,7 @@ RSpec.describe Reek::Configuration::SchemaValidator do
116
116
  context 'when `exclude_paths` mixes types' do
117
117
  let(:configuration) do
118
118
  {
119
- Reek::Configuration::AppConfiguration::EXCLUDE_PATHS_KEY => [42, 'foo']
119
+ Reek::EXCLUDE_PATHS_KEY => [42, 'foo']
120
120
  }
121
121
  end
122
122
 
@@ -130,7 +130,7 @@ RSpec.describe Reek::Configuration::SchemaValidator do
130
130
  context 'when bad detector' do
131
131
  let(:configuration) do
132
132
  {
133
- Reek::Configuration::AppConfiguration::DIRECTORIES_KEY => {
133
+ Reek::DIRECTORIES_KEY => {
134
134
  'web_app/app/helpers' => {
135
135
  'Bar' => { 'enabled' => false }
136
136
  }
@@ -147,7 +147,7 @@ RSpec.describe Reek::Configuration::SchemaValidator do
147
147
  context 'when unknown attribute' do
148
148
  let(:configuration) do
149
149
  {
150
- Reek::Configuration::AppConfiguration::DIRECTORIES_KEY => {
150
+ Reek::DIRECTORIES_KEY => {
151
151
  'web_app/app/controllers' => {
152
152
  'NestedIterators' => { 'foo' => false }
153
153
  }
@@ -7,8 +7,8 @@ RSpec.describe Reek::DetectorRepository do
7
7
  let(:smell_types) { described_class.smell_types }
8
8
 
9
9
  it 'includes existing smell_types' do
10
- expect(smell_types).to include(Reek::SmellDetectors::IrresponsibleModule).
11
- and include(Reek::SmellDetectors::TooManyStatements)
10
+ expect(smell_types).to include(Reek::SmellDetectors::IrresponsibleModule,
11
+ Reek::SmellDetectors::TooManyStatements)
12
12
  end
13
13
 
14
14
  it 'excludes the smell detector base class' do
@@ -30,6 +30,23 @@ RSpec.describe Reek::SmellDetectors::ControlParameter do
30
30
  and reek_of(:ControlParameter, lines: [3], argument: 'charlie')
31
31
  end
32
32
 
33
+ it 'does count multiple occurences of the same parameter' do
34
+ src = <<-EOS
35
+ def alfa(bravo, charlie)
36
+ if bravo
37
+ delta if charlie
38
+ end
39
+ if charlie
40
+ delta if bravo
41
+ end
42
+ end
43
+ EOS
44
+
45
+ expect(src).
46
+ to reek_of(:ControlParameter, lines: [2, 6], argument: 'bravo').
47
+ and reek_of(:ControlParameter, lines: [3, 5], argument: 'charlie')
48
+ end
49
+
33
50
  context 'when a parameter is not used to determine code path' do
34
51
  it 'does not report a ternary check on an ivar' do
35
52
  src = 'def alfa(bravo) @charlie ? bravo : false end'
@@ -29,7 +29,6 @@ RSpec.describe Reek::Source::SourceLocator do
29
29
  end
30
30
  end
31
31
 
32
- # rubocop:disable RSpec/NestedGroups
33
32
  context 'with excluded paths' do
34
33
  let(:configuration) do
35
34
  test_configuration_for(CONFIGURATION_DIR.join('with_excluded_paths.reek'))
@@ -118,7 +117,6 @@ RSpec.describe Reek::Source::SourceLocator do
118
117
  end
119
118
  end
120
119
  end
121
- # rubocop:enable RSpec/NestedGroups
122
120
 
123
121
  context 'with non-Ruby paths' do
124
122
  let(:path) { SAMPLES_DIR.join('source_with_non_ruby_files') }
@@ -1,6 +1,7 @@
1
1
  require 'pathname'
2
2
  require 'timeout'
3
3
  require 'active_support/core_ext/string/strip'
4
+ require 'rspec-benchmark'
4
5
  require_relative '../lib/reek'
5
6
  require_relative '../lib/reek/spec'
6
7
  require_relative '../lib/reek/ast/ast_node_class_map'
@@ -76,6 +77,7 @@ RSpec.configure do |config|
76
77
  config.run_all_when_everything_filtered = true
77
78
  config.include FactoryBot::Syntax::Methods
78
79
  config.include Helpers
80
+ config.include RSpec::Benchmark::Matchers
79
81
 
80
82
  config.disable_monkey_patching!
81
83
 
@@ -1,3 +1,4 @@
1
+ require_relative '../lib/reek'
1
2
  require_relative '../lib/reek/detector_repository'
2
3
  require_relative '../lib/reek/configuration/rake_task_converter'
3
4
  require_relative '../lib/reek/configuration/app_configuration'
@@ -12,7 +13,7 @@ namespace :configuration do
12
13
  hash[klass.smell_type] = Reek::Configuration::RakeTaskConverter.convert klass.default_config
13
14
  end
14
15
  File.open(DEFAULT_SMELL_CONFIGURATION, 'w') do |file|
15
- YAML.dump({ Reek::Configuration::AppConfiguration::DETECTORS_KEY => content }, file)
16
+ YAML.dump({ Reek::DETECTORS_KEY => content }, file)
16
17
  end
17
18
  end
18
19
  end
@@ -7,6 +7,10 @@ namespace 'test' do
7
7
  t.ruby_opts = ['-rbundler/setup -rsimplecov -Ilib -w']
8
8
  end
9
9
 
10
+ RSpec::Core::RakeTask.new('performance') do |t|
11
+ t.pattern = 'spec/performance/**/*_spec.rb'
12
+ end
13
+
10
14
  desc 'Tests code quality'
11
15
  RSpec::Core::RakeTask.new('quality') do |t|
12
16
  t.pattern = 'spec/quality/**/*_spec.rb'
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: 5.0.2
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Rutherford
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-07-10 00:00:00.000000000 Z
14
+ date: 2018-09-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: codeclimate-engine-rb
@@ -103,6 +103,7 @@ files:
103
103
  - ".gitignore"
104
104
  - ".reek.yml"
105
105
  - ".rubocop.yml"
106
+ - ".rubocop_todo.yml"
106
107
  - ".simplecov"
107
108
  - ".travis.yml"
108
109
  - ".yardopts"
@@ -113,7 +114,6 @@ files:
113
114
  - License.txt
114
115
  - README.md
115
116
  - Rakefile
116
- - ataru_setup.rb
117
117
  - bin/code_climate_reek
118
118
  - bin/reek
119
119
  - docs/API.md
@@ -183,6 +183,7 @@ files:
183
183
  - features/configuration_files/mix_accept_reject_setting.feature
184
184
  - features/configuration_files/reject_setting.feature
185
185
  - features/configuration_files/schema_validation.feature
186
+ - features/configuration_files/show_configuration_file.feature
186
187
  - features/configuration_files/unused_private_method.feature
187
188
  - features/configuration_loading.feature
188
189
  - features/configuration_via_source_comments/erroneous_source_comments.feature
@@ -298,6 +299,9 @@ files:
298
299
  - lib/reek/smell_detectors/boolean_parameter.rb
299
300
  - lib/reek/smell_detectors/class_variable.rb
300
301
  - lib/reek/smell_detectors/control_parameter.rb
302
+ - lib/reek/smell_detectors/control_parameter_helpers/call_in_condition_finder.rb
303
+ - lib/reek/smell_detectors/control_parameter_helpers/candidate.rb
304
+ - lib/reek/smell_detectors/control_parameter_helpers/control_parameter_finder.rb
301
305
  - lib/reek/smell_detectors/data_clump.rb
302
306
  - lib/reek/smell_detectors/duplicate_method_call.rb
303
307
  - lib/reek/smell_detectors/feature_envy.rb
@@ -358,6 +362,7 @@ files:
358
362
  - samples/smelly_source/inline.rb
359
363
  - samples/smelly_source/optparse.rb
360
364
  - samples/smelly_source/redcloth.rb
365
+ - samples/smelly_source/ruby.rb
361
366
  - samples/smelly_source/smelly.rb
362
367
  - samples/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb
363
368
  - samples/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb
@@ -368,6 +373,8 @@ files:
368
373
  - samples/source_with_non_ruby_files/python_source.py
369
374
  - samples/source_with_non_ruby_files/ruby.rb
370
375
  - spec/factories/factories.rb
376
+ - spec/performance/reek/smell_detectors/runtime_speed_spec.rb
377
+ - spec/quality/documentation_spec.rb
371
378
  - spec/quality/reek_source_spec.rb
372
379
  - spec/reek/ast/node_spec.rb
373
380
  - spec/reek/ast/object_refs_spec.rb
@@ -451,7 +458,6 @@ files:
451
458
  - spec/reek/spec/smell_matcher_spec.rb
452
459
  - spec/reek/tree_dresser_spec.rb
453
460
  - spec/spec_helper.rb
454
- - tasks/ataru.rake
455
461
  - tasks/configuration.rake
456
462
  - tasks/console.rake
457
463
  - tasks/reek.rake
@@ -481,7 +487,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
481
487
  version: '0'
482
488
  requirements: []
483
489
  rubyforge_project:
484
- rubygems_version: 2.5.2.2
490
+ rubygems_version: 2.5.2.3
485
491
  signing_key:
486
492
  specification_version: 4
487
493
  summary: Code smell detector for Ruby
@@ -1,13 +0,0 @@
1
- require 'reek'
2
- require 'reek/smell_detectors'
3
-
4
- # Ataru setup module.
5
- module Setup
6
- def setup
7
- # Run before every snippet.
8
- end
9
-
10
- def teardown
11
- # Run after every snippet.
12
- end
13
- end
@@ -1,5 +0,0 @@
1
- desc 'Runs ataru to check if our docs are still in sync with our code'
2
- task :ataru do
3
- system 'bundle exec ataru check'
4
- abort unless $CHILD_STATUS.success?
5
- end