Class: RuboCop::Cop::UmtsCustomCops::BeMatcherForNonDuplicableTypes
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::UmtsCustomCops::BeMatcherForNonDuplicableTypes
- Defined in:
- lib/umts-custom-cops/be_matcher_for_non_duplicable_types.rb
Overview
rubocop:disable Metrics/AbcSize
Constant Summary collapse
- MSG =
'Prefer `be` matcher to `eq` or `eql` for non-duplicable types.'- OFFENSE_TYPE_CHECKS =
%i(true_type? false_type? nil_type? int_type?)
Instance Method Summary collapse
Instance Method Details
#autocorrect(node) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/umts-custom-cops/be_matcher_for_non_duplicable_types.rb', line 17 def autocorrect(node) lambda do |corrector| matcher = node.child_nodes[1] corrector.replace matcher.loc.selector, 'be' end end |
#on_send(node) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/umts-custom-cops/be_matcher_for_non_duplicable_types.rb', line 24 def on_send(node) return unless %i(to not_to).include? node.method_name return unless node.child_nodes && node.child_nodes.first.method_name == :expect matcher = node.child_nodes[1] return unless %i(eq eql).include? matcher.method_name args = matcher.child_nodes.first return unless OFFENSE_TYPE_CHECKS.find { |check| args.send check } add_offense node, :expression, MSG end |