Sha256: 6c4563d95ea2562e55f27ab30ba897d5d3846b04bfba0ee4c5055eccf48fbb4e

Contents?: true

Size: 628 Bytes

Versions: 211

Compression:

Stored size: 628 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # This class ensures a require statement is present for a standard library
    # determined by the variable library_name
    class RequireLibraryCorrector
      extend RangeHelp

      class << self
        def correct(corrector, node, library_name)
          node = node.parent while node.parent?
          node = node.children.first if node.begin_type?
          corrector.insert_before(node, require_statement(library_name))
        end

        def require_statement(library_name)
          "require '#{library_name}'\n"
        end
      end
    end
  end
end

Version data entries

211 entries across 202 versions & 19 rubygems

Version Path
rubocop-1.68.0 lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.67.0 lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.66.1 lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.66.0 lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.65.1 lib/rubocop/cop/correctors/require_library_corrector.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.65.0 lib/rubocop/cop/correctors/require_library_corrector.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/correctors/require_library_corrector.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/correctors/require_library_corrector.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/correctors/require_library_corrector.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.64.1 lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.63.4 lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.63.3 lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.63.2 lib/rubocop/cop/correctors/require_library_corrector.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.63.1 lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.63.0 lib/rubocop/cop/correctors/require_library_corrector.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/cop/correctors/require_library_corrector.rb
rubocop-1.62.1 lib/rubocop/cop/correctors/require_library_corrector.rb