reek 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +6 -0
- data/README.md +15 -9
- data/bin/reek +1 -1
- data/config/defaults.reek +71 -86
- data/features/command_line_interface/options.feature +0 -15
- data/features/reports/reports.feature +23 -0
- data/features/samples.feature +3 -12
- data/lib/reek.rb +3 -3
- data/lib/reek/cli/application.rb +1 -1
- data/lib/reek/cli/command_line.rb +10 -8
- data/lib/reek/cli/reek_command.rb +6 -7
- data/lib/reek/cli/report.rb +34 -38
- data/lib/reek/cli/version_command.rb +1 -1
- data/lib/reek/cli/yaml_command.rb +1 -1
- data/lib/reek/core/code_parser.rb +4 -4
- data/lib/reek/core/hash_extensions.rb +2 -2
- data/lib/reek/core/method_context.rb +2 -2
- data/lib/reek/core/module_context.rb +4 -4
- data/lib/reek/core/singleton_method_context.rb +1 -1
- data/lib/reek/core/smell_repository.rb +7 -6
- data/lib/reek/core/sniffer.rb +4 -4
- data/lib/reek/examiner.rb +10 -3
- data/lib/reek/smell_warning.rb +0 -2
- data/lib/reek/smells.rb +22 -21
- data/lib/reek/smells/attribute.rb +4 -8
- data/lib/reek/smells/boolean_parameter.rb +2 -2
- data/lib/reek/smells/class_variable.rb +3 -2
- data/lib/reek/smells/{control_couple.rb → control_parameter.rb} +5 -5
- data/lib/reek/smells/data_clump.rb +13 -29
- data/lib/reek/smells/{duplication.rb → duplicate_method_call.rb} +9 -11
- data/lib/reek/smells/feature_envy.rb +2 -2
- data/lib/reek/smells/irresponsible_module.rb +3 -2
- data/lib/reek/smells/long_parameter_list.rb +6 -10
- data/lib/reek/smells/long_yield_list.rb +4 -8
- data/lib/reek/smells/nested_iterators.rb +31 -25
- data/lib/reek/smells/nil_check.rb +11 -12
- data/lib/reek/smells/{simulated_polymorphism.rb → repeated_conditional.rb} +6 -10
- data/lib/reek/smells/smell_detector.rb +3 -6
- data/lib/reek/smells/too_many_instance_variables.rb +60 -0
- data/lib/reek/smells/too_many_methods.rb +62 -0
- data/lib/reek/smells/{long_method.rb → too_many_statements.rb} +7 -12
- data/lib/reek/smells/uncommunicative_method_name.rb +3 -7
- data/lib/reek/smells/uncommunicative_module_name.rb +3 -7
- data/lib/reek/smells/uncommunicative_parameter_name.rb +4 -8
- data/lib/reek/smells/uncommunicative_variable_name.rb +5 -9
- data/lib/reek/smells/unused_parameters.rb +62 -13
- data/lib/reek/smells/utility_function.rb +3 -7
- data/lib/reek/source.rb +8 -8
- data/lib/reek/source/core_extras.rb +1 -1
- data/lib/reek/source/source_code.rb +2 -2
- data/lib/reek/source/source_file.rb +2 -2
- data/lib/reek/source/source_locator.rb +1 -1
- data/lib/reek/source/source_repository.rb +4 -2
- data/lib/reek/spec.rb +9 -3
- data/lib/reek/spec/should_reek.rb +2 -2
- data/lib/reek/spec/should_reek_of.rb +1 -1
- data/lib/reek/spec/should_reek_only_of.rb +2 -2
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +3 -1
- data/spec/gem/updates_spec.rb +1 -1
- data/spec/gem/yard_spec.rb +1 -1
- data/spec/matchers/smell_of_matcher.rb +53 -19
- data/spec/reek/cli/help_command_spec.rb +2 -2
- data/spec/reek/cli/reek_command_spec.rb +6 -6
- data/spec/reek/cli/report_spec.rb +6 -6
- data/spec/reek/cli/version_command_spec.rb +2 -2
- data/spec/reek/cli/yaml_command_spec.rb +2 -2
- data/spec/reek/core/code_context_spec.rb +4 -4
- data/spec/reek/core/code_parser_spec.rb +2 -2
- data/spec/reek/core/config_spec.rb +4 -4
- data/spec/reek/core/method_context_spec.rb +3 -3
- data/spec/reek/core/module_context_spec.rb +3 -3
- data/spec/reek/core/object_refs_spec.rb +3 -3
- data/spec/reek/core/singleton_method_context_spec.rb +4 -4
- data/spec/reek/core/smell_configuration_spec.rb +2 -2
- data/spec/reek/core/stop_context_spec.rb +2 -2
- data/spec/reek/core/warning_collector_spec.rb +3 -3
- data/spec/reek/examiner_spec.rb +13 -4
- data/spec/reek/smell_warning_spec.rb +2 -2
- data/spec/reek/smells/attribute_spec.rb +4 -4
- data/spec/reek/smells/boolean_parameter_spec.rb +3 -3
- data/spec/reek/smells/class_variable_spec.rb +4 -4
- data/spec/reek/smells/{control_couple_spec.rb → control_parameter_spec.rb} +10 -10
- data/spec/reek/smells/data_clump_spec.rb +3 -3
- data/spec/reek/smells/{duplication_spec.rb → duplicate_method_call_spec.rb} +42 -26
- data/spec/reek/smells/feature_envy_spec.rb +3 -3
- data/spec/reek/smells/irresponsible_module_spec.rb +3 -3
- data/spec/reek/smells/long_parameter_list_spec.rb +3 -3
- data/spec/reek/smells/long_yield_list_spec.rb +3 -3
- data/spec/reek/smells/nested_iterators_spec.rb +42 -4
- data/spec/reek/smells/nil_check_spec.rb +23 -11
- data/spec/reek/smells/{simulated_polymorphism_spec.rb → repeated_conditional_spec.rb} +6 -6
- data/spec/reek/smells/smell_detector_shared.rb +2 -2
- data/spec/reek/smells/too_many_instance_variables_spec.rb +62 -0
- data/spec/reek/smells/{large_class_spec.rb → too_many_methods_spec.rb} +11 -56
- data/spec/reek/smells/{long_method_spec.rb → too_many_statements_spec.rb} +17 -17
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +5 -5
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +5 -5
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +4 -4
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +5 -5
- data/spec/reek/smells/unused_parameters_spec.rb +19 -4
- data/spec/reek/smells/utility_function_spec.rb +3 -3
- data/spec/reek/source/code_comment_spec.rb +2 -2
- data/spec/reek/source/object_source_spec.rb +1 -1
- data/spec/reek/source/reference_collector_spec.rb +2 -2
- data/spec/reek/source/sexp_formatter_spec.rb +2 -2
- data/spec/reek/source/source_code_spec.rb +2 -2
- data/spec/reek/source/tree_dresser_spec.rb +2 -2
- data/spec/reek/spec/should_reek_of_spec.rb +2 -2
- data/spec/reek/spec/should_reek_only_of_spec.rb +2 -2
- data/spec/reek/spec/should_reek_spec.rb +2 -2
- data/spec/samples/all_but_one_masked/masked.reek +1 -1
- data/spec/samples/clean_due_to_masking/masked.reek +1 -1
- data/spec/samples/config/allow_duplication.reek +2 -2
- data/spec/samples/inline_config/dirty.rb +2 -2
- data/spec/samples/mask_some/some.reek +1 -1
- data/spec/samples/masked_by_dotfile/dirty.rb +8 -0
- data/spec/samples/not_quite_masked/smelly.rb +3 -0
- data/spec/samples/overrides/masked/lower.reek +1 -1
- data/spec/samples/overrides/upper.reek +1 -1
- data/spec/spec_helper.rb +4 -9
- data/tasks/test.rake +0 -2
- metadata +253 -263
- data/lib/reek/smells/large_class.rb +0 -87
- data/lib/xp.reek +0 -66
- data/spec/gem/manifest_spec.rb +0 -22
- data/spec/spec.opts +0 -1
@@ -1,87 +0,0 @@
|
|
1
|
-
require File.join( File.dirname( File.expand_path(__FILE__)), 'smell_detector')
|
2
|
-
require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'smell_warning')
|
3
|
-
|
4
|
-
module Reek
|
5
|
-
module Smells
|
6
|
-
|
7
|
-
#
|
8
|
-
# A Large Class is a class or module that has a large number of
|
9
|
-
# instance variables, methods or lines of code.
|
10
|
-
#
|
11
|
-
# Currently +LargeClass+ only reports classes having more than a
|
12
|
-
# configurable number of methods or instance variables. The method count
|
13
|
-
# includes public, protected and
|
14
|
-
# private methods, and excludes methods inherited from superclasses or
|
15
|
-
# included modules.
|
16
|
-
#
|
17
|
-
class LargeClass < SmellDetector
|
18
|
-
|
19
|
-
SMELL_CLASS = self.name.split(/::/)[-1]
|
20
|
-
SUBCLASS_TOO_MANY_METHODS = 'TooManyMethods'
|
21
|
-
SUBCLASS_TOO_MANY_IVARS = 'TooManyInstanceVariables'
|
22
|
-
METHOD_COUNT_KEY = 'method_count'
|
23
|
-
IVAR_COUNT_KEY = 'ivar_count'
|
24
|
-
|
25
|
-
# The name of the config field that sets the maximum number of methods
|
26
|
-
# permitted in a class.
|
27
|
-
MAX_ALLOWED_METHODS_KEY = 'max_methods'
|
28
|
-
|
29
|
-
DEFAULT_MAX_METHODS = 25
|
30
|
-
|
31
|
-
# The name of the config field that sets the maximum number of instance
|
32
|
-
# variables permitted in a class.
|
33
|
-
MAX_ALLOWED_IVARS_KEY = 'max_instance_variables'
|
34
|
-
|
35
|
-
DEFAULT_MAX_IVARS = 9
|
36
|
-
|
37
|
-
def self.contexts # :nodoc:
|
38
|
-
[:class]
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.default_config
|
42
|
-
super.adopt(
|
43
|
-
MAX_ALLOWED_METHODS_KEY => DEFAULT_MAX_METHODS,
|
44
|
-
MAX_ALLOWED_IVARS_KEY => DEFAULT_MAX_IVARS,
|
45
|
-
EXCLUDE_KEY => []
|
46
|
-
)
|
47
|
-
end
|
48
|
-
|
49
|
-
def initialize(source, config = LargeClass.default_config)
|
50
|
-
super(source, config)
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# Checks +klass+ for too many methods or too many instance variables.
|
55
|
-
#
|
56
|
-
# @return [Array<SmellWarning>]
|
57
|
-
#
|
58
|
-
def examine_context(ctx)
|
59
|
-
@max_allowed_ivars = value(MAX_ALLOWED_IVARS_KEY, ctx, DEFAULT_MAX_IVARS)
|
60
|
-
@max_allowed_methods = value(MAX_ALLOWED_METHODS_KEY, ctx, DEFAULT_MAX_METHODS)
|
61
|
-
check_num_methods(ctx) + check_num_ivars(ctx)
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
def check_num_methods(ctx) # :nodoc:
|
67
|
-
actual = ctx.local_nodes(:defn).length
|
68
|
-
return [] if actual <= @max_allowed_methods
|
69
|
-
smell = SmellWarning.new(SMELL_CLASS, ctx.full_name, [ctx.exp.line],
|
70
|
-
"has at least #{actual} methods",
|
71
|
-
@source, SUBCLASS_TOO_MANY_METHODS,
|
72
|
-
{METHOD_COUNT_KEY => actual})
|
73
|
-
[smell]
|
74
|
-
end
|
75
|
-
|
76
|
-
def check_num_ivars(ctx) # :nodoc:
|
77
|
-
count = ctx.local_nodes(:iasgn).map {|iasgn| iasgn[1]}.uniq.length
|
78
|
-
return [] if count <= @max_allowed_ivars
|
79
|
-
smell = SmellWarning.new(SMELL_CLASS, ctx.full_name, [ctx.exp.line],
|
80
|
-
"has at least #{count} instance variables",
|
81
|
-
@source, SUBCLASS_TOO_MANY_IVARS,
|
82
|
-
{IVAR_COUNT_KEY => count})
|
83
|
-
[smell]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
data/lib/xp.reek
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
---
|
2
|
-
LargeClass:
|
3
|
-
max_methods: 25
|
4
|
-
exclude: []
|
5
|
-
enabled: true
|
6
|
-
max_instance_variables: 9
|
7
|
-
LongParameterList:
|
8
|
-
max_params: 3
|
9
|
-
exclude: []
|
10
|
-
enabled: true
|
11
|
-
overrides:
|
12
|
-
initialize:
|
13
|
-
max_params: 5
|
14
|
-
FeatureEnvy:
|
15
|
-
exclude:
|
16
|
-
- initialize
|
17
|
-
enabled: false
|
18
|
-
ClassVariable:
|
19
|
-
exclude: &id001 []
|
20
|
-
enabled: true
|
21
|
-
UncommunicativeVariableName:
|
22
|
-
accept:
|
23
|
-
- Inline::C
|
24
|
-
exclude: []
|
25
|
-
enabled: true
|
26
|
-
reject:
|
27
|
-
- !ruby/regexp /^.$/
|
28
|
-
- !ruby/regexp /[0-9]$/
|
29
|
-
NestedIterators:
|
30
|
-
exclude: *id001
|
31
|
-
enabled: false
|
32
|
-
LongMethod:
|
33
|
-
max_statements: 5
|
34
|
-
exclude:
|
35
|
-
- initialize
|
36
|
-
enabled: false
|
37
|
-
Duplication:
|
38
|
-
exclude: []
|
39
|
-
enabled: true
|
40
|
-
max_calls: 1
|
41
|
-
UtilityFunction:
|
42
|
-
max_helper_calls: 1
|
43
|
-
exclude: []
|
44
|
-
enabled: false
|
45
|
-
Attribute:
|
46
|
-
exclude: []
|
47
|
-
enabled: true
|
48
|
-
SimulatedPolymorphism:
|
49
|
-
exclude: []
|
50
|
-
enabled: true
|
51
|
-
max_ifs: 2
|
52
|
-
DataClump:
|
53
|
-
exclude: []
|
54
|
-
enabled: true
|
55
|
-
max_copies: 2
|
56
|
-
min_clump_size: 2
|
57
|
-
LongYieldList:
|
58
|
-
max_params: 2
|
59
|
-
exclude: []
|
60
|
-
enabled: true
|
61
|
-
overrides:
|
62
|
-
initialize:
|
63
|
-
max_params: 5
|
64
|
-
NilCheck:
|
65
|
-
exclude: []
|
66
|
-
enabled: true
|
data/spec/gem/manifest_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'spec_helper')
|
2
|
-
require 'find'
|
3
|
-
|
4
|
-
describe 'gem manifest' do
|
5
|
-
before :each do
|
6
|
-
@current_files = []
|
7
|
-
Find.find '.' do |path|
|
8
|
-
next unless File.file? path
|
9
|
-
next if path =~ /\.git|\.idea|build|doc|gem\/|tmp|nbproject|quality|xp.reek|Manifest.txt|develop.rake|deployment.rake/
|
10
|
-
@current_files << path[2..-1]
|
11
|
-
end
|
12
|
-
@current_files.sort!
|
13
|
-
@manifest = IO.readlines('Manifest.txt').map {|path| path.chomp}.sort
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'lists every current file' do
|
17
|
-
(@current_files - @manifest).should == []
|
18
|
-
end
|
19
|
-
it 'lists no extra files' do
|
20
|
-
(@manifest - @current_files).should == []
|
21
|
-
end
|
22
|
-
end
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|