Class: RuboCop::Cop::RSpec::SortMetadata
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/rspec/sort_metadata.rb
Overview
Sort RSpec metadata alphabetically.
Constant Summary collapse
- MSG =
'Sort metadata alphabetically.'
Instance Method Summary collapse
- #metadata_in_block(node) ⇒ Object
- #on_block(node) ⇒ Object (also: #on_numblock)
- #rspec_configure(node) ⇒ Object
- #rspec_metadata(node) ⇒ Object
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
#block_pattern, #numblock_pattern, #send_pattern
Methods included from RSpec::Language
#example?, #example_group?, #example_group_with_body?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#metadata_in_block(node) ⇒ Object
39 40 41 |
# File 'lib/rubocop/cop/rspec/sort_metadata.rb', line 39 def_node_search :metadata_in_block, <<~PATTERN (send (lvar %) #Hooks.all _ ${send str sym}* (hash $...)?) PATTERN |
#on_block(node) ⇒ Object Also known as: on_numblock
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubocop/cop/rspec/sort_metadata.rb', line 43 def on_block(node) rspec_configure(node) do |block_var| (node, block_var) do |symbols, pairs| investigate(symbols, pairs.flatten) end end (node) do |symbols, pairs| investigate(symbols, pairs.flatten) end end |
#rspec_configure(node) ⇒ Object
34 35 36 |
# File 'lib/rubocop/cop/rspec/sort_metadata.rb', line 34 def_node_matcher :rspec_configure, <<~PATTERN (block (send #rspec? :configure) (args (arg $_)) ...) PATTERN |
#rspec_metadata(node) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rubocop/cop/rspec/sort_metadata.rb', line 26 def_node_matcher :rspec_metadata, <<~PATTERN (block (send #rspec? {#Examples.all #ExampleGroups.all #SharedGroups.all #Hooks.all} _ ${send str sym}* (hash $...)?) ...) PATTERN |