reek 4.5.4 → 4.5.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 779579909e4877e391f86f92756b1ce1b45a3202
4
- data.tar.gz: a7f30fb8db30c839c335c47be2eb00ce0f321bac
3
+ metadata.gz: f744d82cb65c9d8b3d9f360ed948e1bf7944299a
4
+ data.tar.gz: e74921da8bed3e617aeb1a80d9085f0876c80f38
5
5
  SHA512:
6
- metadata.gz: 5e10d6f4cf3e8f9bc0cf499261647cd167eb5bed0296c97d79263408b4f82b371904da23927e6853ddf2d5643137a513b9f947ce2c3593f3b7b89d602baae21e
7
- data.tar.gz: 8b3e07023d3001002650fd4489aa130d1350093f4e604ba3ee5a33fa71c916618f2fc14d037c5e4eb737823e64ebc054166db2b6643b0e832c906210e85fd6c6
6
+ metadata.gz: 04bc673256d4145a067b4cbe45d9d0d7a2bfd5170779a6ee2520dedc73ec09abbbad073e17d40dd2cbbd70dbab2f5ea297608a244b448fd71020c4525dc76cc9
7
+ data.tar.gz: d43b2c46f59d642e127edc26813058937e90ee10811ca5484f6487f2a2908c3bd313a53317a7c00c166b4553d54dbb35b894cc7d8dc9d068fcd3f34c0fe98052
@@ -12,6 +12,11 @@ Lint/HandleExceptions:
12
12
  Exclude:
13
13
  - 'spec/reek/configuration/configuration_file_finder_spec.rb'
14
14
 
15
+ # Spec blocks can be any size
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - 'spec/**/*'
19
+
15
20
  # FIXME: Make the class shorter
16
21
  Metrics/ClassLength:
17
22
  Exclude:
@@ -44,6 +49,12 @@ RSpec/DescribeClass:
44
49
  RSpec/ExampleLength:
45
50
  Enabled: false
46
51
 
52
+ # FIXME: Find a better way to block output during specs, and fix relevant examples.
53
+ RSpec/ExpectOutput:
54
+ Exclude:
55
+ - 'spec/reek/cli/command/todo_list_command_spec.rb'
56
+ - 'spec/reek/source/source_code_spec.rb'
57
+
47
58
  # FIXME: Split up files to avoid offenses
48
59
  RSpec/MultipleDescribes:
49
60
  Exclude:
@@ -65,7 +76,6 @@ RSpec/MultipleExpectations:
65
76
 
66
77
  # FIXME: Update specs to avoid offenses
67
78
  RSpec/NestedGroups:
68
- MaxNesting: 3
69
79
  Exclude:
70
80
  - 'spec/reek/cli/application_spec.rb'
71
81
 
@@ -1,5 +1,12 @@
1
1
  # Change log
2
2
 
3
+ ## 4.5.5 (2017-02-05)
4
+
5
+ * (mvz) Load YAML in code comments safely
6
+ * (mvz) Combine lines for manual dispatch smells
7
+ * (mvz) Respect exclude_paths when passing sources on the command line
8
+ * (mvz) Ensure explicit arguments of super() are processed
9
+
3
10
  ## 4.5.4 (2017-01-17)
4
11
 
5
12
  * (troessner) Improve documentation and fix PrimaDonnaMethod detector configuration via comment.
data/Gemfile CHANGED
@@ -17,8 +17,8 @@ group :development do
17
17
  gem 'yard', '~> 0.9.5'
18
18
 
19
19
  if RUBY_VERSION >= '2.3'
20
- gem 'rubocop', '~> 0.46.0'
21
- gem 'rubocop-rspec', '~> 1.9.0'
20
+ gem 'rubocop', '~> 0.47.1'
21
+ gem 'rubocop-rspec', '~> 1.10.0'
22
22
  end
23
23
 
24
24
  platforms :mri do
