Sha256: bb2a57fd0c1ba666fc471d38dbef5879894b7b24565f8353258eadc766feafff

Contents?: true

Size: 1.34 KB

Versions: 12

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Gemspec
      # This cop checks that `date =` is not used in gemspec file.
      # It is set automatically when the gem is packaged.
      #
      # @example
      #
      #   # bad
      #   Gem::Specification.new do |spec|
      #     s.name = 'your_cool_gem_name'
      #     spec.date = Time.now.strftime('%Y-%m-%d')
      #   end
      #
      #   # good
      #   Gem::Specification.new do |spec|
      #     s.name = 'your_cool_gem_name'
      #   end
      #
      class DateAssignment < Base
        include RangeHelp
        include GemspecHelp
        extend AutoCorrector

        MSG = 'Do not use `date =` in gemspec, it is set automatically when the gem is packaged.'

        def on_block(block_node)
          return unless gem_specification?(block_node)

          block_parameter = block_node.arguments.first.source

          date_assignment = block_node.descendants.detect do |node|
            node.send_type? && node.receiver&.source == block_parameter && node.method?(:date=)
          end

          return unless date_assignment

          add_offense(date_assignment) do |corrector|
            range = range_by_whole_lines(date_assignment.source_range, include_final_newline: true)

            corrector.remove(range)
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/gemspec/date_assignment.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/gemspec/date_assignment.rb
rubocop-1.27.0 lib/rubocop/cop/gemspec/date_assignment.rb
rubocop-1.26.1 lib/rubocop/cop/gemspec/date_assignment.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/gemspec/date_assignment.rb
rubocop-1.26.0 lib/rubocop/cop/gemspec/date_assignment.rb
rubocop-1.25.1 lib/rubocop/cop/gemspec/date_assignment.rb
rubocop-1.25.0 lib/rubocop/cop/gemspec/date_assignment.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/gemspec/date_assignment.rb
rubocop-1.24.1 lib/rubocop/cop/gemspec/date_assignment.rb
rubocop-1.24.0 lib/rubocop/cop/gemspec/date_assignment.rb
rubocop-1.23.0 lib/rubocop/cop/gemspec/date_assignment.rb