Class: RuboCop::Cop::Chef::Ruby::Ruby27KeywordArgumentWarnings

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/chef/ruby/ruby_27_keyword_argument_warnings.rb

Overview

Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings.

Examples:


# bad
shell_out!('hostnamectl status', { returns: [0, 1] })
shell_out('hostnamectl status', { returns: [0, 1] })

# good
shell_out!('hostnamectl status', returns: [0, 1])
shell_out('hostnamectl status', returns: [0, 1])

Constant Summary collapse

MSG =
"Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings."

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/rubocop/cop/chef/ruby/ruby_27_keyword_argument_warnings.rb', line 44

def on_send(node)
  positional_shellout?(node) do |h|
    next unless h.braces?

    add_offense(h.loc.expression, message: MSG, severity: :refactor) do |corrector|
      corrector.replace(h.loc.expression, h.loc.expression.source[1..-2])
    end
  end
end