@@ -0,0 +1,24 @@
1
+ Feature: Exclude paths directives
2
+ In order to avoid Reek wasting time on files that cannot be fixed
3
+ As a user
4
+ I want to be able to exclude specific paths from being checked
5
+
6
+ Scenario: Exclude some paths
7
+ Given a file named "bad_files_live_here/smelly.rb" with:
8
+ """
9
+ # A smelly example class
10
+ class Smelly
11
+ def alfa(bravo); end
12
+ end
13
+ """
14
+ When I run `reek .`
15
+ Then the exit status indicates smells
16
+ Given a file named "config.reek" with:
17
+ """
18
+ ---
19
+ exclude_paths:
20
+ - bad_files_live_here
21
+ """
22
+ When I run `reek -c config.reek .`
23
+ Then it succeeds
24
+ And it reports nothing
@@ -63,7 +63,7 @@ Feature: Basic smell detection
63
63
  UncommunicativeVariableName: Inline::C#module_name has the variable name 'x' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
64
64
  UncommunicativeVariableName: Inline::C#parse_signature has the variable name 'x' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
65
65
  UtilityFunction: Inline::C#strip_comments doesn't depend on instance state (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Utility-Function.md]
66
- optparse.rb -- 130 warnings:
66
+ optparse.rb -- 126 warnings:
67
67
  Attribute: OptionParser#banner is a writable attribute [https://github.com/troessner/reek/blob/master/docs/Attribute.md]
68
68
  Attribute: OptionParser#default_argv is a writable attribute [https://github.com/troessner/reek/blob/master/docs/Attribute.md]
69
69
  Attribute: OptionParser#program_name is a writable attribute [https://github.com/troessner/reek/blob/master/docs/Attribute.md]
@@ -127,10 +127,6 @@ Feature: Basic smell detection
127
127
  LongParameterList: OptionParser::Switch#initialize has 7 parameters [https://github.com/troessner/reek/blob/master/docs/Long-Parameter-List.md]
128
128
  LongParameterList: OptionParser::Switch#summarize has 5 parameters [https://github.com/troessner/reek/blob/master/docs/Long-Parameter-List.md]
129
129
  ManualDispatch: OptionParser#make_switch manually dispatches method call [https://github.com/troessner/reek/blob/master/docs/Manual-Dispatch.md]
130
- ManualDispatch: OptionParser#make_switch manually dispatches method call [https://github.com/troessner/reek/blob/master/docs/Manual-Dispatch.md]
131
- ManualDispatch: OptionParser#make_switch manually dispatches method call [https://github.com/troessner/reek/blob/master/docs/Manual-Dispatch.md]
132
- ManualDispatch: OptionParser::List#accept manually dispatches method call [https://github.com/troessner/reek/blob/master/docs/Manual-Dispatch.md]
133
- ManualDispatch: OptionParser::List#accept manually dispatches method call [https://github.com/troessner/reek/blob/master/docs/Manual-Dispatch.md]
134
130
  ManualDispatch: OptionParser::List#accept manually dispatches method call [https://github.com/troessner/reek/blob/master/docs/Manual-Dispatch.md]
135
131
  ManualDispatch: OptionParser::List#add_banner manually dispatches method call [https://github.com/troessner/reek/blob/master/docs/Manual-Dispatch.md]
136
132
  ManualDispatch: OptionParser::List#summarize manually dispatches method call [https://github.com/troessner/reek/blob/master/docs/Manual-Dispatch.md]
@@ -194,7 +190,7 @@ Feature: Basic smell detection
194
190
  UnusedParameters: OptionParser::Completion#convert has unused parameter 'opt' [https://github.com/troessner/reek/blob/master/docs/Unused-Parameters.md]
195
191
  UnusedParameters: OptionParser::Switch::NoArgument#parse has unused parameter 'argv' [https://github.com/troessner/reek/blob/master/docs/Unused-Parameters.md]
196
192
  UnusedParameters: OptionParser::Switch::OptionalArgument#parse has unused parameter 'argv' [https://github.com/troessner/reek/blob/master/docs/Unused-Parameters.md]
197
- redcloth.rb -- 111 warnings:
193
+ redcloth.rb -- 110 warnings:
198
194
  Attribute: RedCloth#filter_html is a writable attribute [https://github.com/troessner/reek/blob/master/docs/Attribute.md]
199
195
  Attribute: RedCloth#filter_styles is a writable attribute [https://github.com/troessner/reek/blob/master/docs/Attribute.md]
200
196
  Attribute: RedCloth#hard_breaks is a writable attribute [https://github.com/troessner/reek/blob/master/docs/Attribute.md]
@@ -238,7 +234,6 @@ Feature: Basic smell detection
238
234
  LongParameterList: RedCloth#textile_fn_ has 5 parameters [https://github.com/troessner/reek/blob/master/docs/Long-Parameter-List.md]
