Class: RuboCop::Cop::Capybara::FindAllFirst
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Capybara::FindAllFirst
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/capybara/find_all_first.rb
Overview
Enforces use of ‘first` instead of `all` with `first` or `[0]`.
Constant Summary collapse
- MSG =
'Use `first(%<selector>s)`.'
- RESTRICT_ON_SEND =
i[all find].freeze
Instance Method Summary collapse
Instance Method Details
#find_all_first?(node) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/rubocop/cop/capybara/find_all_first.rb', line 27 def_node_matcher :find_all_first?, "{\n (send (send _ :all _ ...) :first)\n (send (send _ :all _ ...) :[] (int 0))\n}\n" |
#include_match_first?(node) ⇒ Object
35 36 37 |
# File 'lib/rubocop/cop/capybara/find_all_first.rb', line 35 def_node_matcher :include_match_first?, "(send _ {:find :all} _ $(hash <(pair (sym :match) (sym :first)) ...>))\n" |
#on_send(node) ⇒ Object
39 40 41 42 |
# File 'lib/rubocop/cop/capybara/find_all_first.rb', line 39 def on_send(node) on_all_first(node) on_match_first(node) end |