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
@@ -5,9 +5,9 @@ require_relative '../../lib/reek/source/source_code'
|
|
5
5
|
# Dummy repository to inject into TreeWalker in order to count statements in
|
6
6
|
# all contexts.
|
7
7
|
class TestSmellRepository
|
8
|
-
|
8
|
+
attr_accessor :num_statements
|
9
9
|
def examine(context)
|
10
|
-
|
10
|
+
self.num_statements = context.num_statements
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -95,6 +95,18 @@ RSpec.describe Reek::TreeWalker, 'statement counting' do
|
|
95
95
|
expect(method.num_statements).to eq(6)
|
96
96
|
end
|
97
97
|
|
98
|
+
it 'does not count constant assignment with or equals' do
|
99
|
+
source = 'class Hi; CONST ||= 1; end'
|
100
|
+
klass = process_method(source)
|
101
|
+
expect(klass.num_statements).to eq(0)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'does not count multi constant assignment' do
|
105
|
+
source = 'class Hi; CONST, OTHER_CONST = 1, 2; end'
|
106
|
+
klass = process_method(source)
|
107
|
+
expect(klass.num_statements).to eq(0)
|
108
|
+
end
|
109
|
+
|
98
110
|
it 'does not count empty conditional expression' do
|
99
111
|
method = process_method('def one() if val == 4; ; end; end')
|
100
112
|
expect(method.num_statements).to eq(0)
|
data/spec/spec_helper.rb
CHANGED
@@ -25,10 +25,9 @@ SAMPLES_PATH = Pathname.new("#{__dir__}/samples").relative_path_from(Pathname.pw
|
|
25
25
|
module Helpers
|
26
26
|
def test_configuration_for(config)
|
27
27
|
if config.is_a? Pathname
|
28
|
-
configuration = Reek::Configuration::AppConfiguration.
|
28
|
+
configuration = Reek::Configuration::AppConfiguration.from_path(config)
|
29
29
|
elsif config.is_a? Hash
|
30
|
-
configuration = Reek::Configuration::AppConfiguration.
|
31
|
-
configuration.instance_variable_set :@default_directive, config
|
30
|
+
configuration = Reek::Configuration::AppConfiguration.from_map default_directive: config
|
32
31
|
else
|
33
32
|
raise "Unknown config given in `test_configuration_for`: #{config.inspect}"
|
34
33
|
end
|
data/tasks/test.rake
CHANGED
@@ -7,11 +7,6 @@ namespace 'test' do
|
|
7
7
|
t.ruby_opts = ['-Ilib -w']
|
8
8
|
end
|
9
9
|
|
10
|
-
desc 'Tests various release attributes of the gem'
|
11
|
-
RSpec::Core::RakeTask.new('gem') do |t|
|
12
|
-
t.pattern = 'spec/gem/**/*_spec.rb'
|
13
|
-
end
|
14
|
-
|
15
10
|
desc 'Tests code quality'
|
16
11
|
RSpec::Core::RakeTask.new('quality') do |t|
|
17
12
|
t.pattern = 'spec/quality/**/*_spec.rb'
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Rutherford
|
8
8
|
- Timo Roessner
|
9
9
|
- Matijs van Zuijlen
|
10
|
+
- Piotr Szotkowski
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2015-08-
|
14
|
+
date: 2015-08-22 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: parser
|
@@ -226,7 +227,6 @@ files:
|
|
226
227
|
- docs/Class-Variable.md
|
227
228
|
- docs/Code-Smells.md
|
228
229
|
- docs/Command-Line-Options.md
|
229
|
-
- docs/Configuration-Files.md
|
230
230
|
- docs/Control-Couple.md
|
231
231
|
- docs/Control-Parameter.md
|
232
232
|
- docs/Data-Clump.md
|
@@ -296,6 +296,10 @@ files:
|
|
296
296
|
- lib/reek/code_comment.rb
|
297
297
|
- lib/reek/configuration/app_configuration.rb
|
298
298
|
- lib/reek/configuration/configuration_file_finder.rb
|
299
|
+
- lib/reek/configuration/configuration_validator.rb
|
300
|
+
- lib/reek/configuration/default_directive.rb
|
301
|
+
- lib/reek/configuration/directory_directives.rb
|
302
|
+
- lib/reek/configuration/excluded_paths.rb
|
299
303
|
- lib/reek/context/code_context.rb
|
300
304
|
- lib/reek/context/method_context.rb
|
301
305
|
- lib/reek/context/module_context.rb
|
@@ -349,8 +353,6 @@ files:
|
|
349
353
|
- lib/reek/version.rb
|
350
354
|
- reek.gemspec
|
351
355
|
- spec/factories/factories.rb
|
352
|
-
- spec/gem/updates_spec.rb
|
353
|
-
- spec/gem/yard_spec.rb
|
354
356
|
- spec/quality/reek_source_spec.rb
|
355
357
|
- spec/reek/ast/node_spec.rb
|
356
358
|
- spec/reek/ast/object_refs_spec.rb
|
@@ -363,6 +365,9 @@ files:
|
|
363
365
|
- spec/reek/code_comment_spec.rb
|
364
366
|
- spec/reek/configuration/app_configuration_spec.rb
|
365
367
|
- spec/reek/configuration/configuration_file_finder_spec.rb
|
368
|
+
- spec/reek/configuration/default_directive_spec.rb
|
369
|
+
- spec/reek/configuration/directory_directives_spec.rb
|
370
|
+
- spec/reek/configuration/excluded_paths_spec.rb
|
366
371
|
- spec/reek/context/code_context_spec.rb
|
367
372
|
- spec/reek/context/method_context_spec.rb
|
368
373
|
- spec/reek/context/module_context_spec.rb
|
@@ -375,7 +380,6 @@ files:
|
|
375
380
|
- spec/reek/report/xml_report_spec.rb
|
376
381
|
- spec/reek/report/yaml_report_spec.rb
|
377
382
|
- spec/reek/smells/attribute_spec.rb
|
378
|
-
- spec/reek/smells/behaves_like_variable_detector.rb
|
379
383
|
- spec/reek/smells/boolean_parameter_spec.rb
|
380
384
|
- spec/reek/smells/class_variable_spec.rb
|
381
385
|
- spec/reek/smells/control_parameter_spec.rb
|
data/docs/Configuration-Files.md
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# Configuration Files
|
2
|
-
|
3
|
-
## Configuration loading
|
4
|
-
|
5
|
-
Configuring `reek` via configuration file is by far the most powerful way.
|
6
|
-
|
7
|
-
There are 3 ways of passing `reek` a configuration file:
|
8
|
-
|
9
|
-
1. Using the cli "-c" switch (see [Command Line Options](Command-Line-Options.md))
|
10
|
-
2. Having a file ending with .reek either in your current working directory or in a parent directory (more on that later)
|
11
|
-
3. Having a file ending with .reek in your HOME directory
|
12
|
-
|
13
|
-
The order in which `reek` tries to find such a configuration file is exactly like above: First `reek` checks if we have given it a configuration file explicitly via CLI. Then it checks the current working directory for a file and if it can't find one, it traverses up the directories until it hits the root directory. And lastly, it checks your HOME directory.
|
14
|
-
|
15
|
-
As soon as `reek` detects a configuration file it stops searching immediately, meaning that from `reek`'s point of view there exists one configuration file and one configuration only regardless of how many ".reek" files you might have on your filesystem.
|
16
|
-
|
17
|
-
## Configuration options for smells
|
18
|
-
|
19
|
-
The first thing you probably want to check out are the [Basic Smell Options](Basic-Smell-Options.md) which are supported by every smell type.
|
20
|
-
Certain smell types offer a configuration that goes beyond that of the basic smell options - for instance [Data Clump](Data-Clump.md).
|
21
|
-
All options that go beyond the [Basic Smell Options](Basic-Smell-Options.md) should be documented in the corresponding smell type wiki page but if you want to get a quick and full overview over all possible configurations you can always check out [the default.reek file in this repository](https://github.com/troessner/reek/blob/master/config/defaults.reek).
|
22
|
-
|
23
|
-
Here's an excerpt of a `reek` configuration file from a commercial project:
|
24
|
-
|
25
|
-
```yaml
|
26
|
-
---
|
27
|
-
IrresponsibleModule:
|
28
|
-
enabled: false
|
29
|
-
NestedIterators:
|
30
|
-
exclude:
|
31
|
-
- "ActiveModelErrorAdder#self.run" # should be refactored
|
32
|
-
- "BookingRequests::Transfer#remote_validation"
|
33
|
-
- "BookingRequestsController#vehicle_options" # respond_to block
|
34
|
-
- "Content::Base#self.expose_fields" # unavoidable due to metaprogramming
|
35
|
-
DataClump:
|
36
|
-
max_copies: 3
|
37
|
-
min_clump_size: 3
|
38
|
-
```
|
39
|
-
|
40
|
-
## Excluding directories from scans
|
41
|
-
|
42
|
-
You can exclude whole directories from scans using `exclude_paths` in your configuration file:
|
43
|
-
|
44
|
-
```yaml
|
45
|
-
---
|
46
|
-
exclude_paths:
|
47
|
-
- app/views
|
48
|
-
- app/controllers
|
49
|
-
```
|
data/spec/gem/updates_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
require 'find'
|
3
|
-
|
4
|
-
release_timestamp_file = 'build/.last-release'
|
5
|
-
if test('f', release_timestamp_file)
|
6
|
-
describe 'updates' do
|
7
|
-
before :each do
|
8
|
-
@release_time = File.stat(release_timestamp_file).mtime
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'version file' do
|
12
|
-
it 'has been updated since the last release' do
|
13
|
-
version_time = File.stat('lib/reek.rb').mtime
|
14
|
-
expect(version_time).to be > @release_time
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'history file' do
|
19
|
-
it 'has been updated since the last release' do
|
20
|
-
history_time = File.stat('History.txt').mtime
|
21
|
-
expect(history_time).to be > @release_time
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/spec/gem/yard_spec.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
require_relative '../spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe 'yardoc' do
|
5
|
-
it 'executes successfully with no warnings' do
|
6
|
-
stdout, stderr, status = Open3.capture3('yardoc')
|
7
|
-
expect(stdout).to_not include('[warn]')
|
8
|
-
expect(stderr).to be_empty
|
9
|
-
expect(status).to be_success
|
10
|
-
end
|
11
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
RSpec.shared_examples_for 'a variable detector' do
|
2
|
-
context 'with no variables' do
|
3
|
-
it "doesn't record a smell" do
|
4
|
-
@detector.examine_context(@ctx)
|
5
|
-
expect(@detector.smells_found.length).to eq(0)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
context 'with one variable encountered twice' do
|
10
|
-
before :each do
|
11
|
-
@ctx.send(@record_variable, :something)
|
12
|
-
@ctx.send(@record_variable, :something)
|
13
|
-
@detector.examine_context(@ctx)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'records only one smell' do
|
17
|
-
expect(@detector.smells_found.length).to eq(1)
|
18
|
-
end
|
19
|
-
it 'mentions the variable name in the report' do
|
20
|
-
expect(@detector).to have_smell([/something/])
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with two variables' do
|
25
|
-
before :each do
|
26
|
-
@ctx.send(@record_variable, :something)
|
27
|
-
@ctx.send(@record_variable, :something_else)
|
28
|
-
@detector.examine_context(@ctx)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'records both smells' do
|
32
|
-
expect(@detector.num_smells).to eq(2)
|
33
|
-
end
|
34
|
-
it 'mentions both variable names in the report' do
|
35
|
-
expect(@detector).to have_smell([/something/])
|
36
|
-
expect(@detector).to have_smell([/something_else/])
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|