239
235
  LongParameterList: RedCloth#textile_p has 4 parameters [https://github.com/troessner/reek/blob/master/docs/Long-Parameter-List.md]
240
236
  ManualDispatch: RedCloth#block_textile_prefix manually dispatches method call [https://github.com/troessner/reek/blob/master/docs/Manual-Dispatch.md]
241
- ManualDispatch: RedCloth#block_textile_prefix manually dispatches method call [https://github.com/troessner/reek/blob/master/docs/Manual-Dispatch.md]
242
237
  NestedIterators: RedCloth#block_textile_lists contains iterators nested 3 deep [https://github.com/troessner/reek/blob/master/docs/Nested-Iterators.md]
243
238
  NestedIterators: RedCloth#block_textile_table contains iterators nested 2 deep [https://github.com/troessner/reek/blob/master/docs/Nested-Iterators.md]
244
239
  NestedIterators: RedCloth#block_textile_table contains iterators nested 3 deep [https://github.com/troessner/reek/blob/master/docs/Nested-Iterators.md]
@@ -306,5 +301,5 @@ Feature: Basic smell detection
306
301
  UtilityFunction: RedCloth#lT doesn't depend on instance state (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Utility-Function.md]
307
302
  UtilityFunction: RedCloth#no_textile doesn't depend on instance state (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Utility-Function.md]
308
303
  UtilityFunction: RedCloth#v_align doesn't depend on instance state (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Utility-Function.md]
