reek 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +6 -0
  3. data/README.md +15 -9
  4. data/bin/reek +1 -1
  5. data/config/defaults.reek +71 -86
  6. data/features/command_line_interface/options.feature +0 -15
  7. data/features/reports/reports.feature +23 -0
  8. data/features/samples.feature +3 -12
  9. data/lib/reek.rb +3 -3
  10. data/lib/reek/cli/application.rb +1 -1
  11. data/lib/reek/cli/command_line.rb +10 -8
  12. data/lib/reek/cli/reek_command.rb +6 -7
  13. data/lib/reek/cli/report.rb +34 -38
  14. data/lib/reek/cli/version_command.rb +1 -1
  15. data/lib/reek/cli/yaml_command.rb +1 -1
  16. data/lib/reek/core/code_parser.rb +4 -4
  17. data/lib/reek/core/hash_extensions.rb +2 -2
  18. data/lib/reek/core/method_context.rb +2 -2
  19. data/lib/reek/core/module_context.rb +4 -4
  20. data/lib/reek/core/singleton_method_context.rb +1 -1
  21. data/lib/reek/core/smell_repository.rb +7 -6
  22. data/lib/reek/core/sniffer.rb +4 -4
  23. data/lib/reek/examiner.rb +10 -3
  24. data/lib/reek/smell_warning.rb +0 -2
  25. data/lib/reek/smells.rb +22 -21
  26. data/lib/reek/smells/attribute.rb +4 -8
  27. data/lib/reek/smells/boolean_parameter.rb +2 -2
  28. data/lib/reek/smells/class_variable.rb +3 -2
  29. data/lib/reek/smells/{control_couple.rb → control_parameter.rb} +5 -5
  30. data/lib/reek/smells/data_clump.rb +13 -29
  31. data/lib/reek/smells/{duplication.rb → duplicate_method_call.rb} +9 -11
  32. data/lib/reek/smells/feature_envy.rb +2 -2
  33. data/lib/reek/smells/irresponsible_module.rb +3 -2
  34. data/lib/reek/smells/long_parameter_list.rb +6 -10
  35. data/lib/reek/smells/long_yield_list.rb +4 -8
  36. data/lib/reek/smells/nested_iterators.rb +31 -25
  37. data/lib/reek/smells/nil_check.rb +11 -12
  38. data/lib/reek/smells/{simulated_polymorphism.rb → repeated_conditional.rb} +6 -10
  39. data/lib/reek/smells/smell_detector.rb +3 -6
  40. data/lib/reek/smells/too_many_instance_variables.rb +60 -0
  41. data/lib/reek/smells/too_many_methods.rb +62 -0
  42. data/lib/reek/smells/{long_method.rb → too_many_statements.rb} +7 -12
  43. data/lib/reek/smells/uncommunicative_method_name.rb +3 -7
  44. data/lib/reek/smells/uncommunicative_module_name.rb +3 -7
  45. data/lib/reek/smells/uncommunicative_parameter_name.rb +4 -8
  46. data/lib/reek/smells/uncommunicative_variable_name.rb +5 -9
  47. data/lib/reek/smells/unused_parameters.rb +62 -13
  48. data/lib/reek/smells/utility_function.rb +3 -7
  49. data/lib/reek/source.rb +8 -8
  50. data/lib/reek/source/core_extras.rb +1 -1
  51. data/lib/reek/source/source_code.rb +2 -2
  52. data/lib/reek/source/source_file.rb +2 -2
  53. data/lib/reek/source/source_locator.rb +1 -1
  54. data/lib/reek/source/source_repository.rb +4 -2
  55. data/lib/reek/spec.rb +9 -3
  56. data/lib/reek/spec/should_reek.rb +2 -2
  57. data/lib/reek/spec/should_reek_of.rb +1 -1
  58. data/lib/reek/spec/should_reek_only_of.rb +2 -2
  59. data/lib/reek/version.rb +1 -1
  60. data/reek.gemspec +3 -1
  61. data/spec/gem/updates_spec.rb +1 -1
  62. data/spec/gem/yard_spec.rb +1 -1
  63. data/spec/matchers/smell_of_matcher.rb +53 -19
  64. data/spec/reek/cli/help_command_spec.rb +2 -2
  65. data/spec/reek/cli/reek_command_spec.rb +6 -6
  66. data/spec/reek/cli/report_spec.rb +6 -6
  67. data/spec/reek/cli/version_command_spec.rb +2 -2
  68. data/spec/reek/cli/yaml_command_spec.rb +2 -2
  69. data/spec/reek/core/code_context_spec.rb +4 -4
  70. data/spec/reek/core/code_parser_spec.rb +2 -2
  71. data/spec/reek/core/config_spec.rb +4 -4
  72. data/spec/reek/core/method_context_spec.rb +3 -3
  73. data/spec/reek/core/module_context_spec.rb +3 -3
  74. data/spec/reek/core/object_refs_spec.rb +3 -3
  75. data/spec/reek/core/singleton_method_context_spec.rb +4 -4
  76. data/spec/reek/core/smell_configuration_spec.rb +2 -2
  77. data/spec/reek/core/stop_context_spec.rb +2 -2
  78. data/spec/reek/core/warning_collector_spec.rb +3 -3
  79. data/spec/reek/examiner_spec.rb +13 -4
  80. data/spec/reek/smell_warning_spec.rb +2 -2
  81. data/spec/reek/smells/attribute_spec.rb +4 -4
  82. data/spec/reek/smells/boolean_parameter_spec.rb +3 -3
  83. data/spec/reek/smells/class_variable_spec.rb +4 -4
  84. data/spec/reek/smells/{control_couple_spec.rb → control_parameter_spec.rb} +10 -10
  85. data/spec/reek/smells/data_clump_spec.rb +3 -3
  86. data/spec/reek/smells/{duplication_spec.rb → duplicate_method_call_spec.rb} +42 -26
  87. data/spec/reek/smells/feature_envy_spec.rb +3 -3
  88. data/spec/reek/smells/irresponsible_module_spec.rb +3 -3
  89. data/spec/reek/smells/long_parameter_list_spec.rb +3 -3
  90. data/spec/reek/smells/long_yield_list_spec.rb +3 -3
  91. data/spec/reek/smells/nested_iterators_spec.rb +42 -4
  92. data/spec/reek/smells/nil_check_spec.rb +23 -11
  93. data/spec/reek/smells/{simulated_polymorphism_spec.rb → repeated_conditional_spec.rb} +6 -6
  94. data/spec/reek/smells/smell_detector_shared.rb +2 -2
  95. data/spec/reek/smells/too_many_instance_variables_spec.rb +62 -0
  96. data/spec/reek/smells/{large_class_spec.rb → too_many_methods_spec.rb} +11 -56
  97. data/spec/reek/smells/{long_method_spec.rb → too_many_statements_spec.rb} +17 -17
  98. data/spec/reek/smells/uncommunicative_method_name_spec.rb +5 -5
  99. data/spec/reek/smells/uncommunicative_module_name_spec.rb +5 -5
  100. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +4 -4
  101. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +5 -5
  102. data/spec/reek/smells/unused_parameters_spec.rb +19 -4
  103. data/spec/reek/smells/utility_function_spec.rb +3 -3
  104. data/spec/reek/source/code_comment_spec.rb +2 -2
  105. data/spec/reek/source/object_source_spec.rb +1 -1
  106. data/spec/reek/source/reference_collector_spec.rb +2 -2
  107. data/spec/reek/source/sexp_formatter_spec.rb +2 -2
  108. data/spec/reek/source/source_code_spec.rb +2 -2
  109. data/spec/reek/source/tree_dresser_spec.rb +2 -2
  110. data/spec/reek/spec/should_reek_of_spec.rb +2 -2
  111. data/spec/reek/spec/should_reek_only_of_spec.rb +2 -2
  112. data/spec/reek/spec/should_reek_spec.rb +2 -2
  113. data/spec/samples/all_but_one_masked/masked.reek +1 -1
  114. data/spec/samples/clean_due_to_masking/masked.reek +1 -1
  115. data/spec/samples/config/allow_duplication.reek +2 -2
  116. data/spec/samples/inline_config/dirty.rb +2 -2
  117. data/spec/samples/mask_some/some.reek +1 -1
  118. data/spec/samples/masked_by_dotfile/dirty.rb +8 -0
  119. data/spec/samples/not_quite_masked/smelly.rb +3 -0
  120. data/spec/samples/overrides/masked/lower.reek +1 -1
  121. data/spec/samples/overrides/upper.reek +1 -1
  122. data/spec/spec_helper.rb +4 -9
  123. data/tasks/test.rake +0 -2
  124. metadata +253 -263
  125. data/lib/reek/smells/large_class.rb +0 -87
  126. data/lib/xp.reek +0 -66
  127. data/spec/gem/manifest_spec.rb +0 -22
  128. 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
@@ -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
@@ -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
@@ -1 +0,0 @@
1
- --color