Class: RuboCop::Cop::RSpec::SortMetadata
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp, Metadata
- Defined in:
- lib/rubocop/cop/rspec/sort_metadata.rb
Overview
Sort RSpec metadata alphabetically.
Only the trailing metadata is sorted.
Constant Summary collapse
- MSG =
'Sort metadata alphabetically.'
Instance Method Summary collapse
Methods included from Metadata
#metadata_in_block, #on_block, #rspec_configure, #rspec_metadata
Methods included from RSpec::Language
#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Methods inherited from Base
inherited, #on_new_investigation
Instance Method Details
permalink #match_ambiguous_trailing_metadata?(node) ⇒ Object
[View source]
32 33 34 |
# File 'lib/rubocop/cop/rspec/sort_metadata.rb', line 32 def_node_matcher :match_ambiguous_trailing_metadata?, <<~PATTERN (send _ _ _ ... !{hash sym str dstr xstr}) PATTERN |
permalink #on_metadata(args, hash) ⇒ Object
[View source]
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rubocop/cop/rspec/sort_metadata.rb', line 36 def (args, hash) pairs = hash&.pairs || [] symbols = trailing_symbols(args) return if sorted?(symbols, pairs) crime_scene = crime_scene(symbols, pairs) add_offense(crime_scene) do |corrector| corrector.replace(crime_scene, replacement(symbols, pairs)) end end |