Class: RuboCop::Cop::Sevencop::BundlerGemGroupOrdered

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

Overview

Sort ‘group` in alphabetical order.

Note that the sort key is computed from the sorted and concatenated ‘group` arguments. For example, the sort key for `group :test, :development` is `development-test`.

Examples:

# bad
group :test do
  gem 'rspec'
end

group :development do
  gem 'better_errors'
end

# good
group :development do
  gem 'better_errors'
end

group :test do
  gem 'rspec'
end

Constant Summary collapse

MSG =
'Sort `group` 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)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rubocop/cop/sevencop/bundler_gem_group_ordered.rb', line 44

def on_send(node)
  block_node = node.block_node
  return unless block_node

  previous_older_sibling = find_previous_older_sibling(block_node)
  return unless previous_older_sibling

  add_offense(block_node) do |corrector|
    corrector.swap(
      range_with_comments_and_lines(previous_older_sibling),
      range_with_comments_and_lines(block_node)
    )
  end
end