<commit_before># frozen_string_literal: true

module RuboCop
  module Cop
    module Rails
      # This cop checks for the use of the read_attribute or
      # write_attribute methods.
      #
      # @example
      #
      #   # bad
      #   x = read_attribute(:attr)
      #   write_attribute(:attr, val)
      #
      #   # good
      #   x = self[:attr]
      #   self[:attr] = val
      class ReadWriteAttribute < Cop
        MSG = 'Prefer `%s` over `%s`.'.freeze

        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)<commit_msg>Modify Rails/ReadWriteAttribute to use NodePattern<commit_after># frozen_string_literal: true

module RuboCop
  module Cop
    module Rails
      # This cop checks for the use of the read_attribute or
      # write_attribute methods.
      #
      # @example
      #
      #   # bad
      #   x = read_attribute(:attr)
      #   write_attribute(:attr, val)
      #
      #   # good
      #   x = self[:attr]
      #   self[:attr] = val
      class ReadWriteAttribute < Cop
        MSG = 'Prefer `%s` over `%s`.'.freeze

        def_node_matcher :read_write_attribute?, <<-PATTERN
          {
            (send nil :read_attribute _)
            (send nil :write_attribute _ _)
          }
        PATTERN

        def on_send(node)
          read_write_attribute?(node) do
            add_offense(node, :selector)
          end
{'fraction_non_alphanumeric': 0.09108402822322001, 'fraction_numerical': 0.0, 'mean_word_length': 1.8108108108108107, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6951260', 'n_tokens_mistral': 475, 'n_tokens_neox': 463, 'n_words': 115}