Sha256: 15c7211631c59763d2c419fd7162fd2895c796f7dc4bb71831c3df9a49bb9f2f

Contents?: true

Size: 947 Bytes

Versions: 164

Compression:

Stored size: 947 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module InternalAffairs
      # Checks for uses of `create_file` with empty string second argument.
      #
      # @example
      #
      #   # bad
      #   create_file(path, '')
      #
      #   # good
      #   create_empty_file(path)
      #
      class CreateEmptyFile < Base
        extend AutoCorrector

        MSG = 'Use `%<replacement>s`.'
        RESTRICT_ON_SEND = %i[create_file].freeze

        def on_send(node)
          return if node.receiver
          return unless (argument = node.arguments[1])
          return unless argument.str_type? && argument.value.empty?

          replacement = "create_empty_file(#{node.first_argument.source})"
          message = format(MSG, replacement: replacement)

          add_offense(node, message: message) do |corrector|
            corrector.replace(node, replacement)
          end
        end
      end
    end
  end
end

Version data entries

164 entries across 163 versions & 16 rubygems

Version Path
rubocop-1.68.0 lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.67.0 lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.66.1 lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.66.0 lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.65.1 lib/rubocop/cop/internal_affairs/create_empty_file.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.65.0 lib/rubocop/cop/internal_affairs/create_empty_file.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.64.1 lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.63.4 lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.63.3 lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.63.2 lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.63.1 lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.63.0 lib/rubocop/cop/internal_affairs/create_empty_file.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.62.1 lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.62.0 lib/rubocop/cop/internal_affairs/create_empty_file.rb
rubocop-1.61.0 lib/rubocop/cop/internal_affairs/create_empty_file.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb