reek 2.0.4 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +13 -0
- data/.rubocop.yml +66 -0
- data/.ruby-gemset +1 -0
- data/.travis.yml +25 -0
- data/CHANGELOG +6 -0
- data/CONTRIBUTING.md +106 -0
- data/Gemfile +14 -0
- data/README.md +16 -21
- data/bin/reek +2 -2
- data/config/cucumber.yml +3 -0
- data/config/defaults.reek +1 -1
- data/features/command_line_interface/smell_selection.feature +4 -8
- data/features/command_line_interface/smells_count.feature +25 -32
- data/features/command_line_interface/stdin.feature +2 -2
- data/features/configuration_files/masking_smells.feature +30 -41
- data/features/configuration_files/overrides_defaults.feature +5 -3
- data/features/configuration_loading.feature +26 -23
- data/features/programmatic_access.feature +24 -0
- data/features/rake_task/rake_task.feature +25 -22
- data/features/reports/json.feature +24 -26
- data/features/reports/reports.feature +77 -103
- data/features/reports/yaml.feature +26 -20
- data/features/ruby_api/api.feature +4 -3
- data/features/samples.feature +21 -20
- data/features/step_definitions/.rubocop.yml +5 -0
- data/features/step_definitions/reek_steps.rb +16 -28
- data/features/step_definitions/sample_file_steps.rb +158 -0
- data/features/support/env.rb +16 -27
- data/lib/reek.rb +3 -3
- data/lib/reek/cli/application.rb +4 -4
- data/lib/reek/cli/command.rb +1 -1
- data/lib/reek/cli/input.rb +2 -4
- data/lib/reek/cli/option_interpreter.rb +9 -9
- data/lib/reek/cli/options.rb +5 -4
- data/lib/reek/cli/reek_command.rb +3 -3
- data/lib/reek/cli/report/formatter.rb +2 -2
- data/lib/reek/cli/report/heading_formatter.rb +1 -1
- data/lib/reek/cli/report/location_formatter.rb +1 -1
- data/lib/reek/cli/report/report.rb +4 -4
- data/lib/reek/configuration/app_configuration.rb +1 -1
- data/lib/reek/configuration/configuration_file_finder.rb +17 -32
- data/lib/reek/core/code_context.rb +1 -1
- data/lib/reek/core/method_context.rb +6 -2
- data/lib/reek/core/module_context.rb +2 -2
- data/lib/reek/core/singleton_method_context.rb +1 -1
- data/lib/reek/core/smell_repository.rb +3 -2
- data/lib/reek/core/tree_walker.rb +4 -4
- data/lib/reek/examiner.rb +4 -4
- data/lib/reek/smells/attribute.rb +3 -3
- data/lib/reek/smells/boolean_parameter.rb +2 -2
- data/lib/reek/smells/class_variable.rb +2 -2
- data/lib/reek/smells/control_parameter.rb +2 -2
- data/lib/reek/smells/data_clump.rb +2 -3
- data/lib/reek/smells/duplicate_method_call.rb +2 -2
- data/lib/reek/smells/feature_envy.rb +6 -2
- data/lib/reek/smells/irresponsible_module.rb +3 -3
- data/lib/reek/smells/long_parameter_list.rb +3 -3
- data/lib/reek/smells/long_yield_list.rb +2 -2
- data/lib/reek/smells/module_initialize.rb +2 -2
- data/lib/reek/smells/nested_iterators.rb +2 -2
- data/lib/reek/smells/nil_check.rb +2 -2
- data/lib/reek/smells/prima_donna_method.rb +2 -2
- data/lib/reek/smells/repeated_conditional.rb +3 -2
- data/lib/reek/smells/smell_detector.rb +2 -2
- data/lib/reek/smells/too_many_instance_variables.rb +2 -2
- data/lib/reek/smells/too_many_methods.rb +2 -2
- data/lib/reek/smells/too_many_statements.rb +2 -2
- data/lib/reek/smells/uncommunicative_method_name.rb +2 -2
- data/lib/reek/smells/uncommunicative_module_name.rb +2 -2
- data/lib/reek/smells/uncommunicative_parameter_name.rb +2 -2
- data/lib/reek/smells/uncommunicative_variable_name.rb +2 -2
- data/lib/reek/smells/unused_parameters.rb +2 -2
- data/lib/reek/smells/utility_function.rb +8 -9
- data/lib/reek/source/ast_node.rb +1 -1
- data/lib/reek/source/ast_node_class_map.rb +6 -6
- data/lib/reek/source/sexp_extensions.rb +11 -2
- data/lib/reek/source/source_code.rb +10 -2
- data/lib/reek/source/source_locator.rb +1 -3
- data/lib/reek/source/source_repository.rb +3 -4
- data/lib/reek/source/tree_dresser.rb +2 -2
- data/lib/reek/spec.rb +3 -3
- data/lib/reek/spec/should_reek.rb +3 -3
- data/lib/reek/spec/should_reek_of.rb +1 -1
- data/lib/reek/spec/should_reek_only_of.rb +3 -3
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +18 -24
- data/spec/factories/factories.rb +1 -1
- data/spec/gem/updates_spec.rb +1 -1
- data/spec/gem/yard_spec.rb +1 -1
- data/spec/quality/reek_source_spec.rb +1 -1
- data/spec/reek/cli/html_report_spec.rb +6 -9
- data/spec/reek/cli/json_report_spec.rb +6 -6
- data/spec/reek/cli/option_interperter_spec.rb +5 -5
- data/spec/reek/cli/text_report_spec.rb +16 -19
- data/spec/reek/cli/yaml_report_spec.rb +7 -10
- data/spec/reek/configuration/app_configuration_spec.rb +23 -25
- data/spec/reek/configuration/configuration_file_finder_spec.rb +46 -21
- data/spec/reek/core/code_context_spec.rb +17 -19
- data/spec/reek/core/method_context_spec.rb +15 -14
- data/spec/reek/core/module_context_spec.rb +5 -7
- data/spec/reek/core/object_refs_spec.rb +4 -6
- data/spec/reek/core/singleton_method_context_spec.rb +5 -7
- data/spec/reek/core/smell_configuration_spec.rb +5 -7
- data/spec/reek/core/smell_repository_spec.rb +8 -8
- data/spec/reek/core/stop_context_spec.rb +4 -7
- data/spec/reek/core/tree_walker_spec.rb +5 -7
- data/spec/reek/core/warning_collector_spec.rb +5 -7
- data/spec/reek/examiner_spec.rb +10 -12
- data/spec/reek/smell_warning_spec.rb +7 -9
- data/spec/reek/smells/attribute_spec.rb +6 -6
- data/spec/reek/smells/boolean_parameter_spec.rb +4 -4
- data/spec/reek/smells/class_variable_spec.rb +6 -6
- data/spec/reek/smells/control_parameter_spec.rb +4 -4
- data/spec/reek/smells/data_clump_spec.rb +4 -4
- data/spec/reek/smells/duplicate_method_call_spec.rb +6 -6
- data/spec/reek/smells/feature_envy_spec.rb +9 -10
- data/spec/reek/smells/irresponsible_module_spec.rb +7 -7
- data/spec/reek/smells/long_parameter_list_spec.rb +5 -5
- data/spec/reek/smells/long_yield_list_spec.rb +5 -5
- data/spec/reek/smells/module_initialize_spec.rb +3 -3
- data/spec/reek/smells/nested_iterators_spec.rb +4 -4
- data/spec/reek/smells/nil_check_spec.rb +5 -5
- data/spec/reek/smells/prima_donna_method_spec.rb +7 -4
- data/spec/reek/smells/repeated_conditional_spec.rb +12 -11
- data/spec/reek/smells/smell_detector_shared.rb +4 -5
- data/spec/reek/smells/too_many_instance_variables_spec.rb +4 -4
- data/spec/reek/smells/too_many_methods_spec.rb +11 -7
- data/spec/reek/smells/too_many_statements_spec.rb +6 -5
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +4 -4
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +7 -7
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +5 -5
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +9 -6
- data/spec/reek/smells/unused_parameters_spec.rb +3 -3
- data/spec/reek/smells/utility_function_spec.rb +41 -37
- data/spec/reek/source/code_comment_spec.rb +19 -17
- data/spec/reek/source/object_source_spec.rb +1 -3
- data/spec/reek/source/reference_collector_spec.rb +5 -6
- data/spec/reek/source/sexp_extensions_spec.rb +9 -11
- data/spec/reek/source/sexp_formatter_spec.rb +7 -8
- data/spec/reek/source/sexp_node_spec.rb +3 -5
- data/spec/reek/source/source_code_spec.rb +9 -9
- data/spec/reek/source/tree_dresser_spec.rb +4 -6
- data/spec/reek/spec/should_reek_of_spec.rb +11 -10
- data/spec/reek/spec/should_reek_only_of_spec.rb +4 -7
- data/spec/reek/spec/should_reek_spec.rb +4 -7
- data/spec/samples/{overrides/masked/lower.reek → masked_by_dotfile/.reek} +3 -1
- data/spec/spec_helper.rb +4 -4
- data/tasks/develop.rake +1 -1
- data/tasks/reek.rake +1 -1
- metadata +72 -86
- data/features/support/hooks.rb +0 -15
- data/lib/reek/source.rb +0 -16
- data/lib/reek/source/core_extras.rb +0 -46
- data/lib/reek/source/source_file.rb +0 -16
- data/spec/samples/config/allow_duplication.reek +0 -3
- data/spec/samples/config/deeper_nested_iterators.reek +0 -3
- data/spec/samples/configuration_loading/minimal_dirty.rb +0 -4
- data/spec/samples/configuration_loading/reek-test-run-disable_smells.reek +0 -7
- data/spec/samples/configuration_loading/reek-test-run-enable_smells.reek +0 -7
- data/spec/samples/corrupt_config_file/corrupt.reek +0 -1
- data/spec/samples/corrupt_config_file/dirty.rb +0 -8
- data/spec/samples/demo/demo.rb +0 -8
- data/spec/samples/empty_config_file/dirty.rb +0 -8
- data/spec/samples/empty_config_file/empty.reek +0 -0
- data/spec/samples/inline_config/dirty.rb +0 -16
- data/spec/samples/inline_config/masked.reek +0 -7
- data/spec/samples/mask_some/dirty.rb +0 -8
- data/spec/samples/mask_some/some.reek +0 -8
- data/spec/samples/masked/dirty.rb +0 -8
- data/spec/samples/masked/masked.reek +0 -5
- data/spec/samples/minimal_smelly_and_masked/config.reek +0 -7
- data/spec/samples/minimal_smelly_and_masked/minimal_dirty.rb +0 -4
- data/spec/samples/mixed_results/clean_one.rb +0 -7
- data/spec/samples/mixed_results/clean_three.rb +0 -7
- data/spec/samples/mixed_results/clean_two.rb +0 -7
- data/spec/samples/mixed_results/dirty_one.rb +0 -8
- data/spec/samples/mixed_results/dirty_two.rb +0 -8
- data/spec/samples/not_quite_masked/dirty.rb +0 -8
- data/spec/samples/not_quite_masked/masked.reek +0 -5
- data/spec/samples/not_quite_masked/smelly.rb +0 -3
- data/spec/samples/one_smelly_file/dirty.rb +0 -3
- data/spec/samples/overrides/masked/dirty.rb +0 -8
- data/spec/samples/overrides/upper.reek +0 -5
- data/spec/samples/overrides_defaults/camel_case.rb +0 -14
- data/spec/samples/overrides_defaults/config.reek +0 -6
- data/spec/samples/standard_smelly/dirty.rb +0 -8
- data/spec/samples/standard_smelly/minimal_dirty.rb +0 -4
- data/spec/samples/three_smelly_files/dirty_one.rb +0 -3
- data/spec/samples/three_smelly_files/dirty_three.rb +0 -5
- data/spec/samples/three_smelly_files/dirty_two.rb +0 -4
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/reek/smells/uncommunicative_parameter_name'
|
3
|
+
require_relative 'smell_detector_shared'
|
4
|
+
require_relative '../../../lib/reek/core/method_context'
|
5
5
|
|
6
6
|
describe Reek::Smells::UncommunicativeParameterName do
|
7
7
|
before :each do
|
@@ -69,7 +69,7 @@ describe Reek::Smells::UncommunicativeParameterName do
|
|
69
69
|
context 'looking at the smell result fields' do
|
70
70
|
before :each do
|
71
71
|
src = 'def bad(good, bad2, good_again); basics(good, bad2, good_again); end'
|
72
|
-
ctx = Reek::Core::MethodContext.new(nil, src.
|
72
|
+
ctx = Reek::Core::MethodContext.new(nil, Reek::Source::SourceCode.from(src).syntax_tree)
|
73
73
|
@smells = @detector.examine_context(ctx)
|
74
74
|
@warning = @smells[0]
|
75
75
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/reek/smells/uncommunicative_variable_name'
|
3
|
+
require_relative 'smell_detector_shared'
|
4
4
|
|
5
5
|
describe Reek::Smells::UncommunicativeVariableName do
|
6
6
|
before :each do
|
@@ -52,7 +52,8 @@ describe Reek::Smells::UncommunicativeVariableName do
|
|
52
52
|
|
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
57
|
smells = @detector.examine_context(ctx)
|
57
58
|
expect(smells.length).to eq(1)
|
58
59
|
expect(smells[0].smell_type).to eq(described_class.smell_type)
|
@@ -163,7 +164,8 @@ describe Reek::Smells::UncommunicativeVariableName do
|
|
163
164
|
end
|
164
165
|
end
|
165
166
|
EOS
|
166
|
-
|
167
|
+
syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
|
168
|
+
ctx = Reek::Core::CodeContext.new(nil, syntax_tree)
|
167
169
|
@smells = @detector.examine_context(ctx)
|
168
170
|
@warning = @smells[0]
|
169
171
|
end
|
@@ -179,7 +181,8 @@ describe Reek::Smells::UncommunicativeVariableName do
|
|
179
181
|
context 'when a smell is reported in a singleton method' do
|
180
182
|
before :each do
|
181
183
|
src = 'def self.bad() x2 = 4; end'
|
182
|
-
|
184
|
+
syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
|
185
|
+
ctx = Reek::Core::CodeContext.new(nil, syntax_tree)
|
183
186
|
@smells = @detector.examine_context(ctx)
|
184
187
|
@warning = @smells[0]
|
185
188
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/reek/smells/unused_parameters'
|
3
|
+
require_relative 'smell_detector_shared'
|
4
4
|
|
5
5
|
describe Reek::Smells::UnusedParameters do
|
6
6
|
context 'for methods' do
|
@@ -1,30 +1,50 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/reek/smells/utility_function'
|
3
|
+
require_relative 'smell_detector_shared'
|
4
4
|
|
5
5
|
describe Reek::Smells::UtilityFunction do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
describe 'a detector' do
|
7
|
+
before(:each) do
|
8
|
+
@source_name = 'dummy_source'
|
9
|
+
@detector = build(:smell_detector,
|
10
|
+
smell_type: :UtilityFunction,
|
11
|
+
source: @source_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
it_should_behave_like 'SmellDetector'
|
15
|
+
|
16
|
+
context 'when a smells is reported' do
|
17
|
+
before :each do
|
18
|
+
src = <<-EOS
|
19
|
+
def simple(arga)
|
20
|
+
arga.b.c
|
21
|
+
end
|
22
|
+
EOS
|
23
|
+
source = Reek::Source::SourceCode.from(src)
|
24
|
+
mctx = Reek::Core::TreeWalker.new.process_def(source.syntax_tree)
|
25
|
+
@warning = @detector.examine_context(mctx)[0] # SMELL: too cumbersome!
|
26
|
+
end
|
27
|
+
|
28
|
+
it_should_behave_like 'common fields set correctly'
|
10
29
|
|
11
|
-
|
30
|
+
it 'reports the line number of the method' do
|
31
|
+
expect(@warning.lines).to eq([1])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
12
35
|
|
13
36
|
context 'with a singleton method' do
|
14
37
|
['self', 'local_call', '$global'].each do |receiver|
|
15
38
|
it 'ignores the receiver' do
|
16
39
|
src = "def #{receiver}.simple(arga) arga.to_s + arga.to_i end"
|
17
|
-
|
18
|
-
expect(@detector.examine_context(ctx)).to be_empty
|
40
|
+
expect(src).not_to reek_of(:UtilityFunction)
|
19
41
|
end
|
20
42
|
end
|
21
43
|
end
|
22
44
|
|
23
45
|
context 'with no calls' do
|
24
46
|
it 'does not report empty method' do
|
25
|
-
|
26
|
-
ctx = Reek::Core::MethodContext.new(nil, src.to_reek_source.syntax_tree)
|
27
|
-
expect(@detector.examine_context(ctx)).to be_empty
|
47
|
+
expect('def simple(arga) end').not_to reek_of(:UtilityFunction)
|
28
48
|
end
|
29
49
|
|
30
50
|
it 'does not report literal' do
|
@@ -53,12 +73,12 @@ describe Reek::Smells::UtilityFunction do
|
|
53
73
|
end
|
54
74
|
|
55
75
|
context 'with only one call' do
|
56
|
-
it '
|
57
|
-
expect('def simple(arga) arga.to_s end').
|
76
|
+
it 'reports a call to a parameter' do
|
77
|
+
expect('def simple(arga) arga.to_s end').to reek_of(:UtilityFunction, name: 'simple')
|
58
78
|
end
|
59
79
|
|
60
|
-
it '
|
61
|
-
expect('def simple(arga) FIELDS[arga] end').
|
80
|
+
it 'reports a call to a constant' do
|
81
|
+
expect('def simple(arga) FIELDS[arga] end').to reek_of(:UtilityFunction)
|
62
82
|
end
|
63
83
|
end
|
64
84
|
|
@@ -66,6 +86,7 @@ describe Reek::Smells::UtilityFunction do
|
|
66
86
|
it 'reports two calls' do
|
67
87
|
src = 'def simple(arga) arga.to_s + arga.to_i end'
|
68
88
|
expect(src).to reek_of(:UtilityFunction, name: 'simple')
|
89
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
69
90
|
end
|
70
91
|
|
71
92
|
it 'counts a local call in a param initializer' do
|
@@ -88,7 +109,9 @@ describe Reek::Smells::UtilityFunction do
|
|
88
109
|
end
|
89
110
|
|
90
111
|
it 'should report message chain' do
|
91
|
-
|
112
|
+
src = 'def simple(arga) arga.b.c end'
|
113
|
+
expect(src).to reek_of(:UtilityFunction, name: 'simple')
|
114
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
92
115
|
end
|
93
116
|
|
94
117
|
it 'does not report a method that calls super' do
|
@@ -110,23 +133,4 @@ describe Reek::Smells::UtilityFunction do
|
|
110
133
|
expect(src).not_to reek_of(:UtilityFunction)
|
111
134
|
end
|
112
135
|
end
|
113
|
-
|
114
|
-
context 'when a smells is reported' do
|
115
|
-
before :each do
|
116
|
-
src = <<-EOS
|
117
|
-
def simple(arga)
|
118
|
-
arga.b.c
|
119
|
-
end
|
120
|
-
EOS
|
121
|
-
source = src.to_reek_source
|
122
|
-
mctx = Reek::Core::TreeWalker.new.process_def(source.syntax_tree)
|
123
|
-
@warning = @detector.examine_context(mctx)[0] # SMELL: too cumbersome!
|
124
|
-
end
|
125
|
-
|
126
|
-
it_should_behave_like 'common fields set correctly'
|
127
|
-
|
128
|
-
it 'reports the line number of the method' do
|
129
|
-
expect(@warning.lines).to eq([1])
|
130
|
-
end
|
131
|
-
end
|
132
136
|
end
|
@@ -1,12 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/reek/source/code_comment'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
describe CodeComment do
|
4
|
+
describe Reek::Source::CodeComment do
|
7
5
|
context 'with an empty comment' do
|
8
6
|
before :each do
|
9
|
-
@comment = CodeComment.new('')
|
7
|
+
@comment = Reek::Source::CodeComment.new('')
|
10
8
|
end
|
11
9
|
it 'is not descriptive' do
|
12
10
|
expect(@comment).not_to be_descriptive
|
@@ -18,34 +16,37 @@ describe CodeComment do
|
|
18
16
|
|
19
17
|
context 'comment checks' do
|
20
18
|
it 'rejects an empty comment' do
|
21
|
-
expect(CodeComment.new('#')).not_to be_descriptive
|
19
|
+
expect(Reek::Source::CodeComment.new('#')).not_to be_descriptive
|
22
20
|
end
|
23
21
|
it 'rejects a 1-word comment' do
|
24
|
-
expect(CodeComment.new("# fred\n# ")).not_to be_descriptive
|
22
|
+
expect(Reek::Source::CodeComment.new("# fred\n# ")).not_to be_descriptive
|
25
23
|
end
|
26
24
|
it 'accepts a 2-word comment' do
|
27
|
-
expect(CodeComment.new('# fred here ')).to be_descriptive
|
25
|
+
expect(Reek::Source::CodeComment.new('# fred here ')).to be_descriptive
|
28
26
|
end
|
29
27
|
it 'accepts a multi-word comment' do
|
30
|
-
|
28
|
+
comment = "# fred here \n# with \n # biscuits "
|
29
|
+
expect(Reek::Source::CodeComment.new(comment)).to be_descriptive
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
33
|
context 'comment config' do
|
35
34
|
it 'parses hashed options' do
|
36
|
-
|
35
|
+
comment = '# :reek:Duplication: { enabled: false }'
|
36
|
+
config = Reek::Source::CodeComment.new(comment).config
|
37
37
|
expect(config).to include('Duplication')
|
38
38
|
expect(config['Duplication']).to include('enabled')
|
39
39
|
expect(config['Duplication']['enabled']).to be_falsey
|
40
40
|
end
|
41
41
|
it 'parses hashed options with ruby names' do
|
42
|
-
|
42
|
+
comment = '# :reek:nested_iterators: { enabled: true }'
|
43
|
+
config = Reek::Source::CodeComment.new(comment).config
|
43
44
|
expect(config).to include('NestedIterators')
|
44
45
|
expect(config['NestedIterators']).to include('enabled')
|
45
46
|
expect(config['NestedIterators']['enabled']).to be_truthy
|
46
47
|
end
|
47
48
|
it 'parses multiple hashed options' do
|
48
|
-
config = CodeComment.new('
|
49
|
+
config = Reek::Source::CodeComment.new('
|
49
50
|
# :reek:Duplication: { enabled: false }
|
50
51
|
:reek:nested_iterators: { enabled: true }
|
51
52
|
').config
|
@@ -56,7 +57,7 @@ describe CodeComment do
|
|
56
57
|
expect(config['NestedIterators']['enabled']).to be_truthy
|
57
58
|
end
|
58
59
|
it 'parses multiple hashed options on the same line' do
|
59
|
-
config = CodeComment.new('
|
60
|
+
config = Reek::Source::CodeComment.new('
|
60
61
|
#:reek:Duplication: { enabled: false } and :reek:nested_iterators: { enabled: true }
|
61
62
|
').config
|
62
63
|
expect(config).to include('Duplication', 'NestedIterators')
|
@@ -66,7 +67,8 @@ describe CodeComment do
|
|
66
67
|
expect(config['NestedIterators']['enabled']).to be_truthy
|
67
68
|
end
|
68
69
|
it 'parses multiple unhashed options on the same line' do
|
69
|
-
|
70
|
+
comment = '# :reek:Duplication and :reek:nested_iterators'
|
71
|
+
config = Reek::Source::CodeComment.new(comment).config
|
70
72
|
expect(config).to include('Duplication', 'NestedIterators')
|
71
73
|
expect(config['Duplication']).to include('enabled')
|
72
74
|
expect(config['Duplication']['enabled']).to be_falsey
|
@@ -74,13 +76,13 @@ describe CodeComment do
|
|
74
76
|
expect(config['NestedIterators']['enabled']).to be_falsey
|
75
77
|
end
|
76
78
|
it 'disables the smell if no options are specifed' do
|
77
|
-
config = CodeComment.new('# :reek:Duplication').config
|
79
|
+
config = Reek::Source::CodeComment.new('# :reek:Duplication').config
|
78
80
|
expect(config).to include('Duplication')
|
79
81
|
expect(config['Duplication']).to include('enabled')
|
80
82
|
expect(config['Duplication']['enabled']).to be_falsey
|
81
83
|
end
|
82
84
|
it 'ignores smells after a space' do
|
83
|
-
config = CodeComment.new('# :reek: Duplication').config
|
85
|
+
config = Reek::Source::CodeComment.new('# :reek: Duplication').config
|
84
86
|
expect(config).not_to include('Duplication')
|
85
87
|
end
|
86
88
|
end
|
@@ -1,12 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/reek/source/reference_collector'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
describe ReferenceCollector do
|
4
|
+
describe Reek::Source::ReferenceCollector do
|
7
5
|
context 'counting refs to self' do
|
8
6
|
def refs_to_self(src)
|
9
|
-
|
7
|
+
syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
|
8
|
+
Reek::Source::ReferenceCollector.new(syntax_tree).num_refs_to_self
|
10
9
|
end
|
11
10
|
it 'with no refs to self' do
|
12
11
|
expect(refs_to_self('def no_envy(arga) arga.barg end')).to eq(0)
|
@@ -1,9 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/reek/source/sexp_extensions'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
describe SexpExtensions::DefNode do
|
4
|
+
describe Reek::Source::SexpExtensions::DefNode do
|
7
5
|
context 'with no parameters' do
|
8
6
|
before :each do
|
9
7
|
@node = s(:def, :hello, s(:args))
|
@@ -112,7 +110,7 @@ describe SexpExtensions::DefNode do
|
|
112
110
|
|
113
111
|
it 'has a body extended with SexpNode' do
|
114
112
|
b = @node.body
|
115
|
-
expect(b.class.included_modules.first).to eq SexpNode
|
113
|
+
expect(b.class.included_modules.first).to eq Reek::Source::SexpNode
|
116
114
|
end
|
117
115
|
|
118
116
|
it 'finds nodes in the body with #body_nodes' do
|
@@ -135,7 +133,7 @@ describe SexpExtensions::DefNode do
|
|
135
133
|
end
|
136
134
|
end
|
137
135
|
|
138
|
-
describe SexpExtensions::DefsNode do
|
136
|
+
describe Reek::Source::SexpExtensions::DefsNode do
|
139
137
|
context 'with no parameters' do
|
140
138
|
before :each do
|
141
139
|
@node = s(:defs, s(:lvar, :obj), :hello, s(:args))
|
@@ -244,12 +242,12 @@ describe SexpExtensions::DefsNode do
|
|
244
242
|
|
245
243
|
it 'has a body extended with SexpNode' do
|
246
244
|
b = @node.body
|
247
|
-
expect(b.class.included_modules.first).to eq SexpNode
|
245
|
+
expect(b.class.included_modules.first).to eq Reek::Source::SexpNode
|
248
246
|
end
|
249
247
|
end
|
250
248
|
end
|
251
249
|
|
252
|
-
describe SexpExtensions::SendNode do
|
250
|
+
describe Reek::Source::SexpExtensions::SendNode do
|
253
251
|
context 'with no parameters' do
|
254
252
|
before :each do
|
255
253
|
@node = s(:send, nil, :hello)
|
@@ -281,7 +279,7 @@ describe SexpExtensions::SendNode do
|
|
281
279
|
end
|
282
280
|
end
|
283
281
|
|
284
|
-
describe SexpExtensions::BlockNode do
|
282
|
+
describe Reek::Source::SexpExtensions::BlockNode do
|
285
283
|
context 'with no parameters' do
|
286
284
|
before :each do
|
287
285
|
@node = s(:block, s(:send, nil, :map), s(:args), nil)
|
@@ -313,7 +311,7 @@ describe SexpExtensions::BlockNode do
|
|
313
311
|
end
|
314
312
|
end
|
315
313
|
|
316
|
-
describe SexpExtensions::ModuleNode do
|
314
|
+
describe Reek::Source::SexpExtensions::ModuleNode do
|
317
315
|
context 'with a simple name' do
|
318
316
|
subject do
|
319
317
|
mod = ast(:module, :Fred, nil)
|
@@ -1,17 +1,16 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/reek/source/sexp_formatter'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
describe SexpFormatter do
|
4
|
+
describe Reek::Source::SexpFormatter do
|
7
5
|
describe '::format' do
|
8
6
|
it 'formats a simple s-expression' do
|
9
|
-
result = SexpFormatter.format s(:lvar, :foo)
|
7
|
+
result = Reek::Source::SexpFormatter.format s(:lvar, :foo)
|
10
8
|
expect(result).to eq('foo')
|
11
9
|
end
|
12
10
|
|
13
11
|
it 'formats a more complex s-expression' do
|
14
|
-
|
12
|
+
ast = s(:send, nil, :foo, s(:lvar, :bar))
|
13
|
+
result = Reek::Source::SexpFormatter.format(ast)
|
15
14
|
expect(result).to eq('foo(bar)')
|
16
15
|
end
|
17
16
|
|
@@ -22,7 +21,7 @@ describe SexpFormatter do
|
|
22
21
|
s(:begin,
|
23
22
|
s(:send, nil, :baz),
|
24
23
|
s(:send, nil, :qux)))
|
25
|
-
result = SexpFormatter.format ast
|
24
|
+
result = Reek::Source::SexpFormatter.format ast
|
26
25
|
|
27
26
|
expect(result).to eq 'if foo ... end'
|
28
27
|
end
|
@@ -1,9 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/reek/source/sexp_node'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
describe SexpNode do
|
4
|
+
describe Reek::Source::SexpNode do
|
7
5
|
context 'format' do
|
8
6
|
it 'formats self' do
|
9
7
|
@node = s(:self)
|
@@ -1,25 +1,25 @@
|
|
1
|
-
|
1
|
+
require_relative '../../spec_helper'
|
2
2
|
require 'stringio'
|
3
|
-
|
3
|
+
require_relative '../../../lib/reek/source/source_code'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
describe SourceCode do
|
5
|
+
describe Reek::Source::SourceCode do
|
8
6
|
describe '#syntax_tree' do
|
9
7
|
it 'associates comments with the AST' do
|
10
|
-
|
8
|
+
source = "# this is\n# a comment\ndef foo; end"
|
9
|
+
source_code = Reek::Source::SourceCode.new(source, '(string)')
|
11
10
|
result = source_code.syntax_tree
|
12
11
|
expect(result.comments).to eq "# this is\n# a comment"
|
13
12
|
end
|
14
13
|
|
15
14
|
it 'cleanly processes empty source' do
|
16
|
-
source_code = SourceCode.new('', '(string)')
|
15
|
+
source_code = Reek::Source::SourceCode.new('', '(string)')
|
17
16
|
result = source_code.syntax_tree
|
18
17
|
expect(result).to be_nil
|
19
18
|
end
|
20
19
|
|
21
20
|
it 'cleanly processes empty source with comments' do
|
22
|
-
|
21
|
+
source = "# this is\n# a comment\n"
|
22
|
+
source_code = Reek::Source::SourceCode.new(source, '(string)')
|
23
23
|
result = source_code.syntax_tree
|
24
24
|
expect(result).to be_nil
|
25
25
|
end
|
@@ -29,7 +29,7 @@ describe SourceCode do
|
|
29
29
|
let(:source_name) { 'Test source' }
|
30
30
|
let(:error_message) { 'Error message' }
|
31
31
|
let(:parser) { double('parser') }
|
32
|
-
let(:src) { SourceCode.new('', source_name, parser) }
|
32
|
+
let(:src) { Reek::Source::SourceCode.new('', source_name, parser) }
|
33
33
|
|
34
34
|
before :each do
|
35
35
|
@catcher = StringIO.new
|