Class: RuboCop::Cop::Itamae::CommandEqualsToName

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/itamae/command_equals_to_name.rb

Overview

Check that command doesn't equals to name of execute.

Examples:

# bad
execute 'rm -rf /tmp/*' do
  command 'rm -rf /tmp/*'
end

# good
execute 'rm -rf /tmp/*'

execute 'Remove temporary files' do
  command 'rm -rf /tmp/*'
end

Constant Summary collapse

MSG =
'Prefer to omit `command` if `command` equals to ' \
'name of `execute`'

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rubocop/cop/itamae/command_equals_to_name.rb', line 43

def on_block(node)
  find_execute(node) do |name, param_nodes|
    param_nodes.compact.each do |param_node|
      find_command(param_node) do |command|
        next unless name == command

        add_param_node_offense(param_node)
      end
    end
  end
end