Sha256: 60a9a9e2f6b46fc24afc1a36a422dccfd4eb00fb68beac9b0b1f99dbe5c16fa5
Contents?: true
Size: 1.15 KB
Versions: 22
Compression:
Stored size: 1.15 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Rails # Checks that ActiveRecord aliases are not used. The direct method names # are more clear and easier to read. # # @example # #bad # Book.update_attributes!(author: 'Alice') # # #good # Book.update!(author: 'Alice') class ActiveRecordAliases < Cop MSG = 'Use `%<prefer>s` instead of `%<current>s`.' ALIASES = { update_attributes: :update, update_attributes!: :update! }.freeze def on_send(node) ALIASES.each do |bad, good| next unless node.method?(bad) add_offense(node, message: format(MSG, prefer: good, current: bad), location: :selector, severity: :warning) break end end alias on_csend on_send def autocorrect(node) lambda do |corrector| corrector.replace( node.loc.selector, ALIASES[node.method_name].to_s ) end end end end end end
Version data entries
22 entries across 22 versions & 2 rubygems