cookstyle 7.18.0 → 7.22.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/config/cookstyle.yml +122 -5
  3. data/config/disable_all.yml +2 -0
  4. data/config/upstream.yml +24 -2
  5. data/cookstyle.gemspec +1 -1
  6. data/lib/cookstyle/version.rb +2 -2
  7. data/lib/rubocop/cop/chef/correctness/metadata_malformed_version.rb +1 -1
  8. data/lib/rubocop/cop/chef/correctness/powershell_file_exists.rb +50 -0
  9. data/lib/rubocop/cop/chef/deprecation/chef_sugar_helpers.rb +2 -2
  10. data/lib/rubocop/cop/chef/deprecation/depends_chef_nginx_cookbook.rb +54 -0
  11. data/lib/rubocop/cop/chef/deprecation/depends_chef_reporting_cookbook.rb +51 -0
  12. data/lib/rubocop/cop/chef/deprecation/depends_omnibus_updater_cookbook.rb +54 -0
  13. data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +2 -2
  14. data/lib/rubocop/cop/chef/deprecation/hwrp_without_unified_mode_true.rb +1 -1
  15. data/lib/rubocop/cop/chef/deprecation/resource_without_unified_mode_true.rb +1 -1
  16. data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +2 -2
  17. data/lib/rubocop/cop/chef/modernize/chef_15_resources.rb +57 -0
  18. data/lib/rubocop/cop/chef/modernize/depends_chef_vault_cookbook.rb +54 -0
  19. data/lib/rubocop/cop/chef/modernize/depends_chocolatey_cookbooks.rb +55 -0
  20. data/lib/rubocop/cop/chef/modernize/depends_kernel_module_cookbook.rb +54 -0
  21. data/lib/rubocop/cop/chef/modernize/depends_locale_cookbook.rb +54 -0
  22. data/lib/rubocop/cop/chef/modernize/depends_openssl_cookbook.rb +54 -0
  23. data/lib/rubocop/cop/chef/modernize/depends_timezone_lwrp_cookbook.rb +54 -0
  24. data/lib/rubocop/cop/chef/modernize/depends_windows_firewall_cookbook.rb +54 -0
  25. data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +4 -2
  26. data/lib/rubocop/cop/chef/modernize/use_chef_language_cloud_helpers.rb +90 -0
  27. data/lib/rubocop/cop/chef/modernize/use_chef_language_env_helpers.rb +66 -0
  28. data/lib/rubocop/cop/chef/style/immediate_notification_timing.rb +3 -3
  29. metadata +19 -5
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, 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
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Don't depend on the timezone_lwrp cookbook made obsolete by Chef Infra Client 14.6. The timezone resource is now included in Chef Infra Client itself.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'timezone_lwrp'
28
+ #
29
+ class DependsOnTimezoneLwrpCookbook < Base
30
+ extend AutoCorrector
31
+ extend TargetChefVersion
32
+ include RangeHelp
33
+
34
+ minimum_target_chef_version '14.6'
35
+
36
+ MSG = "Don't depend on the timezone_lwrp cookbook made obsolete by Chef Infra Client 14.6. The timezone resource is now included in Chef Infra Client itself."
37
+ RESTRICT_ON_SEND = [:depends].freeze
38
+
39
+ def_node_matcher :legacy_depends?, <<-PATTERN
40
+ (send nil? :depends (str "timezone_lwrp") ... )
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ legacy_depends?(node) do
45
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
46
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, 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
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Don't depend on the windows_firewall cookbook made obsolete by Chef Infra Client 14.7. The windows_firewall resource is now included in Chef Infra Client itself.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # depends 'windows_firewall'
28
+ #
29
+ class DependsOnWindowsFirewallCookbook < Base
30
+ extend AutoCorrector
31
+ extend TargetChefVersion
32
+ include RangeHelp
33
+
34
+ minimum_target_chef_version '14.7'
35
+
36
+ MSG = "Don't depend on the windows_firewall cookbook made obsolete by Chef Infra Client 14.7. The windows_firewall resource is now included in Chef Infra Client itself."
37
+ RESTRICT_ON_SEND = [:depends].freeze
38
+
39
+ def_node_matcher :legacy_depends?, <<-PATTERN
40
+ (send nil? :depends (str "windows_firewall") ... )
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ legacy_depends?(node) do
45
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
46
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -19,11 +19,13 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Modernize
22
- # Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive_file resource.
22
+ # Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive_file resource from the libarchive cookbook.
23
23
  #
24
24
  # @example
25
25
  #
26
26
  # #### incorrect
27
+ # depends 'libarchive'
28
+ #
27
29
  # libarchive_file "C:\file.zip" do
28
30
  # path 'C:\expand_here'
29
31
  # end
@@ -39,7 +41,7 @@ module RuboCop
39
41
 
40
42
  minimum_target_chef_version '15.0'
41
43
 
42
- MSG = 'Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive file resource'
44
+ MSG = 'Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive file resource from the libarchive cookbook'
43
45
  RESTRICT_ON_SEND = [:libarchive_file, :notifies, :subscribes].freeze
