Class: RuboCop::Cop::Chef::Deprecations::SearchUsesPositionalParameters

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

Overview

In the cookbook search helper you need to use named parameters (key/value style) other than the first (type) and second (query string) values.

Examples:


# bad
search(:node, '*:*', 0, 1000, { :ip_address => ["ipaddress"] })
search(:node, '*:*', 0, 1000)
search(:node, '*:*', 0)

# good
search(:node, '*:*', start: 0, rows: 1000, filter_result: { :ip_address => ["ipaddress"] })
search(:node, '*:*', start: 0, rows: 1000)
search(:node, '*:*', start: 0)

Constant Summary collapse

MSG =
"Don't use deprecated positional parameters in cookbook search queries."
RESTRICT_ON_SEND =
[:search].freeze
NAMED_PARAM_LOOKUP_TABLE =
[nil, nil, 'start', 'rows', 'filter_result'].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb', line 48

def on_send(node)
  search_method?(node) do
    add_offense(node, severity: :warning) do |corrector|
      corrector.replace(node, corrected_string(node))
    end if positional_arguments?(node)
  end
end