Sha256: 816f42464a047d602ca9908310b8c15253dfa2dd82c6b321eb74e278e7dc4b80

Contents?: true

Size: 598 Bytes

Versions: 1

Compression:

Stored size: 598 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class TrivialAccessors < Cop
      MSG = 'Use attr_%s to define trivial %s methods.'

      def on_def(node)
        _, args, body = *node

        kind = if body.type == :ivar
                 'reader'
               elsif args.children.size == 1 && body.type == :ivasgn &&
                   body.children[1].type == :lvar
                 'writer'
               end
        if kind
          add_offence(:convention, node.loc.keyword.line,
                      sprintf(MSG, kind, kind))
        end

        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.8.0 lib/rubocop/cop/trivial_accessors.rb