44
46
 
45
47
  def_node_matcher :notification_property?, <<-PATTERN
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, 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
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Chef Infra Client 15.5 and later include cloud helpers to make detecting instance that run on public and private clouds easier.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # node['cloud']['provider'] == 'alibaba'
28
+ # node['cloud']['provider'] == 'ec2'
29
+ # node['cloud']['provider'] == 'gce'
30
+ # node['cloud']['provider'] == 'rackspace'
31
+ # node['cloud']['provider'] == 'eucalyptus'
32
+ # node['cloud']['provider'] == 'linode'
33
+ # node['cloud']['provider'] == 'openstack'
34
+ # node['cloud']['provider'] == 'azure'
35
+ # node['cloud']['provider'] == 'digital_ocean'
36
+ # node['cloud']['provider'] == 'softlayer'
37
+ #
38
+ # #### correct
39
+ # alibaba?
40
+ # ec2?
41
+ # gce?
42
+ # rackspace?
43
+ # eucalyptus?
44
+ # linode?
45
+ # openstack?
46
+ # azure?
47
+ # digital_ocean?
48
+ # softlayer?
49
+ #
50
+ class UseChefLanguageCloudHelpers < Base
51
+ extend AutoCorrector
52
+
53
+ MSG = 'Chef Infra Client 15.5 and later include cloud helpers to make detecting instance that run on public and private clouds easier.'
54
+ RESTRICT_ON_SEND = [:==, :[]].freeze
55
+ VALID_CLOUDS = %w(alibaba ec2 gce rackspace eucalyptus linode openstack azure digital_ocean softlayer).freeze
56
+
57
+ def_node_matcher :provider_comparison?, <<-PATTERN
58
+ (send
59
+ (send
60
+ (send
61
+ (send nil? :node) :[]
62
+ (str "cloud")) :[]
63
+ (str "provider")) :==
64
+ (str $_))
65
+ PATTERN
66
+
67
+ def_node_matcher :node_cloud?, <<-PATTERN
68
+ (send
69
+ (send nil? :node) :[]
70
+ (str "cloud"))
71
+ PATTERN
72
+
73
+ def on_send(node)
74
+ provider_comparison?(node) do |cloud_name|
75
+ # skip it if someone was checking for a bogus cloud provider
76
+ next unless VALID_CLOUDS.include?(cloud_name)
77
+
78
+ # if they were checking for node['cloud'] and the provider replace it all
79
+ node = node.parent if node.parent.and_type? && node_cloud?(node.left_sibling)
80
+
81
+ add_offense(node, message: MSG, severity: :refactor) do |corrector|
82
+ corrector.replace(node, "#{cloud_name}?")
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2021, 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
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module Modernize
22
+ # Chef Infra Client 15.5 and later include a large number of new helpers in the Chef Infra Language to simplify checking the system configuration in recipes and resources. These should be used when possible over more complex attribute or ENV var comparisons.
23
+ #
24
+ # @example
25
+ #
26
+ # #### incorrect
27
+ # ENV['CI']
28
+ # ENV['TEST_KITCHEN']
29
+ #
30
+ # #### correct
31
+ # ci?
32
+ # kitchen?
33
+ #
34
+ class UseChefLanguageEnvHelpers < Base
35
+ extend AutoCorrector
36
+
37
+ RESTRICT_ON_SEND = [:[]].freeze
38
+
39
+ def_node_matcher :env?, <<-PATTERN
40
+ (send
41
+ (const nil? :ENV) :[]
42
+ (str ${"TEST_KITCHEN" "CI"}))
43
+ PATTERN
44
+
45
+ def on_send(node)
46
+ env?(node) do |env_value|
47
+ # we don't handle .nil? checks yet so just skip them
48
+ next if node.parent.send_type? && node.parent.method_name == :nil?
49
+
50
+ case env_value
51
+ when 'CI'
52
+ add_offense(node, message: 'Chef Infra Client 15.5 and later include a helper `ci?` that should be used to see if the `CI` env var is set.', severity: :refactor) do |corrector|
53
+ corrector.replace(node, 'ci?')
54
+ end
55
+ when 'TEST_KITCHEN'
56
+ add_offense(node, message: 'Chef Infra Client 15.5 and later include a helper `kitchen?` that should be used to see if the `TEST_KITCHEN` env var is set.', severity: :refactor) do |corrector|
57
+ corrector.replace(node, 'kitchen?')
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -19,7 +19,7 @@ module RuboCop
19
19
  module Cop
20
20
  module Chef
21
21
  module Style
22
- # Use :immediately instead of :immediate for resource notification timing
22
+ # Use :immediately instead of :immediate for resource notification timing.
23
23
  #
24
24
  # @example
25
25
  #
@@ -39,10 +39,10 @@ module RuboCop
39
39
  extend AutoCorrector
40
40
 
41
41
  MSG = 'Use :immediately instead of :immediate for resource notification timing'
42
- RESTRICT_ON_SEND = [:notifies].freeze
42
+ RESTRICT_ON_SEND = [:notifies, :subscribes].freeze
43
43
 
