cookstyle 6.2.5 → 6.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/config/cookstyle.yml +292 -13
- data/config/disable_all.yml +13 -3
- data/config/upstream.yml +88 -17
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/chef/platform_helpers.rb +2 -1
- data/lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb +77 -0
- data/lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb +77 -0
- data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +56 -0
- data/lib/rubocop/cop/chef/correctness/node_normal.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb +45 -0
- data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +10 -4
- data/lib/rubocop/cop/chef/deprecation/deprecated_shellout_methods.rb +65 -0
- data/lib/rubocop/cop/chef/deprecation/easy_install.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/erl_call.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb +2 -2
- data/lib/rubocop/cop/chef/deprecation/log_resource_notifications.rb +5 -2
- data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/node_set.rb +2 -3
- data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +2 -3
- data/lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb +3 -3
- data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +59 -0
- data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +6 -1
- data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +3 -3
- data/lib/rubocop/cop/chef/modernize/respond_to_compile_time.rb +93 -0
- data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +15 -5
- data/lib/rubocop/cop/chef/modernize/shell_out_helper.rb +64 -0
- data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +8 -4
- data/lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb +9 -2
- data/lib/rubocop/cop/chef/redundant/grouping_metadata.rb +0 -1
- data/lib/rubocop/cop/chef/redundant/sensitive_property_in_resource.rb +3 -3
- data/lib/rubocop/cop/chef/style/negating_only_if.rb +8 -3
- data/lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb +1 -1
- data/lib/rubocop/cop/target_chef_version.rb +4 -0
- metadata +12 -4
@@ -0,0 +1,56 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2020, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module ChefCorrectness
|
22
|
+
# When setting a node attribute as a default value for a custom resource property, make sure to wrap the node attribute in `lazy {}` so that the node attribute is available when the resource executes.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# property :Something, String, default: node['hostname']
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# property :Something, String, default: lazy { node['hostname'] }
|
31
|
+
#
|
32
|
+
class LazyEvalNodeAttributeDefaults < Cop
|
33
|
+
include RuboCop::Chef::CookbookHelpers
|
34
|
+
|
35
|
+
MSG = 'When setting a node attribute as a default value for a custom resource property, make sure to wrap the node attribute in `lazy {}` so that the node attribute is available when the resource executes.'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :non_lazy_node_attribute_default?, <<-PATTERN
|
38
|
+
(send nil? :property (sym _) ... (hash <(pair (sym :default) $(send (send _ :node) :[] _) ) ...>))
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_send(node)
|
42
|
+
non_lazy_node_attribute_default?(node) do |default|
|
43
|
+
add_offense(default, location: :expression, message: MSG, severity: :refactor)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def autocorrect(node)
|
48
|
+
lambda do |corrector|
|
49
|
+
corrector.replace(node.loc.expression, "lazy { #{node.loc.expression.source} }")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
module Chef
|
19
19
|
module ChefCorrectness
|
20
20
|
# Normal attributes are discouraged since their semantics differ importantly from the
|
21
|
-
# default and override levels.
|
21
|
+
# default and override levels. Their values persist in the node object even after
|
22
22
|
# all code referencing them has been deleted, unlike default and override.
|
23
23
|
#
|
24
24
|
# Code should be updated to use default or override levels, but this will change
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
module Chef
|
19
19
|
module ChefCorrectness
|
20
20
|
# Normal attributes are discouraged since their semantics differ importantly from the
|
21
|
-
# default and override levels.
|
21
|
+
# default and override levels. Their values persist in the node object even after
|
22
22
|
# all code referencing them has been deleted, unlike default and override.
|
23
23
|
#
|
24
24
|
# Code should be updated to use default or override levels, but this will change
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright 2020, Chef Software Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
module ChefCorrectness
|
21
|
+
# The openSSL cookbook provides a deprecated `secure_password` helper in the `Opscode::OpenSSL::Password` class, which should not longer be used. This helper would generate a random password that would be used when a data bag or attribute was no present. The practice of generating passwords to be stored on the node is bad security as it exposes the password to anyone that can view the nodes, and deleting a node deletes the password. Passwords should be retrieved from a secure source for use in cookbooks.
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# ::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)
|
25
|
+
# basic_auth_password = secure_password
|
26
|
+
#
|
27
|
+
class OpenSSLPasswordHelpers < Cop
|
28
|
+
MSG = 'The `secure_password` helper from the openssl cookbooks `Opscode::OpenSSL::Password` class should not be used to generate passwords.'.freeze
|
29
|
+
|
30
|
+
def_node_matcher :openssl_helper?, <<~PATTERN
|
31
|
+
(const
|
32
|
+
(const
|
33
|
+
(const nil? :Opscode) :OpenSSL) :Password)
|
34
|
+
PATTERN
|
35
|
+
|
36
|
+
def on_const(node)
|
37
|
+
openssl_helper?(node) do
|
38
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefDeprecations
|
21
|
-
# Don't depend on the deprecated compat_resource cookbook made obsolete by Chef 12.19+
|
21
|
+
# Don't depend on the deprecated compat_resource cookbook made obsolete by Chef Infra Client 12.19+
|
22
22
|
#
|
23
23
|
# @example
|
24
24
|
#
|
@@ -47,22 +47,28 @@ module RuboCop
|
|
47
47
|
'> 16.04, < 18.04' => true,
|
48
48
|
},
|
49
49
|
'fedora' => {
|
50
|
-
'<
|
50
|
+
'< 31' => '31',
|
51
51
|
},
|
52
52
|
'freebsd' => {
|
53
|
-
'< 11' => '
|
53
|
+
'~> 11.0, < 11.2' => '11',
|
54
|
+
'= 12.0' => '12',
|
55
|
+
'< 11' => true,
|
54
56
|
},
|
55
57
|
'mac_os_x' => {
|
56
58
|
'< 10.12' => '10.15',
|
57
59
|
},
|
60
|
+
'suse' => {
|
61
|
+
'~> 12.0, < 12.4' => '12',
|
62
|
+
'< 12' => true,
|
63
|
+
},
|
58
64
|
'opensuse' => {
|
59
65
|
'< 14' => true,
|
60
66
|
'~> 42.0' => true,
|
61
67
|
},
|
62
68
|
'debian' => {
|
63
69
|
'< 8' => true,
|
64
|
-
'> 8.0, < 8.
|
65
|
-
'> 9.0, < 9.
|
70
|
+
'> 8.0, < 8.10' => '8',
|
71
|
+
'> 9.0, < 9.9' => '9',
|
66
72
|
},
|
67
73
|
'centos' => {
|
68
74
|
'< 6.0' => true,
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2020, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module ChefDeprecations
|
22
|
+
# The large number of shell_out helper methods in Chef Infra Client has been reduced to just shell_out and shell_out! methods. The legacy methods were removed in Chef Infra Client and cookbooks using these legacy helpers will need to be updated.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# shell_out_compact('foo')
|
28
|
+
# shell_out_compact!('foo')
|
29
|
+
# shell_out_with_timeout('foo')
|
30
|
+
# shell_out_with_timeout!('foo')
|
31
|
+
# shell_out_with_systems_locale('foo')
|
32
|
+
# shell_out_with_systems_locale!('foo')
|
33
|
+
# shell_out_compact_timeout('foo')
|
34
|
+
# shell_out_compact_timeout!('foo')
|
35
|
+
#
|
36
|
+
# # good
|
37
|
+
# shell_out('foo')
|
38
|
+
# shell_out!('foo')
|
39
|
+
# shell_out!('foo', default_env: false) # replaces shell_out_with_systems_locale
|
40
|
+
#
|
41
|
+
class DeprecatedShelloutMethods < Cop
|
42
|
+
extend TargetChefVersion
|
43
|
+
|
44
|
+
minimum_target_chef_version '14.3'
|
45
|
+
|
46
|
+
DEPRECATED_SHELLOUT_METHODS = %i( shell_out_compact
|
47
|
+
shell_out_compact!
|
48
|
+
shell_out_compact_timeout
|
49
|
+
shell_out_compact_timeout!
|
50
|
+
shell_out_with_timeout
|
51
|
+
shell_out_with_timeout!
|
52
|
+
shell_out_with_systems_locale
|
53
|
+
shell_out_with_systems_locale!
|
54
|
+
).freeze
|
55
|
+
|
56
|
+
MSG = 'Many legacy specialized shell_out methods were replaced in Chef Infra Client 14.3 and removed in Chef Infra Client 15. Use shell_out and any additional options if necessary.'.freeze
|
57
|
+
|
58
|
+
def on_send(node)
|
59
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning) if DEPRECATED_SHELLOUT_METHODS.include?(node.method_name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefDeprecations
|
22
|
-
# Don't use the deprecated easy_install resource removed in Chef 13
|
22
|
+
# Don't use the deprecated easy_install resource removed in Chef Infra Client 13
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
# end
|
30
30
|
#
|
31
31
|
class EasyInstallResource < Cop
|
32
|
-
MSG = "Don't use the deprecated easy_install resource removed in Chef 13".freeze
|
32
|
+
MSG = "Don't use the deprecated easy_install resource removed in Chef Infra Client 13".freeze
|
33
33
|
|
34
34
|
def on_send(node)
|
35
35
|
add_offense(node, location: :expression, message: MSG, severity: :warning) if node.method_name == :easy_install
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
# end
|
30
30
|
#
|
31
31
|
class ErlCallResource < Cop
|
32
|
-
MSG = "Don't use the deprecated erl_call resource removed in Chef 13".freeze
|
32
|
+
MSG = "Don't use the deprecated erl_call resource removed in Chef Infra Client 13".freeze
|
33
33
|
|
34
34
|
def on_send(node)
|
35
35
|
add_offense(node, location: :expression, message: MSG, severity: :warning) if node.method_name == :erl_call
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefDeprecations
|
21
|
-
# The local resource's lc_all property has been deprecated and will be removed in Chef Infra Client
|
21
|
+
# The local resource's lc_all property has been deprecated and will be removed in Chef Infra Client 17
|
22
22
|
#
|
23
23
|
# @example
|
24
24
|
#
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
class LocaleDeprecatedLcAllProperty < Cop
|
32
32
|
include RuboCop::Chef::CookbookHelpers
|
33
33
|
|
34
|
-
MSG = "The local resource's lc_all property has been deprecated and will be removed in Chef Infra Client
|
34
|
+
MSG = "The local resource's lc_all property has been deprecated and will be removed in Chef Infra Client 17".freeze
|
35
35
|
|
36
36
|
def on_block(node)
|
37
37
|
match_property_in_resource?(:locale, 'lc_all', node) do |property|
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module ChefDeprecations
|
22
|
-
# In Chef Infra Client 16 the log resource no longer notifies when logging so notifications should not be triggered from log resources.
|
22
|
+
# In Chef Infra Client 16 the log resource no longer notifies when logging so notifications should not be triggered from log resources. Use the notify_group resource introduced in Chef Infra Client 15.8 instead to aggregate notifications.
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
@@ -45,8 +45,11 @@ module RuboCop
|
|
45
45
|
#
|
46
46
|
class LogResourceNotifications < Cop
|
47
47
|
include RuboCop::Chef::CookbookHelpers
|
48
|
+
extend TargetChefVersion
|
48
49
|
|
49
|
-
|
50
|
+
minimum_target_chef_version '15.8'
|
51
|
+
|
52
|
+
MSG = 'In Chef Infra Client 16 the log resource no longer notifies when logging so notifications should not be triggered from log resources. Use the notify_group resource introduced in Chef Infra Client 15.8 instead to aggregate notifications.'.freeze
|
50
53
|
|
51
54
|
def on_block(node)
|
52
55
|
match_property_in_resource?(:log, 'notifies', node) do |prop_node|
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefDeprecations
|
21
|
-
#
|
21
|
+
# Use node attributes to access data provided by Ohai instead of using node methods to access that data.
|
22
22
|
#
|
23
23
|
# @example
|
24
24
|
#
|
@@ -17,10 +17,9 @@ module RuboCop
|
|
17
17
|
module Cop
|
18
18
|
module Chef
|
19
19
|
module ChefDeprecations
|
20
|
-
# The node.set method has been removed in Chef
|
20
|
+
# The `node.set` method has been removed in Chef Infra Client 13 and usage must be replaced with `node.normal`.
|
21
21
|
#
|
22
|
-
#
|
23
|
-
# also discouraged.
|
22
|
+
# This cop will autocorrect code to use node.normal, which is functionally identical to node.set, but we also discourage the use of that method as normal level attributes persist on the node even if the code setting the attribute is later removed.
|
24
23
|
#
|
25
24
|
# @example
|
26
25
|
#
|
@@ -17,10 +17,9 @@ module RuboCop
|
|
17
17
|
module Cop
|
18
18
|
module Chef
|
19
19
|
module ChefDeprecations
|
20
|
-
# The node.set_unless method has been removed in Chef
|
20
|
+
# The node.set_unless method has been removed in Chef Infra Client 13 and usage must be replaced with node.normal_unless.
|
21
21
|
#
|
22
|
-
#
|
23
|
-
# also discouraged.
|
22
|
+
# This cop will autocorrect code to use node.normal_unless, which is functionally identical to node.set_unless, but we also discourage the use of that method as normal level attributes persist on the node even if the code setting the attribute is later removed.
|
24
23
|
#
|
25
24
|
# @example
|
26
25
|
#
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefDeprecations
|
21
|
-
# Use node['powershell']['version'] or the new powershell_version helper available in Chef Infra Client
|
21
|
+
# Use `node['powershell']['version']` or the new `powershell_version` helper available in Chef Infra Client 15.8+ instead of the deprecated PowerShell cookbook helpers
|
22
22
|
#
|
23
23
|
# @example
|
24
24
|
#
|
@@ -28,11 +28,11 @@ module RuboCop
|
|
28
28
|
# # good
|
29
29
|
# node['powershell']['version'].to_f == 4.0
|
30
30
|
#
|
31
|
-
# #
|
31
|
+
# # better (Chef Infra Client 15.8+)
|
32
32
|
# powershell_version == 4.0
|
33
33
|
#
|
34
34
|
class PowershellCookbookHelpers < Cop
|
35
|
-
MSG = "Use node['powershell']['version'] or the new powershell_version helper available in Chef Infra Client
|
35
|
+
MSG = "Use node['powershell']['version'] or the new powershell_version helper available in Chef Infra Client 15.8+ instead of the deprecated PowerShell cookbook helpers.".freeze
|
36
36
|
|
37
37
|
def_node_matcher :ps_cb_helper?, <<-PATTERN
|
38
38
|
(send
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2020, Chef Software, Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module ChefDeprecations
|
22
|
+
# Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# shell_out!('hostnamectl status', { returns: [0, 1] })
|
28
|
+
# shell_out('hostnamectl status', { returns: [0, 1] })
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# shell_out!('hostnamectl status', returns: [0, 1])
|
32
|
+
# shell_out('hostnamectl status', returns: [0, 1])
|
33
|
+
#
|
34
|
+
class Ruby27KeywordArgumentWarnings < Cop
|
35
|
+
include RuboCop::Chef::CookbookHelpers
|
36
|
+
|
37
|
+
MSG = 'Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings.'.freeze
|
38
|
+
|
39
|
+
def_node_matcher :positional_shellout?, <<-PATTERN
|
40
|
+
(send nil? {:shell_out :shell_out!} ... $(hash ... ))
|
41
|
+
PATTERN
|
42
|
+
|
43
|
+
def on_send(node)
|
44
|
+
positional_shellout?(node) do |h|
|
45
|
+
add_offense(h, location: :expression, message: MSG, severity: :refactor) if h.braces?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def autocorrect(node)
|
50
|
+
lambda do |corrector|
|
51
|
+
# @todo when we drop ruby 2.4 support we can convert to to just delete_prefix delete_suffix
|
52
|
+
corrector.replace(node.loc.expression, node.loc.expression.source.gsub(/^{/, '').gsub(/}$/, ''))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -54,8 +54,13 @@ module RuboCop
|
|
54
54
|
def autocorrect(node)
|
55
55
|
lambda do |corrector|
|
56
56
|
new_text = []
|
57
|
+
|
57
58
|
node.arguments.first.each_pair do |k, v|
|
58
|
-
|
59
|
+
# account for a strange edge case where the person incorrectly makes "manage_home a method
|
60
|
+
# the code would be broken, but without this handling cookstyle would explode
|
61
|
+
key_value = (k.send_type? && k.method_name == :manage_home) ? 'manage_home' : k.value
|
62
|
+
|
63
|
+
new_text << "#{key_value} #{v.source}"
|
59
64
|
end
|
60
65
|
|
61
66
|
corrector.replace(node.loc.expression, new_text.join("\n "))
|