diff --git a/features/samples.feature b/features/samples.feature index d7117943a..b996f43cc 100644 --- a/features/samples.feature +++ b/features/samples.feature @@ -46,7 +46,7 @@ Feature: Basic smell detection RepeatedConditional: Inline::C tests '@@type_map.has_key? type' at least 3 times TooManyConstants: Inline has 6 constants TooManyInstanceVariables: Inline::C has at least 13 instance variables - TooManyMethods: Inline::C has at least 25 methods + TooManyMethods: Inline::C has at least 30 methods TooManyStatements: File#self.write_with_backup has approx 6 statements TooManyStatements: Inline#self.rootdir has approx 8 statements TooManyStatements: Inline::C#build has approx 63 statements @@ -144,7 +144,7 @@ Feature: Basic smell detection TooManyConstants: OptionParser has 16 constants TooManyInstanceVariables: OptionParser has at least 6 instance variables TooManyInstanceVariables: OptionParser::Switch has at least 7 instance variables - TooManyMethods: OptionParser has at least 42 methods + TooManyMethods: OptionParser has at least 49 methods TooManyStatements: OptionParser#complete has approx 6 statements TooManyStatements: OptionParser#getopts has approx 18 statements TooManyStatements: OptionParser#load has approx 6 statements @@ -247,7 +247,7 @@ Feature: Basic smell detection RepeatedConditional: RedCloth tests 'title' at least 4 times SubclassedFromCoreClass: RedCloth inherits from core class 'String' TooManyConstants: RedCloth has 45 constants - TooManyMethods: RedCloth has at least 44 methods + TooManyMethods: RedCloth has at least 50 methods TooManyStatements: RedCloth#block_markdown_bq has approx 6 statements TooManyStatements: RedCloth#block_textile_lists has approx 21 statements TooManyStatements: RedCloth#block_textile_table has approx 19 statements diff --git a/lib/reek/ast/sexp_extensions/symbols.rb b/lib/reek/ast/sexp_extensions/symbols.rb index 0899bf048..786e57c3e 100644 --- a/lib/reek/ast/sexp_extensions/symbols.rb +++ b/lib/reek/ast/sexp_extensions/symbols.rb @@ -9,9 +9,17 @@ def name children.first end + def ends_with_bang? + name[-1] == '!' + end + def full_name(outer) "#{outer}##{name}" end + + def arg_names + [] + end end end end diff --git a/lib/reek/cli/options.rb b/lib/reek/cli/options.rb index 3da67c2a5..eff5561cc 100644 --- a/lib/reek/cli/options.rb +++ b/lib/reek/cli/options.rb @@ -15,7 +15,7 @@ module CLI # See {file:docs/Command-Line-Options.md} for details. # # @quality :reek:TooManyInstanceVariables { max_instance_variables: 13 } - # @quality :reek:TooManyMethods { max_methods: 18 } + # @quality :reek:TooManyMethods { max_methods: 32 } # @quality :reek:Attribute { enabled: false } # class Options diff --git a/lib/reek/context/module_context.rb b/lib/reek/context/module_context.rb index 28dc057f5..ab2867003 100644 --- a/lib/reek/context/module_context.rb +++ b/lib/reek/context/module_context.rb @@ -55,13 +55,6 @@ def instance_method_calls end end - # - # @deprecated use `defined_instance_methods` instead - # - def node_instance_methods - local_nodes(:def).to_a - end - def descriptively_commented? CodeComment.new(comment: exp.leading_comment).descriptive? end diff --git a/lib/reek/context_builder.rb b/lib/reek/context_builder.rb index d2e1cdff9..c2da2b6d2 100644 --- a/lib/reek/context_builder.rb +++ b/lib/reek/context_builder.rb @@ -20,7 +20,7 @@ module Reek # counting. Ideally `ContextBuilder` would only build up the context tree and leave the # statement and reference counting to the contexts. # - # @quality :reek:TooManyMethods { max_methods: 31 } + # @quality :reek:TooManyMethods { max_methods: 32 } # @quality :reek:UnusedPrivateMethod { exclude: [ !ruby/regexp /process_/ ] } # @quality :reek:DataClump class ContextBuilder diff --git a/lib/reek/smell_detectors/data_clump.rb b/lib/reek/smell_detectors/data_clump.rb index f9bec48b2..2c741b3fe 100644 --- a/lib/reek/smell_detectors/data_clump.rb +++ b/lib/reek/smell_detectors/data_clump.rb @@ -80,7 +80,7 @@ def min_clump_size end def candidate_methods - @candidate_methods ||= context.node_instance_methods + @candidate_methods ||= context.defined_instance_methods.map(&:exp) end def candidate_clumps diff --git a/lib/reek/smell_detectors/instance_variable_assumption.rb b/lib/reek/smell_detectors/instance_variable_assumption.rb index 52ac46d36..ee64b2b95 100644 --- a/lib/reek/smell_detectors/instance_variable_assumption.rb +++ b/lib/reek/smell_detectors/instance_variable_assumption.rb @@ -30,7 +30,7 @@ def sniff private def method_expressions - @method_expressions ||= context.node_instance_methods + @method_expressions ||= context.defined_instance_methods.map(&:exp) end def build_smell_warning(assumption) diff --git a/lib/reek/smell_detectors/missing_safe_method.rb b/lib/reek/smell_detectors/missing_safe_method.rb index 67128a969..e1b4157d7 100644 --- a/lib/reek/smell_detectors/missing_safe_method.rb +++ b/lib/reek/smell_detectors/missing_safe_method.rb @@ -47,7 +47,7 @@ def self.contexts # :nodoc: # s(:args), nil)) # def sniff - context.node_instance_methods.select do |method_sexp| + context.defined_instance_methods.map(&:exp).select do |method_sexp| missing_safe_method?(method_sexp) end.map do |method_sexp| name = method_sexp.name @@ -69,7 +69,7 @@ def missing_safe_method?(method_sexp) end def version_without_bang_exists?(method_sexp) - context.node_instance_methods.find do |sexp_item| + context.defined_instance_methods.find do |sexp_item| sexp_item.name.to_s == method_sexp.name_without_bang end end diff --git a/lib/reek/smell_detectors/too_many_methods.rb b/lib/reek/smell_detectors/too_many_methods.rb index 79f47699d..56b8e3745 100644 --- a/lib/reek/smell_detectors/too_many_methods.rb +++ b/lib/reek/smell_detectors/too_many_methods.rb @@ -37,7 +37,7 @@ def self.default_config # def sniff # TODO: Only checks instance methods! - actual = context.node_instance_methods.length + actual = context.defined_instance_methods.length return [] if actual <= max_allowed_methods [smell_warning(