Sha256: 538e08033e429c30299baf126d1e390504c2f2894ee0a997e0aa34636ec6bf0f

Contents?: true

Size: 1.41 KB

Versions: 6778

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # Checks for unnecessary `require` statement.
      #
      # The following features are unnecessary `require` statement because
      # they are already loaded.
      #
      # ruby -ve 'p $LOADED_FEATURES.reject { |feature| %r|/| =~ feature }'
      # ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-darwin13]
      # ["enumerator.so", "rational.so", "complex.so", "thread.rb"]
      #
      # This cop targets Ruby 2.2 or higher containing these 4 features.
      #
      # @example
      #   # bad
      #   require 'unloaded_feature'
      #   require 'thread'
      #
      #   # good
      #   require 'unloaded_feature'
      class UnneededRequireStatement < Cop
        include RangeHelp

        MSG = 'Remove unnecessary `require` statement.'.freeze

        def_node_matcher :unnecessary_require_statement?, <<-PATTERN
          (send nil? :require
            (str {"enumerator" "rational" "complex" "thread"}))
        PATTERN

        def on_send(node)
          return unless unnecessary_require_statement?(node)

          add_offense(node)
        end

        def autocorrect(node)
          lambda do |corrector|
            range = range_with_surrounding_space(range: node.loc.expression,
                                                 side: :right)
            corrector.remove(range)
          end
        end
      end
    end
  end
end

Version data entries

6,778 entries across 6,772 versions & 24 rubygems

Version Path
primary_connect_proto-0.2.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
primary_connect_proto-0.1.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-client-0.0.1.alpha30 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-client-0.0.1.alpha29 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
primary_connect_proto-0.0.6 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-client-0.0.1.alpha28 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
primary_connect_proto-0.0.5 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-client-0.0.1.alpha27 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-client-0.0.1.alpha24 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
primary_connect_proto-0.0.4 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
primary_connect_proto-0.0.3 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-client-0.0.1.alpha23 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-kratos-client-0.8.0.alpha2 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-client-0.0.1.alpha21 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-keto-client-0.7.0.alpha1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-keto-client-0.7.0.alpha0 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-kratos-client-0.7.6.alpha7 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-kratos-client-0.7.6.alpha6 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-kratos-client-0.7.6.alpha5 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb
ory-kratos-client-0.7.6.alpha4 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/unneeded_require_statement.rb