Class: RuboCop::Cop::Sevencop::BundlerGemGroupNameOrdered

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp, Sevencop::CopConcerns::Ordered
Defined in:
lib/rubocop/cop/sevencop/bundler_gem_group_name_ordered.rb

Overview

Sort ‘group` names in alphabetical order.

Examples:

# bad
group :test, :development do
  gem 'rspec-rails'
end

# good
group :development, :test do
  gem 'rspec-rails'
end

Constant Summary collapse

MSG =
'Sort `group` names in alphabetical order.'
RESTRICT_ON_SEND =
%i[
  group
].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ void

This method returns an undefined value.

Parameters:

  • node (RuboCop::AST::SendNode)


33
34
35
36
37
38
39
40
41
42
# File 'lib/rubocop/cop/sevencop/bundler_gem_group_name_ordered.rb', line 33

def on_send(node)
  node.arguments.select(&:sym_type?).each do |argument|
    previous_older_sibling = find_previous_older_sibling(argument)
    next unless previous_older_sibling

    add_offense(argument) do |corrector|
      corrector.swap(previous_older_sibling, argument)
    end
  end
end