Sha256: 15c7211631c59763d2c419fd7162fd2895c796f7dc4bb71831c3df9a49bb9f2f

Contents?: true

Size: 947 Bytes

Versions: 165

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

165 entries across 164 versions & 16 rubygems

Version Path
harbr-0.1.81 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.80 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.79 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.78 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.77 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.76 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.75 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.74 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.73 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.72 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.71 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.70 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.69 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.68 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.67 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.66 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.65 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.64 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.63 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb
harbr-0.1.62 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/internal_affairs/create_empty_file.rb