Sha256: 4f255690cd180041ade547b9437f2f999e1c71c68760a05f4dc92b62cd3fd6b3

Contents?: true

Size: 1.12 KB

Versions: 47

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for ambiguous regexp literals in the first argument of
      # a method invocation without parentheses.
      #
      # @example
      #
      #   # bad
      #
      #   # This is interpreted as a method invocation with a regexp literal,
      #   # but it could possibly be `/` method invocations.
      #   # (i.e. `do_something./(pattern)./(i)`)
      #   do_something /pattern/i
      #
      # @example
      #
      #   # good
      #
      #   # With parentheses, there's no ambiguity.
      #   do_something(/pattern/i)
      class AmbiguousRegexpLiteral < Cop
        include ParserDiagnostic

        MSG = 'Ambiguous regexp literal. Parenthesize the method arguments ' \
              "if it's surely a regexp literal, or add a whitespace to the " \
              'right of the `/` if it should be a division.'

        private

        def relevant_diagnostic?(diagnostic)
          diagnostic.reason == :ambiguous_literal
        end

        def alternative_message(_diagnostic)
          MSG
        end
      end
    end
  end
end

Version data entries

47 entries across 28 versions & 3 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
rubocop-0.82.0 lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
rubocop-0.81.0 lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
rubocop-0.80.1 lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
rubocop-0.80.0 lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
rubocop-0.79.0 lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
rubocop-0.78.0 lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
rubocop-0.77.0 lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb