reek 3.4.0 → 3.4.1
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 +9 -0
- data/features/step_definitions/reek_steps.rb +19 -16
- data/lib/reek/ast/sexp_extensions.rb +17 -8
- data/lib/reek/cli/application.rb +21 -12
- data/lib/reek/cli/option_interpreter.rb +1 -6
- data/lib/reek/cli/options.rb +32 -22
- data/lib/reek/report/location_formatter.rb +11 -5
- data/lib/reek/smells/smell_warning.rb +10 -2
- data/lib/reek/smells/uncommunicative_method_name.rb +25 -21
- data/lib/reek/smells/uncommunicative_parameter_name.rb +14 -15
- data/lib/reek/spec/should_reek_of.rb +44 -9
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +2 -2
- data/spec/reek/ast/node_spec.rb +1 -1
- data/spec/reek/ast/object_refs_spec.rb +1 -1
- data/spec/reek/ast/reference_collector_spec.rb +1 -1
- data/spec/reek/ast/sexp_extensions_spec.rb +49 -2
- data/spec/reek/ast/sexp_formatter_spec.rb +1 -1
- data/spec/reek/cli/option_interpreter_spec.rb +7 -7
- data/spec/reek/cli/options_spec.rb +27 -19
- data/spec/reek/cli/warning_collector_spec.rb +2 -2
- data/spec/reek/code_comment_spec.rb +1 -1
- data/spec/reek/configuration/app_configuration_spec.rb +4 -4
- data/spec/reek/configuration/default_directive_spec.rb +1 -1
- data/spec/reek/configuration/directory_directives_spec.rb +1 -1
- data/spec/reek/configuration/excluded_paths_spec.rb +1 -1
- data/spec/reek/context/code_context_spec.rb +2 -2
- data/spec/reek/context/method_context_spec.rb +1 -1
- data/spec/reek/context/module_context_spec.rb +2 -2
- data/spec/reek/context/root_context_spec.rb +1 -1
- data/spec/reek/context/singleton_method_context_spec.rb +1 -1
- data/spec/reek/examiner_spec.rb +1 -1
- data/spec/reek/report/html_report_spec.rb +2 -2
- data/spec/reek/report/json_report_spec.rb +3 -3
- data/spec/reek/report/location_formatter_spec.rb +30 -0
- data/spec/reek/report/text_report_spec.rb +4 -4
- data/spec/reek/report/xml_report_spec.rb +2 -2
- data/spec/reek/report/yaml_report_spec.rb +3 -3
- data/spec/reek/smells/attribute_spec.rb +1 -1
- data/spec/reek/smells/boolean_parameter_spec.rb +1 -1
- data/spec/reek/smells/class_variable_spec.rb +2 -2
- data/spec/reek/smells/control_parameter_spec.rb +1 -1
- data/spec/reek/smells/data_clump_spec.rb +1 -1
- data/spec/reek/smells/duplicate_method_call_spec.rb +3 -3
- data/spec/reek/smells/feature_envy_spec.rb +2 -2
- data/spec/reek/smells/irresponsible_module_spec.rb +2 -2
- data/spec/reek/smells/long_parameter_list_spec.rb +2 -2
- data/spec/reek/smells/long_yield_list_spec.rb +2 -2
- data/spec/reek/smells/module_initialize_spec.rb +1 -1
- data/spec/reek/smells/nested_iterators_spec.rb +1 -1
- data/spec/reek/smells/nil_check_spec.rb +2 -2
- data/spec/reek/smells/prima_donna_method_spec.rb +1 -1
- data/spec/reek/smells/repeated_conditional_spec.rb +3 -3
- data/spec/reek/smells/smell_configuration_spec.rb +1 -1
- data/spec/reek/smells/smell_repository_spec.rb +2 -2
- data/spec/reek/smells/smell_warning_spec.rb +1 -1
- data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
- data/spec/reek/smells/too_many_methods_spec.rb +1 -1
- data/spec/reek/smells/too_many_statements_spec.rb +1 -1
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +2 -2
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +2 -2
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +2 -2
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +1 -1
- data/spec/reek/smells/unused_parameters_spec.rb +1 -1
- data/spec/reek/smells/utility_function_spec.rb +2 -2
- data/spec/reek/source/source_code_spec.rb +1 -1
- data/spec/reek/source/source_locator_spec.rb +2 -2
- data/spec/reek/spec/should_reek_of_spec.rb +90 -37
- data/spec/reek/spec/should_reek_only_of_spec.rb +1 -1
- data/spec/reek/spec/should_reek_spec.rb +1 -1
- data/spec/reek/tree_dresser_spec.rb +2 -2
- data/spec/reek/tree_walker_spec.rb +2 -2
- data/spec/spec_helper.rb +6 -0
- metadata +7 -6
data/spec/reek/examiner_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'tempfile'
|
2
2
|
require_relative '../../spec_helper'
|
3
|
-
|
4
|
-
|
3
|
+
require_lib 'reek/examiner'
|
4
|
+
require_lib 'reek/report/report'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Report::HTMLReport do
|
7
7
|
let(:instance) { Reek::Report::HTMLReport.new }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
require_lib 'reek/examiner'
|
3
|
+
require_lib 'reek/report/report'
|
4
|
+
require_lib 'reek/report/formatter'
|
5
5
|
|
6
6
|
require 'json'
|
7
7
|
require 'stringio'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_lib 'reek/report/formatter'
|
3
|
+
|
4
|
+
RSpec.describe 'location formatters' do
|
5
|
+
let(:warning) { build(:smell_warning, lines: [11, 9, 250, 100]) }
|
6
|
+
|
7
|
+
describe Reek::Report::BlankLocationFormatter do
|
8
|
+
describe '.format' do
|
9
|
+
it 'returns a blank String regardless of the warning' do
|
10
|
+
expect(described_class.format(warning)).to eq('')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Reek::Report::DefaultLocationFormatter do
|
16
|
+
describe '.format' do
|
17
|
+
it 'returns a prefix with sorted line numbers' do
|
18
|
+
expect(described_class.format(warning)).to eq('[9, 11, 100, 250]:')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Reek::Report::SingleLineLocationFormatter do
|
24
|
+
describe '.format' do
|
25
|
+
it 'returns the first line where the smell was found' do
|
26
|
+
expect(described_class.format(warning)).to eq('dummy_file:9: ')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
require_lib 'reek/examiner'
|
3
|
+
require_lib 'reek/report/report'
|
4
|
+
require_lib 'reek/report/formatter'
|
5
|
+
require_lib 'reek/report/heading_formatter'
|
6
6
|
require 'rainbow'
|
7
7
|
|
8
8
|
RSpec.describe Reek::Report::TextReport do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
2
|
+
require_lib 'reek/examiner'
|
3
|
+
require_lib 'reek/report/report'
|
4
4
|
|
5
5
|
RSpec.describe Reek::Report::XMLReport do
|
6
6
|
let(:xml_report) { Reek::Report::XMLReport.new }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
require_lib 'reek/examiner'
|
3
|
+
require_lib 'reek/report/report'
|
4
|
+
require_lib 'reek/report/formatter'
|
5
5
|
|
6
6
|
require 'yaml'
|
7
7
|
require 'stringio'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
2
|
+
require_lib 'reek/smells/class_variable'
|
3
|
+
require_lib 'reek/context/module_context'
|
4
4
|
require_relative 'smell_detector_shared'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Smells::ClassVariable do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
require_lib 'reek/smells/duplicate_method_call'
|
3
|
+
require_lib 'reek/context/code_context'
|
4
|
+
require_lib 'reek/tree_walker'
|
5
5
|
require_relative 'smell_detector_shared'
|
6
6
|
|
7
7
|
RSpec.describe Reek::Smells::DuplicateMethodCall do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
2
|
+
require_lib 'reek/smells/feature_envy'
|
3
|
+
require_lib 'reek/examiner'
|
4
4
|
require_relative 'smell_detector_shared'
|
5
5
|
|
6
6
|
# TODO: Bring specs in line with specs for other detectors
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
2
|
+
require_lib 'reek/context/code_context'
|
3
|
+
require_lib 'reek/smells/irresponsible_module'
|
4
4
|
require_relative 'smell_detector_shared'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Smells::IrresponsibleModule do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
2
|
+
require_lib 'reek/context/code_context'
|
3
|
+
require_lib 'reek/smells/long_parameter_list'
|
4
4
|
require_relative 'smell_detector_shared'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Smells::LongParameterList do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
2
|
+
require_lib 'reek/context/code_context'
|
3
|
+
require_lib 'reek/smells/long_yield_list'
|
4
4
|
require_relative 'smell_detector_shared'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Smells::LongYieldList do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
2
|
+
require_lib 'reek/context/code_context'
|
3
|
+
require_lib 'reek/smells/nil_check'
|
4
4
|
require_relative 'smell_detector_shared'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Smells::NilCheck do
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
2
|
+
require_lib 'reek/smells/repeated_conditional'
|
3
|
+
require_lib 'reek/context/code_context'
|
4
4
|
require_relative 'smell_detector_shared'
|
5
|
-
|
5
|
+
require_lib 'reek/source/source_code'
|
6
6
|
|
7
7
|
RSpec.describe Reek::Smells::RepeatedConditional do
|
8
8
|
let(:detector) { build(:smell_detector, smell_type: :RepeatedConditional, source: source_name) }
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
2
|
+
require_lib 'reek/smells/smell_detector'
|
3
|
+
require_lib 'reek/smells/smell_repository'
|
4
4
|
|
5
5
|
RSpec.describe Reek::Smells::SmellRepository do
|
6
6
|
describe '.smell_types' do
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
2
|
+
require_lib 'reek/smells/smell_warning'
|
3
3
|
|
4
4
|
RSpec.describe Reek::Smells::SmellWarning do
|
5
5
|
let(:duplication_detector) { build(:smell_detector, smell_type: 'DuplicateMethodCall') }
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
2
|
+
require_lib 'reek/smells/too_many_instance_variables'
|
3
3
|
require_relative 'smell_detector_shared'
|
4
4
|
|
5
5
|
RSpec.describe Reek::Smells::TooManyInstanceVariables do
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
2
|
+
require_lib 'reek/smells/uncommunicative_method_name'
|
3
3
|
require_relative 'smell_detector_shared'
|
4
4
|
|
5
5
|
RSpec.describe Reek::Smells::UncommunicativeMethodName do
|
@@ -12,7 +12,7 @@ RSpec.describe Reek::Smells::UncommunicativeMethodName do
|
|
12
12
|
|
13
13
|
['help', '+', '-', '/', '*'].each do |method_name|
|
14
14
|
it "accepts the method name '#{method_name}'" do
|
15
|
-
src = "def #{method_name}(
|
15
|
+
src = "def #{method_name}(arg) basics(17) end"
|
16
16
|
expect(src).not_to reek_of(:UncommunicativeMethodName)
|
17
17
|
end
|
18
18
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
2
|
+
require_lib 'reek/smells/uncommunicative_module_name'
|
3
3
|
require_relative 'smell_detector_shared'
|
4
|
-
|
4
|
+
require_lib 'reek/context/code_context'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Smells::UncommunicativeModuleName do
|
7
7
|
let(:source_name) { 'string' }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
2
|
+
require_lib 'reek/smells/uncommunicative_parameter_name'
|
3
3
|
require_relative 'smell_detector_shared'
|
4
|
-
|
4
|
+
require_lib 'reek/context/method_context'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Smells::UncommunicativeParameterName do
|
7
7
|
let(:detector) do
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
2
|
+
require_lib 'reek/smells/uncommunicative_variable_name'
|
3
3
|
require_relative 'smell_detector_shared'
|
4
4
|
|
5
5
|
RSpec.describe Reek::Smells::UncommunicativeVariableName do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
|
2
|
+
require_lib 'reek/smells/utility_function'
|
3
|
+
require_lib 'reek/examiner'
|
4
4
|
require_relative 'smell_detector_shared'
|
5
5
|
|
6
6
|
# TODO: Bring specs in line with specs for other detectors
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require_relative '../../spec_helper'
|
3
|
-
|
4
|
-
|
3
|
+
require_lib 'reek/configuration/app_configuration'
|
4
|
+
require_lib 'reek/source/source_locator'
|
5
5
|
|
6
6
|
RSpec.describe Reek::Source::SourceLocator do
|
7
7
|
describe '#sources' do
|
@@ -1,63 +1,116 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require_relative '../../spec_helper'
|
3
|
-
|
3
|
+
require_lib 'reek/spec'
|
4
4
|
|
5
5
|
RSpec.describe Reek::Spec::ShouldReekOf do
|
6
|
-
|
7
|
-
let(:
|
6
|
+
describe 'smell type check' do
|
7
|
+
let(:src) { 'def double_thing() @other.thing.foo + @other.thing.foo end' }
|
8
8
|
|
9
|
-
it 'reports duplicate calls
|
10
|
-
expect(
|
9
|
+
it 'reports duplicate calls' do
|
10
|
+
expect(src).to reek_of(:Duplication)
|
11
11
|
end
|
12
12
|
|
13
|
-
it '
|
14
|
-
expect(
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'does not report any feature envy' do
|
18
|
-
expect(ruby).not_to reek_of(:FeatureEnvy)
|
13
|
+
it 'does not report any other smell types' do
|
14
|
+
expect(src).not_to reek_of(:FeatureEnvy)
|
19
15
|
end
|
20
16
|
end
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
describe 'different sources of input' do
|
19
|
+
context 'checking code in a string' do
|
20
|
+
let(:clean_code) { 'def good() true; end' }
|
21
|
+
let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'y') }
|
22
|
+
let(:smelly_code) { 'def x() y = 4; end' }
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
it 'matches a smelly String' do
|
25
|
+
expect(matcher.matches?(smelly_code)).to be_truthy
|
26
|
+
end
|
30
27
|
|
31
|
-
|
32
|
-
|
28
|
+
it 'doesnt match a fragrant String' do
|
29
|
+
expect(matcher.matches?(clean_code)).to be_falsey
|
30
|
+
end
|
33
31
|
end
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
context 'checking code in a File' do
|
34
|
+
let(:clean_file) { Pathname.glob("#{SAMPLES_PATH}/three_clean_files/*.rb").first }
|
35
|
+
let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: '@s') }
|
36
|
+
let(:smelly_file) { Pathname.glob("#{SAMPLES_PATH}/two_smelly_files/*.rb").first }
|
37
|
+
|
38
|
+
it 'matches a smelly file' do
|
39
|
+
expect(matcher.matches?(smelly_file)).to be_truthy
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'doesnt match a fragrant file' do
|
43
|
+
expect(matcher.matches?(clean_file)).to be_falsey
|
44
|
+
end
|
38
45
|
end
|
39
46
|
end
|
40
47
|
|
41
|
-
|
42
|
-
|
43
|
-
|
48
|
+
describe 'smell types and smell details' do
|
49
|
+
context 'passing in smell_details with unknown parameter name' do
|
50
|
+
let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, foo: 'y') }
|
51
|
+
let(:smelly_code) { 'def x() y = 4; end' }
|
44
52
|
|
45
|
-
|
46
|
-
|
53
|
+
it 'raises ArgumentError' do
|
54
|
+
expect { matcher.matches?(smelly_code) }.to raise_error(ArgumentError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'both are matching' do
|
59
|
+
let(:smelly_code) { 'def x() y = 4; end' }
|
60
|
+
let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'y') }
|
61
|
+
|
62
|
+
it 'is truthy' do
|
63
|
+
expect(matcher.matches?(smelly_code)).to be_truthy
|
64
|
+
end
|
47
65
|
end
|
48
|
-
end
|
49
66
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
67
|
+
context 'no smell_type is matching' do
|
68
|
+
let(:smelly_code) { 'def dummy() y = 4; end' }
|
69
|
+
let(:falsey_matcher) { Reek::Spec::ShouldReekOf.new(:FeatureEnvy, name: 'y') }
|
70
|
+
let(:truthy_matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'y') }
|
54
71
|
|
55
|
-
|
56
|
-
|
72
|
+
it 'is falsey' do
|
73
|
+
expect(falsey_matcher.matches?(smelly_code)).to be_falsey
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'sets the proper error message' do
|
77
|
+
falsey_matcher.matches?(smelly_code)
|
78
|
+
|
79
|
+
expect(falsey_matcher.failure_message).to\
|
80
|
+
match('Expected string to reek of FeatureEnvy, but it didn\'t')
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'sets the proper error message when negated' do
|
84
|
+
truthy_matcher.matches?(smelly_code)
|
85
|
+
|
86
|
+
expect(truthy_matcher.failure_message_when_negated).to\
|
87
|
+
match('Expected string not to reek of UncommunicativeVariableName, but it did')
|
88
|
+
end
|
57
89
|
end
|
58
90
|
|
59
|
-
|
60
|
-
|
91
|
+
context 'smell type is matching but smell details are not' do
|
92
|
+
let(:smelly_code) { 'def dummy() y = 4; end' }
|
93
|
+
let(:matcher) { Reek::Spec::ShouldReekOf.new(:UncommunicativeVariableName, name: 'x') }
|
94
|
+
|
95
|
+
it 'is falsey' do
|
96
|
+
expect(matcher.matches?(smelly_code)).to be_falsey
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'sets the proper error message' do
|
100
|
+
matcher.matches?(smelly_code)
|
101
|
+
|
102
|
+
expect(matcher.failure_message).to\
|
103
|
+
match('Expected string to reek of UncommunicativeVariableName (which it did) with '\
|
104
|
+
'smell details {:name=>"x"}, which it didn\'t')
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'sets the proper error message when negated' do
|
108
|
+
matcher.matches?(smelly_code)
|
109
|
+
|
110
|
+
expect(matcher.failure_message_when_negated).to\
|
111
|
+
match('Expected string not to reek of UncommunicativeVariableName with smell '\
|
112
|
+
'details {:name=>"x"}, but it did')
|
113
|
+
end
|
61
114
|
end
|
62
115
|
end
|
63
116
|
end
|