cookstyle 6.16.10 → 6.17.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e15b2148d2b58205dc5b6653e3824b59dda2a927c1e0753f42d522105682021
4
- data.tar.gz: e2c9f7bb6727c8f97b7de581e29b4f18db002b17f10732e115652e728f844ded
3
+ metadata.gz: 76d0f2a3917c4ff1035541386d4edaa98f4cb782bd2f43a839d938b66aada708
4
+ data.tar.gz: ca7aff409b3d786fd71ac630c1d23b36f51a51ba495f7c2c4761c753c5e40624
5
5
  SHA512:
6
- metadata.gz: f9d1c969323e34fc6c58c987a9b339c625f2cfeb7b6ceeea83e7e7a0b5292dfe8d54e1f05dca2773ec582aaa6ad5b12914715d77b140906f14b8911406396d5e
7
- data.tar.gz: e343548e500f20767be5ce478d47969677e31d9ebd1f8661cab493e9777eadd0e8ed09921a22690ef61a5ade718b8ae954bc1fa3464c01abbcd12cd6843e1273
6
+ metadata.gz: 94bd535e28382dfd08776a053b8c6c9bb46e054a4dc3f10876b470de3755b3d6a78da9c71982ae3a7e0aee3856230e027ffe25457c77b8fd703df839acffeed4
7
+ data.tar.gz: f80c75e882aa27d4d4d81628c996acd2c2f5b1fc0226fafcd37b2ff86b2f9dddc9aa8f84c0b5cf4c8f71b1333757e2e239699966ac612902b426cae881ca91c1
@@ -2,7 +2,7 @@
2
2
  # -*- encoding: utf-8 -*-
3
3
  # frozen_string_literal: true
4
4
 
5
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), %w(.. lib))
5
+ $LOAD_PATH.unshift File.join(__dir__, %w(.. lib))
6
6
 
7
7
  require 'cookstyle'
8
8
 
@@ -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
  ###############################
@@ -2616,4 +2657,4 @@ Style/RedundantAssignment:
2616
2657
 
2617
2658
  # alert on invalid ruby
2618
2659
  Lint/Syntax:
2619
- Enabled: true
2660
+ Enabled: true
@@ -19,7 +19,7 @@ module RuboCop
19
19
  class ConfigLoader
20
20
  RUBOCOP_HOME.gsub!(
21
21
  /^.*$/,
22
- File.realpath(File.join(File.dirname(__FILE__), '..'))
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(File.dirname(__FILE__) + '/rubocop/cop/chef/**/*.rb') do |file|
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Cookstyle
3
- VERSION = "6.16.10" # rubocop: disable Style/StringLiterals
3
+ VERSION = "6.17.5" # rubocop: disable Style/StringLiterals
4
4
  RUBOCOP_VERSION = '0.90.0'
5
5
  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
@@ -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 %i(send hash block_pass).include?(arg.type)
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.match?(/:servermanagercmd/)
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
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.16.10
4
+ version: 6.17.5
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-03 00:00:00.000000000 Z
12
+ date: 2020-09-11 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