Sha256: 78ddb409445ddabbba1157e234c61c62fe3d47db294fac19d66a9e5d1e602959
Contents?: true
Size: 779 Bytes
Versions: 38
Compression:
Stored size: 779 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) { |corrector| corrector.replace(node, "#{node.source} =~ $_") } end end end end end
Version data entries
38 entries across 38 versions & 6 rubygems