Sha256: 9afa53738a88207ef7e4367ff8e75cbb92dffed6cf009fb1e223c60d5061f67c
Contents?: true
Size: 804 Bytes
Versions: 37
Compression:
Stored size: 804 Bytes
Contents
# frozen_string_literal: true module RuboCop module Cop module Lint # This cop checks for regexp literals used as `match-current-line`. # If a regexp literal is in condition, the regexp matches `$_` implicitly. # # @example # # bad # if /foo/ # do_something # end # # # good # if /foo/ =~ $_ # do_something # end class RegexpAsCondition < Base extend AutoCorrector MSG = 'Do not use regexp literal as a condition.' \ ' The regexp literal matches `$_` implicitly.' def on_match_current_line(node) add_offense(node) do |corrector| corrector.replace(node, "#{node.source} =~ $_") end end end end end end
Version data entries
37 entries across 37 versions & 3 rubygems