Sha256: a20479da5a9119bf09e1c0bf7514b5dfbbe7d1af2d59d909be425749ae96a327

Contents?: true

Size: 1.08 KB

Versions: 52

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Rails
      # Checks for consistent uses of `to_fs` or `to_formatted_s`,
      # depending on the cop's configuration.
      #
      # @example EnforcedStyle: to_fs (default)
      #
      #   # bad
      #   time.to_formatted_s(:db)
      #
      #   # good
      #   time.to_fs(:db)
      #
      # @example EnforcedStyle: to_formatted_s
      #
      #   # bad
      #   time.to_fs(:db)
      #
      #   # good
      #   time.to_formatted_s(:db)
      #
      class ToFormattedS < Base
        include ConfigurableEnforcedStyle
        extend AutoCorrector
        extend TargetRailsVersion

        minimum_target_rails_version 7.0

        MSG = 'Use `%<prefer>s` instead.'
        RESTRICT_ON_SEND = %i[to_formatted_s to_fs].freeze

        def on_send(node)
          return if node.method?(style)

          add_offense(node.loc.selector, message: format(MSG, prefer: style)) do |corrector|
            corrector.replace(node.loc.selector, style)
          end
        end
        alias on_csend on_send
      end
    end
  end
end

Version data entries

52 entries across 49 versions & 8 rubygems

Version Path
rubocop-rails-2.30.3 lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.30.2 lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.30.1 lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.30.0 lib/rubocop/cop/rails/to_formatted_s.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rubocop-rails-2.29.1/lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.29.1 lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.29.0 lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.28.0 lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.27.0 lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.26.2 lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.26.1 lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.26.0 lib/rubocop/cop/rails/to_formatted_s.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.25.1/lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.25.1 lib/rubocop/cop/rails/to_formatted_s.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-rails-2.15.2/lib/rubocop/cop/rails/to_formatted_s.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-rails-2.15.2/lib/rubocop/cop/rails/to_formatted_s.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-rails-2.15.2/lib/rubocop/cop/rails/to_formatted_s.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rails-2.25.0/lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.24.1 lib/rubocop/cop/rails/to_formatted_s.rb
rubocop-rails-2.24.0 lib/rubocop/cop/rails/to_formatted_s.rb