Sha256: 0439cfefcad9d823ed0a69892c57d9765447874ce35eb9b0892cef205a42098a

Contents?: true

Size: 1014 Bytes

Versions: 11

Compression:

Stored size: 1014 Bytes

Contents

require_relative 'code_context'

module Reek
  module Context
    #
    # A context wrapper for any method definition found in a syntax tree.
    #
    class MethodContext < CodeContext
      attr_reader :refs

      def references_self?
        exp.depends_on_instance?
      end

      def uses_param?(param)
        local_nodes(:lvar).find { |node| node.var_name == param.to_sym }
      end

      # :reek:FeatureEnvy
      def unused_params
        exp.arguments.select do |param|
          next if param.anonymous_splat?
          next if param.marked_unused?
          !uses_param? param.plain_name
        end
      end

      def uses_super_with_implicit_arguments?
        (body = exp.body) && body.contains_nested_node?(:zsuper)
      end

      def default_assignments
        @default_assignments ||=
          exp.parameters.select(&:optional_argument?).map(&:children)
      end

      def singleton_method?
        exp.singleton_method? || visibility == :module_function
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
reek-3.8.3 lib/reek/context/method_context.rb
reek-3.8.2 lib/reek/context/method_context.rb
reek-3.8.1 lib/reek/context/method_context.rb
reek-3.8.0 lib/reek/context/method_context.rb
reek-3.7.1 lib/reek/context/method_context.rb
reek-3.7.0 lib/reek/context/method_context.rb
reek-3.6.1 lib/reek/context/method_context.rb
reek-3.6.0 lib/reek/context/method_context.rb
reek-3.5.0 lib/reek/context/method_context.rb
reek-3.4.1 lib/reek/context/method_context.rb
reek-3.4.0 lib/reek/context/method_context.rb