cookstyle 6.16.7 → 6.17.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cookstyle +1 -1
- data/config/cookstyle.yml +47 -2
- data/config/upstream.yml +0 -1
- data/lib/cookstyle.rb +2 -2
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +36 -8
- data/lib/rubocop/cop/chef/deprecation/chef_shellout.rb +86 -0
- data/lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb +8 -4
- data/lib/rubocop/cop/chef/deprecation/execute_path_property.rb +51 -0
- data/lib/rubocop/cop/chef/deprecation/execute_relative_creates_without_cwd.rb +67 -0
- data/lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb +2 -1
- data/lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb +4 -2
- data/lib/rubocop/cop/chef/deprecation/windows_feature_servermanagercmd.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/windows_package_installer_type_string.rb +61 -0
- data/lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb +3 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0385aed05c2f7b990958984ace106ea1f8b12d62feae5ba63fc0c382a880f678'
|
4
|
+
data.tar.gz: e7888f5a8f5959069e00a5d3be8ce8a80325b34fe0d943baddb8a414f97947fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a89eab0482fd1c1c158b9f5ead6f61b4693a391fd88855bba6b5e46f60ae3ebb28074ef7782e4d249cd097ebd8093461c25baaff2c699ae214bc12d8584b95ef
|
7
|
+
data.tar.gz: b125b09055b3388353ac3374ea1aa5061dc6dfe75f051a538004ed13d064820e40920d2d13fd2a0557cfe3b602237f346b7316adaa2e1174f9b0e4400ff7e71b
|
data/bin/cookstyle
CHANGED
data/config/cookstyle.yml
CHANGED
@@ -908,10 +908,11 @@ ChefDeprecations/RubyBlockCreateAction:
|
|
908
908
|
- '**/Berksfile'
|
909
909
|
|
910
910
|
ChefDeprecations/DeprecatedPlatformMethods:
|
911
|
-
Description: Use provider_for_action instead of the deprecated Chef::Platform methods in resources.
|
911
|
+
Description: Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources.
|
912
912
|
StyleGuide: '#chefdeprecationsdeprecatedplatformmethods'
|
913
913
|
Enabled: true
|
914
914
|
VersionAdded: '5.16.0'
|
915
|
+
VersionChanged: '6.17.0'
|
915
916
|
Include:
|
916
917
|
- '**/libraries/*.rb'
|
917
918
|
- '**/resources/*.rb'
|
@@ -1062,6 +1063,46 @@ ChefDeprecations/CookbooksDependsOnSelf:
|
|
1062
1063
|
Include:
|
1063
1064
|
- '**/metadata.rb'
|
1064
1065
|
|
1066
|
+
ChefDeprecations/ChefShellout:
|
1067
|
+
Description: Don't use deprecated Chef::ShellOut which was removed in Chef Infra Client 13. Use Mixlib::ShellOut instead, which behaves identically.
|
1068
|
+
StyleGuide: '#chefdeprecationschefshellout'
|
1069
|
+
Enabled: true
|
1070
|
+
VersionAdded: '6.17.0'
|
1071
|
+
Exclude:
|
1072
|
+
- '**/metadata.rb'
|
1073
|
+
- '**/attributes/*.rb'
|
1074
|
+
- '**/Berksfile'
|
1075
|
+
|
1076
|
+
ChefDeprecations/ExecutePathProperty:
|
1077
|
+
Description: In Chef Infra Client 13 and later you must set path env vars in `execute` resources using the `environment` property not the legacy `path` property.
|
1078
|
+
StyleGuide: '#chefdeprecationsexecutepathproperty'
|
1079
|
+
Enabled: true
|
1080
|
+
VersionAdded: '6.17.0'
|
1081
|
+
Exclude:
|
1082
|
+
- '**/metadata.rb'
|
1083
|
+
- '**/attributes/*.rb'
|
1084
|
+
- '**/Berksfile'
|
1085
|
+
|
1086
|
+
ChefDeprecations/ExecuteRelativeCreatesWithoutCwd:
|
1087
|
+
Description: In Chef Infra Client 13 and later you must either specify an absolute path when using the `execute` resource's `creates` property or also use the `cwd` property.
|
1088
|
+
StyleGuide: '#chefdeprecationsexecuterelativecreateswithoutcwd'
|
1089
|
+
Enabled: true
|
1090
|
+
VersionAdded: '6.17.0'
|
1091
|
+
Exclude:
|
1092
|
+
- '**/metadata.rb'
|
1093
|
+
- '**/attributes/*.rb'
|
1094
|
+
- '**/Berksfile'
|
1095
|
+
|
1096
|
+
ChefDeprecations/WindowsPackageInstallerTypeString:
|
1097
|
+
Description: In Chef Infra Client 13 and later the `windows_package` resource's `installer_type` property must be a symbol.
|
1098
|
+
StyleGuide: '#chefdeprecationswindowspackageinstallertypestring'
|
1099
|
+
Enabled: true
|
1100
|
+
VersionAdded: '6.17.0'
|
1101
|
+
Exclude:
|
1102
|
+
- '**/metadata.rb'
|
1103
|
+
- '**/attributes/*.rb'
|
1104
|
+
- '**/Berksfile'
|
1105
|
+
|
1065
1106
|
###############################
|
1066
1107
|
# ChefModernize: Cleaning up legacy code and using new built-in resources
|
1067
1108
|
###############################
|
@@ -2612,4 +2653,8 @@ Style/BisectedAttrAccessor:
|
|
2612
2653
|
|
2613
2654
|
# avoid assignments that aren't needed
|
2614
2655
|
Style/RedundantAssignment:
|
2615
|
-
Enabled: true
|
2656
|
+
Enabled: true
|
2657
|
+
|
2658
|
+
# alert on invalid ruby
|
2659
|
+
Lint/Syntax:
|
2660
|
+
Enabled: true
|
data/config/upstream.yml
CHANGED
data/lib/cookstyle.rb
CHANGED
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
class ConfigLoader
|
20
20
|
RUBOCOP_HOME.gsub!(
|
21
21
|
/^.*$/,
|
22
|
-
File.realpath(File.join(
|
22
|
+
File.realpath(File.join(__dir__, '..'))
|
23
23
|
)
|
24
24
|
|
25
25
|
DEFAULT_FILE.gsub!(
|
@@ -46,7 +46,7 @@ require_relative 'rubocop/chef/cookbook_only'
|
|
46
46
|
require_relative 'rubocop/cop/target_chef_version'
|
47
47
|
|
48
48
|
# Chef Infra specific cops
|
49
|
-
Dir.glob(
|
49
|
+
Dir.glob(__dir__ + '/rubocop/cop/chef/**/*.rb') do |file|
|
50
50
|
next if File.directory?(file)
|
51
51
|
|
52
52
|
require_relative file # not actually relative but require_relative is faster
|
data/lib/cookstyle/version.rb
CHANGED
@@ -33,30 +33,58 @@ module RuboCop
|
|
33
33
|
# ::Chef::DSL::Recipe.send(:include, Filebeat::Helpers) # covers previous Recipe & Provider classes
|
34
34
|
#
|
35
35
|
class IncorrectLibraryInjection < Base
|
36
|
+
include RangeHelp
|
36
37
|
extend AutoCorrector
|
37
38
|
|
38
39
|
MSG = 'Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.'
|
39
40
|
|
41
|
+
def_node_search :correct_send?, <<-PATTERN
|
42
|
+
(send
|
43
|
+
(const
|
44
|
+
(const
|
45
|
+
(const {cbase nil?} :Chef) :DSL) :Recipe) :send
|
46
|
+
(sym :include)
|
47
|
+
... )
|
48
|
+
PATTERN
|
49
|
+
|
50
|
+
def_node_search :correct_include?, <<-PATTERN
|
51
|
+
(send
|
52
|
+
(const
|
53
|
+
(const
|
54
|
+
(const {cbase nil?} :Chef) :DSL) :Recipe) :include
|
55
|
+
... )
|
56
|
+
PATTERN
|
57
|
+
|
40
58
|
def_node_matcher :legacy_class_sends?, <<-PATTERN
|
41
|
-
(send (const (const
|
59
|
+
(send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :send (sym :include) ... )
|
42
60
|
PATTERN
|
43
61
|
|
44
|
-
def_node_matcher :
|
45
|
-
(send (const (const
|
62
|
+
def_node_matcher :legacy_class_include?, <<-PATTERN
|
63
|
+
(send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :include ... )
|
46
64
|
PATTERN
|
47
65
|
|
66
|
+
# @todo: This is highly repetitive and could be simplified into a single node_matcher
|
67
|
+
# call with some matcher magic that should be figured out
|
48
68
|
def on_send(node)
|
49
69
|
legacy_class_sends?(node) do
|
50
70
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
51
|
-
|
52
|
-
|
71
|
+
if node.parent && correct_send?(node.parent)
|
72
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
73
|
+
else
|
74
|
+
corrector.replace(node.loc.expression,
|
75
|
+
node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
|
76
|
+
end
|
53
77
|
end
|
54
78
|
end
|
55
79
|
|
56
|
-
|
80
|
+
legacy_class_include?(node) do
|
57
81
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
58
|
-
|
59
|
-
|
82
|
+
if node.parent && correct_include?(node.parent)
|
83
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
84
|
+
else
|
85
|
+
corrector.replace(node.loc.expression,
|
86
|
+
node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
|
87
|
+
end
|
60
88
|
end
|
61
89
|
end
|
62
90
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: 2020, Chef Software Inc.
|
4
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module RuboCop
|
20
|
+
module Cop
|
21
|
+
module Chef
|
22
|
+
module ChefDeprecations
|
23
|
+
# Don't use deprecated Chef::ShellOut which was removed in Chef Infra Client 13.
|
24
|
+
# Use Mixlib::ShellOut instead, which behaves identically or convert to the shell_out
|
25
|
+
# helper provided in chef-utils.
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
#
|
29
|
+
# # bad
|
30
|
+
# include Chef::ShellOut
|
31
|
+
# require 'chef/shellout'
|
32
|
+
# Chef::ShellOut.new('some_command')
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# include Mixlib::ShellOut
|
36
|
+
# require 'mixlib/shellout'
|
37
|
+
# Mixlib::ShellOut.new('some_command')
|
38
|
+
#
|
39
|
+
class ChefShellout < Base
|
40
|
+
include RangeHelp
|
41
|
+
extend AutoCorrector
|
42
|
+
|
43
|
+
MSG = "Don't use deprecated Chef::ShellOut which was removed in Chef Infra Client 13. Use Mixlib::ShellOut instead, which behaves identically."
|
44
|
+
# RESTRICT_ON_SEND = [:new, :require, :include].freeze
|
45
|
+
|
46
|
+
def_node_matcher :include_shellout?, <<-PATTERN
|
47
|
+
(send nil? :include
|
48
|
+
(const
|
49
|
+
(const nil? :Chef) :ShellOut))
|
50
|
+
PATTERN
|
51
|
+
|
52
|
+
def_node_matcher :require_shellout?, <<-PATTERN
|
53
|
+
(send nil? :require (str "chef/shellout"))
|
54
|
+
PATTERN
|
55
|
+
|
56
|
+
def_node_matcher :shellout_new?, <<-PATTERN
|
57
|
+
(send
|
58
|
+
(const
|
59
|
+
(const nil? :Chef) :ShellOut) :new
|
60
|
+
... )
|
61
|
+
PATTERN
|
62
|
+
|
63
|
+
def on_send(node)
|
64
|
+
include_shellout?(node) do
|
65
|
+
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
66
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
require_shellout?(node) do
|
71
|
+
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
72
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
shellout_new?(node) do
|
77
|
+
add_offense(node, message: MSG, severity: :warning) do |corrector|
|
78
|
+
corrector.replace(node.loc.expression, node.source.gsub('Chef::ShellOut', 'Mixlib::ShellOut'))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
|
-
# Copyright:: 2019, Chef Software Inc.
|
3
|
+
# Copyright:: 2019-2020, Chef Software Inc.
|
4
4
|
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
module Cop
|
21
21
|
module Chef
|
22
22
|
module ChefDeprecations
|
23
|
-
# Use provider_for_action instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.
|
23
|
+
# Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.
|
24
24
|
#
|
25
25
|
# @example
|
26
26
|
#
|
@@ -34,15 +34,19 @@ module RuboCop
|
|
34
34
|
# resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
|
35
35
|
# provider = Chef::Platform.find_provider_for_node(node, resource)
|
36
36
|
#
|
37
|
+
# Chef::Platform.set :platform => :mac_os_x, :resource => :package, :provider => Chef::Provider::Package::Homebrew
|
38
|
+
#
|
37
39
|
# # good
|
38
40
|
# resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
|
39
41
|
# provider = resource.provider_for_action(:create)
|
40
42
|
#
|
43
|
+
# # provides :package, platform_family: 'mac_os_x'
|
44
|
+
|
41
45
|
class DeprecatedPlatformMethods < Base
|
42
|
-
MSG = 'Use provider_for_action instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.'
|
46
|
+
MSG = 'Use provider_for_action or provides instead of the deprecated Chef::Platform methods in resources, which were removed in Chef Infra Client 13.'
|
43
47
|
|
44
48
|
def_node_matcher :platform_method?, <<-PATTERN
|
45
|
-
(send (const (const nil? :Chef) :Platform) {:provider_for_resource :find_provider :find_provider_for_node} ... )
|
49
|
+
(send (const (const nil? :Chef) :Platform) {:provider_for_resource :find_provider :find_provider_for_node :set} ... )
|
46
50
|
PATTERN
|
47
51
|
|
48
52
|
def on_send(node)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: 2020, Chef Software Inc.
|
4
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module RuboCop
|
20
|
+
module Cop
|
21
|
+
module Chef
|
22
|
+
module ChefDeprecations
|
23
|
+
# In Chef Infra Client 13 and later you must set path env vars in execute resources using the `environment` property not the legacy `path` property.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
#
|
27
|
+
# # bad
|
28
|
+
# execute 'some_cmd' do
|
29
|
+
# path '/foo/bar'
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # good
|
33
|
+
# execute 'some_cmd' do
|
34
|
+
# environment {path: '/foo/bar'}
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
class ExecutePathProperty < Base
|
38
|
+
include RuboCop::Chef::CookbookHelpers
|
39
|
+
|
40
|
+
MSG = 'In Chef Infra Client 13 and later you must set path env vars in execute resources using the `environment` property not the legacy `path` property.'
|
41
|
+
|
42
|
+
def on_block(node)
|
43
|
+
match_property_in_resource?(:execute, 'path', node) do |offense|
|
44
|
+
add_offense(offense.loc.expression, message: MSG, severity: :warning) # @todo: we could probably autocorrect this with some work
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: 2020, Chef Software Inc.
|
4
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module RuboCop
|
20
|
+
module Cop
|
21
|
+
module Chef
|
22
|
+
module ChefDeprecations
|
23
|
+
# In Chef Infra Client 13 and later you must either specific an absolute path when using the `execute` resource's `creates` property or also use the `cwd` property.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
#
|
27
|
+
# # bad
|
28
|
+
# execute 'some_cmd' do
|
29
|
+
# creates 'something'
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # good
|
33
|
+
# execute 'some_cmd' do
|
34
|
+
# creates '/tmp/something'
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# execute 'some_cmd' do
|
38
|
+
# creates 'something'
|
39
|
+
# cwd '/tmp/'
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
class ExecuteRelativeCreatesWithoutCwd < Base
|
43
|
+
include RuboCop::Chef::CookbookHelpers
|
44
|
+
|
45
|
+
MSG = "In Chef Infra Client 13 and later you must either specific an absolute path when using the `execute` resource's `creates` property or also use the `cwd` property."
|
46
|
+
|
47
|
+
def on_block(node)
|
48
|
+
match_property_in_resource?(:execute, 'creates', node) do |offense|
|
49
|
+
return unless offense.arguments.count == 1 # we can only analyze simple string args
|
50
|
+
return unless offense.arguments.first.str_type? # we can only analyze simple string args
|
51
|
+
|
52
|
+
# skip any creates that are abs paths https://rubular.com/r/3TbDsgcAa1EaIF
|
53
|
+
return if offense.arguments.first.value.match?(%r{^(/|[a-zA-Z]:)})
|
54
|
+
|
55
|
+
# return if we have a cwd property
|
56
|
+
match_property_in_resource?(:execute, 'cwd', node) do
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
add_offense(offense.loc.expression, message: MSG, severity: :warning)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -33,11 +33,12 @@ module RuboCop
|
|
33
33
|
#
|
34
34
|
class ResourceOverridesProvidesMethod < Base
|
35
35
|
MSG = "Don't override the provides? method in a resource provider. Use provides :SOME_PROVIDER_NAME instead. This will cause failures in Chef Infra Client 13 and later."
|
36
|
-
RESTRICT_ON_SEND = [:provides?].freeze
|
37
36
|
|
38
37
|
def_node_search :provides, '(send nil? :provides ...)'
|
39
38
|
|
40
39
|
def on_def(node)
|
40
|
+
return unless node.method_name == :provides?
|
41
|
+
|
41
42
|
add_offense(node, message: MSG, severity: :warning) if provides(processed_source.ast).count == 0
|
42
43
|
end
|
43
44
|
end
|
@@ -57,6 +57,8 @@ module RuboCop
|
|
57
57
|
|
58
58
|
private
|
59
59
|
|
60
|
+
VALID_TYPES = %i(send hash block_pass).freeze
|
61
|
+
|
60
62
|
#
|
61
63
|
# Are the arguments in the passed node object positional
|
62
64
|
#
|
@@ -68,7 +70,7 @@ module RuboCop
|
|
68
70
|
return false if node.arguments.count < 3
|
69
71
|
node.arguments[2..-1].each do |arg|
|
70
72
|
# hashes, blocks, or variable/methods are valid. Anything else is not
|
71
|
-
return true unless
|
73
|
+
return true unless VALID_TYPES.include?(arg.type)
|
72
74
|
end
|
73
75
|
false
|
74
76
|
end
|
@@ -81,7 +83,7 @@ module RuboCop
|
|
81
83
|
# @return [String]
|
82
84
|
#
|
83
85
|
def corrected_string(node)
|
84
|
-
args = node.arguments
|
86
|
+
args = node.arguments.dup
|
85
87
|
|
86
88
|
# If the 2nd argument is a String and not an Integer as a String
|
87
89
|
# then it's the old sort field and we need to delete it. Same thing
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
|
49
49
|
def on_block(node)
|
50
50
|
match_property_in_resource?(:windows_feature, :install_method, node) do |prop_node|
|
51
|
-
add_offense(prop_node, message: MSG, severity: :warning) if prop_node.source.
|
51
|
+
add_offense(prop_node, message: MSG, severity: :warning) if prop_node.source.include?(':servermanagercmd')
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: 2020, Chef Software Inc.
|
4
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module RuboCop
|
20
|
+
module Cop
|
21
|
+
module Chef
|
22
|
+
module ChefDeprecations
|
23
|
+
# In Chef Infra Client 13 and later the `windows_package` resource's `installer_type` property must be a symbol.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
#
|
27
|
+
# # bad
|
28
|
+
# windows_package 'AppveyorDeploymentAgent' do
|
29
|
+
# source 'https://www.example.com/appveyor.msi'
|
30
|
+
# installer_type 'msi'
|
31
|
+
# options "/quiet /qn /norestart /log install.log"
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# windows_package 'AppveyorDeploymentAgent' do
|
36
|
+
# source 'https://www.example.com/appveyor.msi'
|
37
|
+
# installer_type :msi
|
38
|
+
# options "/quiet /qn /norestart /log install.log"
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
class WindowsPackageInstallerTypeString < Base
|
42
|
+
include RuboCop::Chef::CookbookHelpers
|
43
|
+
extend AutoCorrector
|
44
|
+
|
45
|
+
MSG = "In Chef Infra Client 13 and later the `windows_package` resource's `installer_type` property must be a symbol."
|
46
|
+
|
47
|
+
def on_block(node)
|
48
|
+
match_property_in_resource?(:windows_package, 'installer_type', node) do |offense|
|
49
|
+
return unless offense.arguments.count == 1 # we can only analyze simple string args
|
50
|
+
return unless offense.arguments.first.str_type? # anything else is fine
|
51
|
+
|
52
|
+
add_offense(offense.loc.expression, message: MSG, severity: :warning) do |corrector|
|
53
|
+
corrector.replace(offense.arguments.first.source_range, ":#{offense.arguments.first.value}")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -44,6 +44,9 @@ module RuboCop
|
|
44
44
|
PATTERN
|
45
45
|
|
46
46
|
def on_send(node)
|
47
|
+
# avoid triggering on things like new_resource.actions
|
48
|
+
return unless node.receiver.nil?
|
49
|
+
|
47
50
|
# if the resource requires poise then bail out since we're in a poise resource where @allowed_actions is legit
|
48
51
|
return if poise_require(processed_source.ast).any? || !resource_actions?(processed_source.ast)
|
49
52
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cookstyle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.17.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thom May
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-09-
|
12
|
+
date: 2020-09-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb
|
89
89
|
- lib/rubocop/cop/chef/deprecation/chef_rest.rb
|
90
90
|
- lib/rubocop/cop/chef/deprecation/chef_rewind.rb
|
91
|
+
- lib/rubocop/cop/chef/deprecation/chef_shellout.rb
|
91
92
|
- lib/rubocop/cop/chef/deprecation/chef_windows_platform_helper.rb
|
92
93
|
- lib/rubocop/cop/chef/deprecation/chefdk_generators.rb
|
93
94
|
- lib/rubocop/cop/chef/deprecation/cheffile.rb
|
@@ -107,6 +108,8 @@ files:
|
|
107
108
|
- lib/rubocop/cop/chef/deprecation/eol_audit_mode.rb
|
108
109
|
- lib/rubocop/cop/chef/deprecation/epic_fail.rb
|
109
110
|
- lib/rubocop/cop/chef/deprecation/erl_call.rb
|
111
|
+
- lib/rubocop/cop/chef/deprecation/execute_path_property.rb
|
112
|
+
- lib/rubocop/cop/chef/deprecation/execute_relative_creates_without_cwd.rb
|
110
113
|
- lib/rubocop/cop/chef/deprecation/hwrp_without_provides.rb
|
111
114
|
- lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb
|
112
115
|
- lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb
|
@@ -139,6 +142,7 @@ files:
|
|
139
142
|
- lib/rubocop/cop/chef/deprecation/user_supports_property.rb
|
140
143
|
- lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb
|
141
144
|
- lib/rubocop/cop/chef/deprecation/windows_feature_servermanagercmd.rb
|
145
|
+
- lib/rubocop/cop/chef/deprecation/windows_package_installer_type_string.rb
|
142
146
|
- lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb
|
143
147
|
- lib/rubocop/cop/chef/deprecation/windows_version_helpers.rb
|
144
148
|
- lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb
|