class RuboCop::Cop::Bundler::OrderedGems
Gems should be alphabetically sorted within groups.
@example
# bad gem 'rubocop' gem 'rspec' # good gem 'rspec' gem 'rubocop' # good gem 'rubocop' gem 'rspec'
@example TreatCommentsAsGroupSeparators: true (default)
# good # For code quality gem 'rubocop' # For tests gem 'rspec'
@example TreatCommentsAsGroupSeparators: false
# bad # For code quality gem 'rubocop' # For tests gem 'rspec'
Constants
- MSG
Public Instance Methods
on_new_investigation()
click to toggle source
# File lib/rubocop/cop/bundler/ordered_gems.rb, line 43 def on_new_investigation return if processed_source.blank? gem_declarations(processed_source.ast) .each_cons(2) do |previous, current| next unless consecutive_lines(previous, current) next unless case_insensitive_out_of_order?(gem_name(current), gem_name(previous)) register_offense(previous, current) end end
Private Instance Methods
previous_declaration(node)
click to toggle source
# File lib/rubocop/cop/bundler/ordered_gems.rb, line 57 def previous_declaration(node) declarations = gem_declarations(processed_source.ast) node_index = declarations.map(&:location).find_index(node.location) declarations.to_a[node_index - 1] end