309
- 292 total warnings
304
+ 287 total warnings
310
305
  """
@@ -46,8 +46,8 @@ Then /^it reports:$/ do |report|
46
46
  end
47
47
 
48
48
  Then /^it reports this yaml:$/ do |expected_yaml|
49
- expected_warnings = YAML.load(expected_yaml.chomp)
50
- actual_warnings = YAML.load(last_command_started.stdout)
49
+ expected_warnings = YAML.safe_load(expected_yaml.chomp)
50
+ actual_warnings = YAML.safe_load(last_command_started.stdout)
51
51
  expect(actual_warnings).to eq expected_warnings
52
52
  end
53
53
 
@@ -85,7 +85,7 @@ module Reek
85
85
  end
86
86
 
87
87
  def sources_from_argv
88
- Source::SourceLocator.new(argv).sources
88
+ Source::SourceLocator.new(argv, configuration: configuration).sources
89
89
  end
90
90
 
91
91
  def source_from_pipe
@@ -46,7 +46,8 @@ module Reek
46
46
  line: line,
47
47
  source: source,
48
48
  options: options).validate
49
- @config.merge! detector_name => YAML.load(options || DISABLE_DETECTOR_CONFIGURATION)
49
+ @config.merge! detector_name => YAML.safe_load(options || DISABLE_DETECTOR_CONFIGURATION,
50
+ [Regexp])
50
51
  end
51
52
  end
52
53
 
@@ -130,7 +131,8 @@ module Reek
130
131
  end
131
132
 
132
133
  def escalate_bad_detector_configuration
133
- @parsed_options = YAML.load(options || CodeComment::DISABLE_DETECTOR_CONFIGURATION)
134
+ @parsed_options = YAML.safe_load(options || CodeComment::DISABLE_DETECTOR_CONFIGURATION,
135
+ [Regexp])
134
136
  rescue Psych::SyntaxError
135
137
  raise Errors::GarbageDetectorConfigurationInCommentError, detector_name: detector_name,
136
138
  original_comment: original_comment,
@@ -248,8 +248,9 @@ module Reek
248
248
  #
249
249
  # We record one reference to `self`.
250
250
  #
251
- def process_super(_)
251
+ def process_super(exp)
252
252
  current_context.record_use_of_self
253
+ process(exp)
253
254
  end
254
255
 
255
256
  # Handles `block` nodes.
@@ -20,11 +20,10 @@ module Reek
20
20
  #
21
21
  # :reek:FeatureEnvy
22
22
  def sniff(ctx)
23
- ctx.each_node(:send).flat_map do |node|
24
- next unless node.name.equal?(:respond_to?)
25
-
26
- smell_warning(context: ctx, lines: [node.line], message: MESSAGE)
27
- end.compact
23
+ smelly_nodes = ctx.each_node(:send).select { |node| node.name == :respond_to? }
24
+ return [] if smelly_nodes.empty?
25
+ lines = smelly_nodes.map(&:line)
26
+ [smell_warning(context: ctx, lines: lines, message: MESSAGE)]
28
27
  end
29
28
  end
30
29
  end
@@ -7,6 +7,6 @@ module Reek
7
7
  # @public
8
8
  module Version
9
9
  # @public
10
- STRING = '4.5.4'.freeze
10
+ STRING = '4.5.5'.freeze
11
11
  end
12
12
  end
@@ -1,9 +1,11 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  RSpec.describe 'Reek source code' do
4
- it 'has no smells' do
5
- Pathname.glob('lib/**/*.rb').each do |pathname|
6
- expect(pathname).not_to reek
4
+ Pathname.glob('lib/**/*.rb').each do |pathname|
5
+ describe pathname do
6
+ it 'has no smells' do
7
+ expect(pathname).not_to reek
8
+ end
7
9
  end
8
10
  end
9
11
  end
@@ -100,6 +100,30 @@ RSpec.describe Reek::CLI::Application do
100
100
  configuration: Reek::Configuration::AppConfiguration,
101
101
  options: Reek::CLI::Options)
102
102
  end
103
+
104
+ context 'when source files are excluded through configuration' do
105
+ let(:app) { described_class.new ['--config', 'some_file.reek', '.'] }
106
+
107
+ before do
108
+ allow(Reek::Configuration::AppConfiguration).
109
+ to receive(:from_path).
110
+ with(Pathname.new('some_file.reek')).
111
+ and_return configuration
112
+ end
113
+
114
+ it 'uses configuration for excluded paths' do
115
+ expected_sources = Reek::Source::SourceLocator.
116
+ new(['.'], configuration: configuration).sources
117
+ expect(expected_sources).not_to include(path_excluded_in_configuration)
118
+
119
+ app.execute
120
+
121
+ expect(Reek::CLI::Command::ReportCommand).to have_received(:new).
122
+ with(sources: expected_sources,
123
+ configuration: configuration,
124
+ options: Reek::CLI::Options)
125
+ end
126
+ end
103
127
  end
104
128
  end
105
129
  end
@@ -161,6 +161,13 @@ RSpec.describe Reek::CodeComment::CodeCommentValidator do
161
161
  FactoryGirl.build(:code_comment, comment: comment)
162
162
  end.not_to raise_error
163
163
  end
164
+
165
+ it 'does not raise on regexps' do
166
+ expect do
167
+ comment = '# :reek:UncommunicativeMethodName { exclude: !ruby/regexp /alfa/ }'
168
+ FactoryGirl.build(:code_comment, comment: comment)
169
+ end.not_to raise_error
170
+ end
164
171
  end
165
172
 
166
173
  context 'unknown custom options' do
@@ -30,8 +30,8 @@ RSpec.describe Reek::Report::YAMLReport do
30
30
  out = StringIO.new
31
31
  instance.show(out)
32
32
  out.rewind
33
- result = YAML.load(out.read)
34
- expected = YAML.load <<-EOS
33
+ result = YAML.safe_load(out.read)
34
+ expected = YAML.safe_load <<-EOS
35
35
  ---
36
36
  - context: "simple"
37
37
  lines:
@@ -57,8 +57,8 @@ RSpec.describe Reek::Report::YAMLReport do
57
57
  out = StringIO.new
58
58
  instance.show(out)
59
59
  out.rewind
60
- result = YAML.load(out.read)
61
- expected = YAML.load <<-EOS
60
+ result = YAML.safe_load(out.read)
61
+ expected = YAML.safe_load <<-EOS
62
62
  ---
63
63
  - context: "simple"
64
64
  lines:
@@ -97,11 +97,16 @@ RSpec.describe Reek::SmellDetectors::FeatureEnvy do
97
97
  expect(src).not_to reek_of(:FeatureEnvy)
98
98
  end
99
99
 
100
- it 'does not report parameter method called with super ' do
100
+ it 'does not report parameter method called with super' do
101
101
  src = 'def alfa(bravo) super(bravo.to_s); end'
102
102
  expect(src).not_to reek_of(:FeatureEnvy)
103
103
  end
104
104
 
105
+ it 'reports parameter method called with super and elsewhere' do
106
+ src = 'def alfa(bravo) bravo.charley; super(bravo.to_s); end'
107
+ expect(src).to reek_of(:FeatureEnvy)
108
+ end
109
+
105
110
  it 'ignores multiple ivars' do
106
111
  src = <<-EOS
107
112
  def func
@@ -147,7 +152,7 @@ RSpec.describe Reek::SmellDetectors::FeatureEnvy do
147
152
  and reek_of(:FeatureEnvy, name: 'bravo')
148
153
  end
149
154
 
150
- it 'is not be fooled by duplication' do
155
+ it 'is not fooled by duplication' do
151
156
  src = <<-EOS
152
157
  def alfa(bravo)
153
158
  @charlie.delta(bravo.echo)
@@ -155,18 +160,18 @@ RSpec.describe Reek::SmellDetectors::FeatureEnvy do
155
160
  end
156
161
  EOS
157
162
 
158
- expect(src).to reek_only_of(:DuplicateMethodCall)
163
+ expect(src).to reek_only_of(:DuplicateMethodCall, name: 'bravo.echo')
159
164
  end
160
165
 
161
- it 'does not count local calls' do
166
+ it 'counts local calls' do
162
167
  src = <<-EOS
163
168
  def alfa(bravo)
164
- @charlie.delta(bravo.echo)
165
- @foxtrot.delta(bravo.echo)
169
+ charlie.delta(bravo.echo)
170
+ foxtrot.delta(bravo.echo)
166
171
  end
167
172
  EOS
168
173
 
169
- expect(src).to reek_only_of(:DuplicateMethodCall)
174
+ expect(src).to reek_only_of(:DuplicateMethodCall, name: 'bravo.echo')
170
175
  end
171
176
 
172
177
  it 'reports many calls to lvar' do
@@ -59,4 +59,17 @@ RSpec.describe Reek::SmellDetectors::ManualDispatch do
59
59
 
60
60
  expect(src).to reek_of(:ManualDispatch)
61
61
  end
62
+
63
+ it 'reports occurences in a single method as one smell warning' do
64
+ src = <<-EOS
65
+ class Alfa
66
+ def bravo(charlie, delta)
67
+ return true if charlie.respond_to?(:to_a)
68
+ true if delta.respond_to?(:to_a)
69
+ end
70
+ end
71
+ EOS
72
+
73
+ expect(src).to reek_of(:ManualDispatch, lines: [3, 4], context: 'Alfa#bravo')
74
+ end
62
75
  end
@@ -155,7 +155,7 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
155
155
  it 'handles the case where super receives a block and arguments' do
156
156
  src = <<-EOS
157
157
  def alfa
158
- super do |bravo|
158
+ super(delta) do |bravo|
159
159
  bravo.each { |charlie| charlie }
160
160
  end
161
161
  end
@@ -45,11 +45,6 @@ RSpec.describe Reek::SmellDetectors::SubclassedFromCoreClass do
45
45
  expect(src).not_to reek_of(:SubclassedFromCoreClass)
46
46
  end
47
47
 
48
- it 'reports if we inherit from a core class using Class#new' do
49
- src = 'Alfa = Class.new(Array)'
50
- expect(src).to reek_of(:SubclassedFromCoreClass)
51
- end
52
-
53
48
  it 'reports if inner class inherit from a core class' do
54
49
  src = <<-EOS
55
50
  class Alfa
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: 4.5.4
4
+ version: 4.5.5
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: 2017-01-17 00:00:00.000000000 Z
14
+ date: 2017-02-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: codeclimate-engine-rb
@@ -151,6 +151,7 @@ files:
151
151
  - features/configuration_files/accept_setting.feature
152
152
  - features/configuration_files/directory_specific_directives.feature
153
153
  - features/configuration_files/exclude_directives.feature
154
+ - features/configuration_files/exclude_paths_directives.feature
154
155
  - features/configuration_files/masking_smells.feature
155
156
  - features/configuration_files/mix_accept_reject_setting.feature
156
157
  - features/configuration_files/reject_setting.feature
@@ -434,7 +435,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
434
435
  version: '0'
435
436
  requirements: []
436
437
  rubyforge_project:
437
- rubygems_version: 2.5.1
438
+ rubygems_version: 2.6.8
438
439
  signing_key:
439
440
  specification_version: 4
440
441
  summary: Code smell detector for Ruby