Sha256: fac741f41b9d9edf79590b9d42e685ba8e994878e137b4b8e2f795342c76ab41

Contents?: true

Size: 1.39 KB

Versions: 13

Compression:

Stored size: 1.39 KB

Contents

require_relative 'smell_configuration'
require_relative 'smell_detector'
require_relative 'smell_warning'

module Reek
  module Smells
    #
    # A class that publishes a getter or setter for an instance variable
    # invites client classes to become too intimate with its inner workings,
    # and in particular with its representation of state.
    #
    # This detector raises a warning for every public +attr_writer+,
    # +attr_accessor+, and +attr+ with the writable flag set to +true+.
    #
    # See {file:docs/Attribute.md} for details.
    #
    # TODO: Catch attributes declared "by hand"
    class Attribute < SmellDetector
      def initialize(*args)
        super
      end

      def self.contexts # :nodoc:
        [:sym]
      end

      #
      # Checks whether the given class declares any attributes.
      #
      # @return [Array<SmellWarning>]
      #
      def inspect(ctx)
        attributes_in(ctx).map do |attribute, line|
          smell_warning(
            context: ctx,
            lines: [line],
            message: 'is a writable attribute',
            parameters: { name: attribute.to_s })
        end
      end

      private

      # :reek:UtilityFunction
      def attributes_in(module_ctx)
        if module_ctx.visibility == :public
          call_node = module_ctx.exp
          [[call_node.name, call_node.line]]
        else
          []
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
reek-3.11 lib/reek/smells/attribute.rb
reek-3.10.2 lib/reek/smells/attribute.rb
reek-3.10.1 lib/reek/smells/attribute.rb
reek-3.10.0 lib/reek/smells/attribute.rb
reek-3.9.1 lib/reek/smells/attribute.rb
reek-3.9.0 lib/reek/smells/attribute.rb
reek-3.8.3 lib/reek/smells/attribute.rb
reek-3.8.2 lib/reek/smells/attribute.rb
reek-3.8.1 lib/reek/smells/attribute.rb
reek-3.8.0 lib/reek/smells/attribute.rb
reek-3.7.1 lib/reek/smells/attribute.rb
reek-3.7.0 lib/reek/smells/attribute.rb
reek-3.6.1 lib/reek/smells/attribute.rb