Sha256: 928c2027f0bcaa86cb4dc4d3f3d2a7e8e22bb76da6d1c0ab166607330b2a69a5
Contents?: true
Size: 1.01 KB
Versions: 11
Compression:
Stored size: 1.01 KB
Contents
# encoding: utf-8 module RuboCop module Cop module Rails # This cop checks for the use of the read_attribute or # write_attribute methods. # # @example # # # bad # x = read_attributed(:attr) # write_attribute(:attr, val) # # # good # x = self[:attr] # self[:attr] = val class ReadWriteAttribute < Cop MSG = 'Prefer `%s` over `%s`.' def on_send(node) receiver, method_name, *_args = *node return if receiver return unless [:read_attribute, :write_attribute].include?(method_name) add_offense(node, :selector) end def message(node) _receiver, method_name, *_args = *node if method_name == :read_attribute format(MSG, 'self[:attr]', 'read_attribute(:attr)') else format(MSG, 'self[:attr] = val', 'write_attribute(:attr, var)') end end end end end end
Version data entries
11 entries across 11 versions & 2 rubygems