44
44
  def_node_matcher :immediate_notify?, <<-PATTERN
45
- (send nil? :notifies (sym _) (...) $(sym :immediate))
45
+ (send nil? {:notifies :subscribes} (sym _) (...) $(sym :immediate))
46
46
  PATTERN
47
47
 
48
48
  def on_send(node)
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: 7.18.0
4
+ version: 7.22.3
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: 2021-08-14 00:00:00.000000000 Z
12
+ date: 2021-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 1.19.0
20
+ version: 1.20.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 1.19.0
27
+ version: 1.20.0
28
28
  description:
29
29
  email:
30
30
  - thom@chef.io
@@ -78,6 +78,7 @@ files:
78
78
  - lib/rubocop/cop/chef/correctness/octal_mode_as_string.rb
79
79
  - lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb
80
80
  - lib/rubocop/cop/chef/correctness/powershell_delete_file.rb
81
+ - lib/rubocop/cop/chef/correctness/powershell_file_exists.rb
81
82
  - lib/rubocop/cop/chef/correctness/property_without_type.rb
82
83
  - lib/rubocop/cop/chef/correctness/resource_sets_internal_properties.rb
83
84
  - lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb
@@ -99,7 +100,10 @@ files:
99
100
  - lib/rubocop/cop/chef/deprecation/chefspec_coverage_report.rb
100
101
  - lib/rubocop/cop/chef/deprecation/chefspec_legacy_runner.rb
101
102
  - lib/rubocop/cop/chef/deprecation/chocolatey_package_uninstall_action.rb
103
+ - lib/rubocop/cop/chef/deprecation/depends_chef_nginx_cookbook.rb
104
+ - lib/rubocop/cop/chef/deprecation/depends_chef_reporting_cookbook.rb
102
105
  - lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb
106
+ - lib/rubocop/cop/chef/deprecation/depends_omnibus_updater_cookbook.rb
103
107
  - lib/rubocop/cop/chef/deprecation/depends_partial_search.rb
104
108
  - lib/rubocop/cop/chef/deprecation/depends_poise.rb
105
109
  - lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb
@@ -175,6 +179,7 @@ files:
175
179
  - lib/rubocop/cop/chef/modernize/berksfile_source.rb
176
180
  - lib/rubocop/cop/chef/modernize/build_essential.rb
177
181
  - lib/rubocop/cop/chef/modernize/chef_14_resources.rb
182
+ - lib/rubocop/cop/chef/modernize/chef_15_resources.rb
178
183
  - lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb
179
184
  - lib/rubocop/cop/chef/modernize/compile_time_resources.rb
180
185
  - lib/rubocop/cop/chef/modernize/conditional_using_test.rb
@@ -184,6 +189,13 @@ files:
184
189
  - lib/rubocop/cop/chef/modernize/default_action_initializer.rb
185
190
  - lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb
186
191
  - lib/rubocop/cop/chef/modernize/definitions.rb
192
+ - lib/rubocop/cop/chef/modernize/depends_chef_vault_cookbook.rb
193
+ - lib/rubocop/cop/chef/modernize/depends_chocolatey_cookbooks.rb
194
+ - lib/rubocop/cop/chef/modernize/depends_kernel_module_cookbook.rb
195
+ - lib/rubocop/cop/chef/modernize/depends_locale_cookbook.rb
196
+ - lib/rubocop/cop/chef/modernize/depends_openssl_cookbook.rb
197
+ - lib/rubocop/cop/chef/modernize/depends_timezone_lwrp_cookbook.rb
198
+ - lib/rubocop/cop/chef/modernize/depends_windows_firewall_cookbook.rb
187
199
  - lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb
188
200
  - lib/rubocop/cop/chef/modernize/dsl_include_in_resource.rb
189
201
  - lib/rubocop/cop/chef/modernize/empty_resource_initialize.rb
@@ -224,6 +236,8 @@ files:
224
236
  - lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb
225
237
  - lib/rubocop/cop/chef/modernize/sysctl_param_resource.rb
226
238
  - lib/rubocop/cop/chef/modernize/unnecessary_mixlib_shellout_require.rb
239
+ - lib/rubocop/cop/chef/modernize/use_chef_language_cloud_helpers.rb
240
+ - lib/rubocop/cop/chef/modernize/use_chef_language_env_helpers.rb
227
241
  - lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb
228
242
  - lib/rubocop/cop/chef/modernize/use_require_relative.rb
229
243
  - lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb
@@ -291,7 +305,7 @@ licenses:
291
305
  - Apache-2.0
292
306
  metadata:
293
307
  homepage_uri: https://github.com/chef/cookstyle
294
- changelog_uri: https://github.com/chef/cookstyle/blob/master/CHANGELOG.md
308
+ changelog_uri: https://github.com/chef/cookstyle/blob/main/CHANGELOG.md
295
309
  source_code_uri: https://github.com/chef/cookstyle
296
310
  documentation_uri: https://docs.chef.io/workstation/cookstyle/
297
311
  bug_tracker_uri: https://github.com/chef/cookstyle/issues