Sha256: 07a84dd407f3240fed201048fd544ec277dccb63d0a2a0ffd73719761c152e07

Contents?: true

Size: 1.17 KB

Versions: 14

Compression:

Stored size: 1.17 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for methods invoked via the :: operator instead
      # of the . operator (like FileUtils::rmdir instead of FileUtils.rmdir).
      class ColonMethodCall < Cop
        MSG = 'Do not use `::` for method calls.'.freeze

        JAVA_TYPES = [:byte, :boolean, :byte, :short, :char,
                      :int, :long, :float, :double].freeze

        JAVA_TYPE_NODES =
          JAVA_TYPES.map { |t| s(:send, s(:const, nil, :Java), t) }

        def on_send(node)
          # ignore Java interop code like Java::int
          return if JAVA_TYPE_NODES.include?(node)

          receiver, method_name, *_args = *node

          # discard methods with nil receivers and op methods(like [])
          return unless receiver && node.loc.dot && node.loc.dot.is?('::')
          return if allowed_name(method_name.to_s)

          add_offense(node, :dot)
        end

        def allowed_name(method_name)
          method_name.match(/^[A-Z]/)
        end

        def autocorrect(node)
          ->(corrector) { corrector.replace(node.loc.dot, '.') }
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/colon_method_call.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.43.0 lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.42.0 lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.41.2 lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.41.1 lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.41.0 lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.40.0 lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.39.0 lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.38.0 lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.37.2 lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.37.1 lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.37.0 lib/rubocop/cop/style/colon_method_call.rb
rubocop-0.36.0 lib/rubocop/cop/style/colon_method_call.rb