Class: RuboCop::Cop::Capybara::RedundantWithinFind
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Capybara::RedundantWithinFind
- Extended by:
- AutoCorrector
- Includes:
- CssSelector
- Defined in:
- lib/rubocop/cop/capybara/redundant_within_find.rb
Overview
Checks for redundant ‘within find(…)` calls.
Constant Summary collapse
- MSG =
'Redundant `within %<method>s(...)` call detected.'- RESTRICT_ON_SEND =
%i[within].freeze
- FIND_METHODS =
Set.new(%i[find find_by_id]).freeze
Instance Method Summary collapse
Methods included from CssSelector
attribute?, attributes, classes, css_escape, id, id?, multiple_selectors?, pseudo_classes
Instance Method Details
#on_send(node) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/rubocop/cop/capybara/redundant_within_find.rb', line 42 def on_send(node) within_find(node) do |find_node| add_offense(find_node, message: msg(find_node)) do |corrector| corrector.replace(find_node, replaced(find_node)) end end end |
#within_find(node) ⇒ Object
37 38 39 40 |
# File 'lib/rubocop/cop/capybara/redundant_within_find.rb', line 37 def_node_matcher :within_find, <<~PATTERN (send nil? :within $(send nil? %FIND_METHODS ...)) PATTERN |